Skip to content

Commit

Permalink
Parameters resolving improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey K committed Nov 14, 2019
1 parent 6f72c35 commit e7658ab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group 'com.zoomint'
version '1.4.6'
version '1.4.7'
sourceCompatibility = 1.8

repositories {
Expand Down
41 changes: 35 additions & 6 deletions src/main/java/io/github/legionivo/plugin/TestRailApiWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.java.PsiMethodCallExpressionImpl;
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
import com.intellij.psi.impl.source.tree.java.PsiReturnStatementImpl;
import io.github.legionivo.plugin.api.TestRailClient;
import io.github.legionivo.plugin.api.TestRailClientBuilder;
import io.github.legionivo.plugin.enums.State;
Expand Down Expand Up @@ -243,13 +244,29 @@ private static String getValueFromExpression(PsiExpression expression) {
if (expression instanceof PsiMethodCallExpression) {
PsiMethod method = ((PsiMethodCallExpressionImpl) expression).resolveMethod();
if (Objects.requireNonNull(method).hasAnnotation(Annotations.OWNER_KEY_ANNOTATION) || method.getAnnotations().length > 0) {
PsiModifierList modifierList = method.getModifierList();
Project project = expression.getProject();
PsiAnnotation[] list = modifierList.getAnnotations();
PsiLiteralExpression expression1 = (PsiLiteralExpression) list[0].findAttributeValue("value");
String parameterValue = Objects.requireNonNull(expression1).getText().replace("\"", "");
text = PropertiesImplUtil.findPropertiesByKey(project, parameterValue).get(0).getValue();
text = getValueFromAnnotatedMethod(expression, method);
} else if (method.getBody() != null) {
PsiStatement[] statements = method.getBody().getStatements();
if (((PsiReturnStatementImpl) statements[0]).getReturnValue() instanceof PsiReferenceExpression) {
PsiExpression psiReferenceExpression = (((PsiReturnStatementImpl) statements[0]).getReturnValue());
assert psiReferenceExpression != null;
PsiVariable variable = (PsiVariable) ((PsiReferenceExpressionImpl) psiReferenceExpression).resolve();
if ((((PsiReturnStatementImpl) statements[0]).getReturnValue() instanceof PsiLiteralExpression)) {
text = ((Objects.requireNonNull(((PsiReturnStatementImpl) statements[0]).getReturnValue()).getText())).replaceAll("^\"|\"$", "");
} else if (Objects.requireNonNull(variable).hasInitializer()) {
PsiExpression initializer = Objects.requireNonNull(variable).getInitializer();
if (initializer == null) {
text = Objects.requireNonNull(variable.getNameIdentifier()).getText();
} else if (initializer instanceof PsiMethodCallExpressionImpl) {
PsiMethod psiMethod = ((PsiMethodCallExpressionImpl) initializer).resolveMethod();
if (Objects.requireNonNull(psiMethod).hasAnnotation(Annotations.OWNER_KEY_ANNOTATION) || psiMethod.getAnnotations().length > 0) {
text = getValueFromAnnotatedMethod(initializer, psiMethod);
}
} else text = Objects.requireNonNull(initializer).getText().replace("\"", "");
} else text = expression.getText();
}
} else text = expression.getText();

} else if (expression instanceof PsiReferenceExpression) {
PsiVariable variable = (PsiVariable) ((PsiReferenceExpressionImpl) expression).resolve();
if (Objects.requireNonNull(variable).hasInitializer()) {
Expand All @@ -268,6 +285,18 @@ private static String getValueFromExpression(PsiExpression expression) {

}


private static String getValueFromAnnotatedMethod(PsiExpression expression, PsiMethod method) {
String text;
PsiModifierList modifierList = method.getModifierList();
Project project = expression.getProject();
PsiAnnotation[] list = modifierList.getAnnotations();
PsiLiteralExpression expression1 = (PsiLiteralExpression) list[0].findAttributeValue("value");
String parameterValue = Objects.requireNonNull(expression1).getText().replace("\"", "");
text = PropertiesImplUtil.findPropertiesByKey(project, parameterValue).get(0).getValue();
return text;
}

private static String getValueFromPsiPolyadicExpression(PsiPolyadicExpression polyadicExpression) {
PsiExpression[] operands = polyadicExpression.getOperands();
StringBuilder fullExpression = new StringBuilder();
Expand Down

0 comments on commit e7658ab

Please sign in to comment.