IDEA-27065: Editor cannot resolve GDK methods invoked on uninitialized untyped variab...
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sun, 31 Jan 2010 12:21:16 +0000 (15:21 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sun, 31 Jan 2010 12:21:16 +0000 (15:21 +0300)
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.java
plugins/groovy/testdata/resolve/method/notInitializedVariable/A.groovy [new file with mode: 0644]

index 3c40bac3dd73b42a00ca8008a01b93b1ed7cc339..20f4c6918d9d4371e04bedabc20f2a401eb3c8cb 100644 (file)
@@ -427,7 +427,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements
       }
     }
 
-    private void processQualifierForSpreadDot(GrReferenceExpressionImpl refExpr, ResolverProcessor processor, GrExpression qualifier) {
+    private static void processQualifierForSpreadDot(GrReferenceExpressionImpl refExpr, ResolverProcessor processor, GrExpression qualifier) {
       PsiType qualifierType = qualifier.getType();
       if (qualifierType instanceof PsiClassType) {
         PsiClassType.ClassResolveResult result = ((PsiClassType) qualifierType).resolveGenerics();
@@ -449,13 +449,19 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements
       }
     }
 
-    private void processQualifier(GrReferenceExpressionImpl refExpr, ResolverProcessor processor, GrExpression qualifier) {
+    private static void processQualifier(GrReferenceExpressionImpl refExpr, ResolverProcessor processor, GrExpression qualifier) {
       PsiType qualifierType = qualifier.getType();
       if (qualifierType == null) {
         if (qualifier instanceof GrReferenceExpression) {
           PsiElement resolved = ((GrReferenceExpression) qualifier).resolve();
           if (resolved instanceof PsiPackage) {
-            if (!resolved.processDeclarations(processor, ResolveState.initial(), null, refExpr)) return;
+            if (!resolved.processDeclarations(processor, ResolveState.initial(), null, refExpr)) //noinspection UnnecessaryReturnStatement
+              return;
+          }
+          else {
+            qualifierType = JavaPsiFacade.getInstance(refExpr.getProject()).getElementFactory()
+              .createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, refExpr.getResolveScope());
+            processClassQualifierType(refExpr, processor, qualifierType);
           }
         }
       } else {
@@ -556,6 +562,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements
     return Kind.TYPE_OR_PROPERTY;
   }
 
+  @Nullable
   public String getCanonicalText() {
     return null;
   }
index bb5787809bf938b0b03825c9573d67353fac28d5..b64c58e9714771edcb43b1025d90e9fd529450bd 100644 (file)
@@ -65,6 +65,9 @@ public class GrClassImplUtil {
     }
   };
 
+  private GrClassImplUtil() {
+  }
+
 
   @Nullable
   public static PsiClass getSuperClass(GrTypeDefinition grType) {
@@ -74,6 +77,7 @@ public class GrClassImplUtil {
     return superClass != null ? superClass : getBaseClass(grType);
   }
 
+  @Nullable
   public static PsiClass getBaseClass(GrTypeDefinition grType) {
     if (grType.isEnum()) {
       return JavaPsiFacade.getInstance(grType.getProject()).findClass(CommonClassNames.JAVA_LANG_ENUM, grType.getResolveScope());
index e66d0336db5e742c04473394bc82082fb86a231d..146af08a9ae441f83a1645c953fe3b8bb7881f86 100644 (file)
@@ -540,4 +540,10 @@ public class ResolveMethodTest extends GroovyResolveTestCase {
     final PsiElement resolved = ref.resolve();
     assertInstanceOf(resolved, PsiMethod.class);
   }
+
+  public void testNotInitializedVariable() throws Exception {
+    PsiReference ref = configureByFile("notInitializedVariable/A.groovy");
+    final PsiElement resolved = ref.resolve();
+    assertInstanceOf(resolved, PsiMethod.class);
+  }
 }
diff --git a/plugins/groovy/testdata/resolve/method/notInitializedVariable/A.groovy b/plugins/groovy/testdata/resolve/method/notInitializedVariable/A.groovy
new file mode 100644 (file)
index 0000000..02476e7
--- /dev/null
@@ -0,0 +1,2 @@
+def foo
+foo.hashC<ref>ode()
\ No newline at end of file