From fc936e2e24023a7bb540c3ca8b359c34fec0dc4a Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 26 Dec 2016 17:37:57 +0300 Subject: [PATCH] [groovy] fix EA-63038 and EA-67911 --- .../GroovyStaticImportMethodFix.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java index 25e6c93e7857..478c7bdb25c4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/GroovyStaticImportMethodFix.java @@ -81,7 +81,14 @@ public class GroovyStaticImportMethodFix extends Intention { } @Nullable - private static GrReferenceExpression getMethodExpression(GrMethodCall call) { + private GrReferenceExpression getMethodExpression() { + GrMethodCall methodCall = myMethodCall.getElement(); + if (methodCall == null) return null; + return getMethodExpression(methodCall); + } + + @Nullable + private static GrReferenceExpression getMethodExpression(@NotNull GrMethodCall call) { GrExpression result = call.getInvokedExpression(); return result instanceof GrReferenceExpression ? (GrReferenceExpression)result : null; } @@ -89,12 +96,13 @@ public class GroovyStaticImportMethodFix extends Intention { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { myCandidates = null; - return myMethodCall.getElement() != null && - myMethodCall.getElement().isValid() && - getMethodExpression(myMethodCall.getElement()) != null && - getMethodExpression(myMethodCall.getElement()).getQualifierExpression() == null && - file.getManager().isInProject(file) && - !getCandidates().isEmpty(); + + if (!file.getManager().isInProject(file)) return false; + + GrReferenceExpression invokedExpression = getMethodExpression(); + if (invokedExpression == null || invokedExpression.getQualifierExpression() != null) return false; + + return !getCandidates().isEmpty(); } @NotNull @@ -189,10 +197,13 @@ public class GroovyStaticImportMethodFix extends Intention { return true; } + @NotNull private List getCandidates() { - if (myCandidates == null) { - myCandidates = getMethodsToImport(); + List result = myCandidates; + if (result == null) { + result = getMethodsToImport(); + myCandidates = result; } - return myCandidates; + return result; } }