IDEA-52183: If groovy library added to a project 'Method getMetaClass is not implemen...
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 12 Feb 2010 13:56:29 +0000 (12 16:56 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Fri, 12 Feb 2010 13:56:29 +0000 (12 16:56 +0300)
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java
plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyOverrideImplementUtil.java

index 3cc2645..35707bf 100644 (file)
@@ -16,7 +16,6 @@
 
 package org.jetbrains.plugins.groovy.annotator;
 
-import com.intellij.codeInsight.ClassUtil;
 import com.intellij.codeInspection.ProblemHighlightType;
 import com.intellij.lang.ASTNode;
 import com.intellij.lang.annotation.Annotation;
@@ -27,6 +26,7 @@ import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.*;
+import com.intellij.psi.infos.CandidateInfo;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.PsiTreeUtil;
 import gnu.trove.TObjectHashingStrategy;
@@ -76,6 +76,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.processors.PropertyResolverProcessor;
+import org.jetbrains.plugins.groovy.overrideImplement.GroovyOverrideImplementUtil;
 import org.jetbrains.plugins.groovy.overrideImplement.quickFix.ImplementMethodsQuickFix;
 
 import java.util.*;
@@ -644,12 +645,12 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
     if (typeDefinition.isEnum() || typeDefinition.isAnnotationType()) return;
     if (typeDefinition instanceof GrTypeParameter) return;
 
-    Collection<HierarchicalMethodSignature> allMethods = typeDefinition.getVisibleSignatures();
-    PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(typeDefinition, allMethods);
+    Collection<CandidateInfo> collection = GroovyOverrideImplementUtil.getMethodsToImplement(typeDefinition);
+    if (collection.isEmpty()) return;
 
-    if (abstractMethod == null) return;
-
-    String notImplementedMethodName = abstractMethod.getName();
+    final PsiElement element = collection.iterator().next().getElement();
+    assert element instanceof PsiNamedElement;
+    String notImplementedMethodName = ((PsiNamedElement)element).getName();
 
     final int startOffset = typeDefinition.getTextOffset();
     int endOffset = typeDefinition.getNameIdentifierGroovy().getTextRange().getEndOffset();
index b64c58e..f6dba4f 100644 (file)
@@ -157,10 +157,8 @@ public class GrClassImplUtil {
       }
     }
 
-//    addGroovyObjectMethods(clazz, allMethods);
-
     final PsiClass[] supers = clazz.getSupers();
-    if (supers.length<2) {
+    if (supers.length < 2) {
       addGroovyObjectMethods(clazz, allMethods);
     }
     for (PsiClass aSuper : supers) {
index 51f0c2b..01e28b6 100644 (file)
@@ -118,9 +118,9 @@ public class GroovyOverrideImplementUtil {
             modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
             modifierList.setModifierProperty(PsiModifier.NATIVE, false);
 
-            setupOverridingMethodBody(project, method, result, template, substitutor, editor);
+            setupOverridingMethodBody(project, method, result, template, substitutor);
 
-            final GrTypeDefinitionBody classBody = ((GrTypeDefinition) aClass).getBody();
+            final GrTypeDefinitionBody classBody = aClass.getBody();
             final PsiMethod[] methods = aClass.getMethods();
 
             PsiElement anchor = null;
@@ -281,7 +281,11 @@ public class GroovyOverrideImplementUtil {
     return (GrMethod) GroovyPsiElementFactory.getInstance(project).createTopElementFromText(buffer.toString());
   }
 
-  private static void setupOverridingMethodBody(Project project, PsiMethod method, GrMethod resultMethod, FileTemplate template, PsiSubstitutor substitutor, final Editor editor) {
+  private static void setupOverridingMethodBody(Project project,
+                                                PsiMethod method,
+                                                GrMethod resultMethod,
+                                                FileTemplate template,
+                                                PsiSubstitutor substitutor) {
     final PsiType returnType = substitutor.substitute(method.getReturnType());
 
     String returnTypeText = "";
@@ -300,7 +304,8 @@ public class GroovyOverrideImplementUtil {
       final GrCodeBlock newBody = GroovyPsiElementFactory.getInstance(project).createMethodBodyFromText("\n" + bodyText + "\n");
 
       resultMethod.setBlock(newBody);
-    } catch (IOException e) {
+    }
+    catch (IOException e) {
       LOG.error(e);
     }
   }