accept that with different library versions inheritance relation may be intransitive...
[idea/community.git] / java / java-impl / src / com / intellij / util / xml / impl / ExtendsClassChecker.java
index 5bdba4cb4c3c435a764248199adb82401b999eda..3fe146e787c0300e7141a7a9af120ab45cad718d 100644 (file)
@@ -19,11 +19,11 @@ import com.intellij.openapi.project.Project;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference;
 import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
-import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.ProcessingContext;
 import com.intellij.util.ReflectionCache;
 import com.intellij.util.SmartList;
-import com.intellij.util.ProcessingContext;
 import com.intellij.util.xml.*;
 import com.intellij.util.xml.highlighting.DomCustomAnnotationChecker;
 import com.intellij.util.xml.highlighting.DomElementAnnotationHolder;
@@ -81,7 +81,7 @@ public class ExtendsClassChecker extends DomCustomAnnotationChecker<ExtendClass>
                                                                    final boolean allowEnum,
                                                                    final DomElementAnnotationHolder holder) {
     final Project project = element.getManager().getProject();
-    PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
+    PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, value.getResolveScope());
     final SmartList<DomElementProblemDescriptor> list = new SmartList<DomElementProblemDescriptor>();
     if (extendClass != null) {
       if (!name.equals(value.getQualifiedName()) && !value.isInheritor(extendClass, true)) {
@@ -97,19 +97,22 @@ public class ExtendsClassChecker extends DomCustomAnnotationChecker<ExtendClass>
       else if (!allowNonPublic && !value.hasModifierProperty(PsiModifier.PUBLIC)) {
         list.add(holder.createProblem(element, DomBundle.message("class.is.not.public", value.getQualifiedName())));
       }
-      else if (!hasDefaultConstructor(value)) {
+      else if (!PsiUtil.hasDefaultConstructor(value, true)) {
         if (canBeDecorator) {
           boolean hasConstructor = false;
 
           for (PsiMethod method : value.getConstructors()) {
             final PsiParameterList psiParameterList = method.getParameterList();
             if (psiParameterList.getParametersCount() != 1) continue;
-            final PsiType psiType = psiParameterList.getParameters()[0].getTypeElement().getType();
-            if (psiType instanceof PsiClassType) {
-              final PsiClass psiClass = ((PsiClassType)psiType).resolve();
-              if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
-                hasConstructor = true;
-                break;
+            PsiTypeElement typeElement = psiParameterList.getParameters()[0].getTypeElement();
+            if (typeElement != null) {
+              final PsiType psiType = typeElement.getType();
+              if (psiType instanceof PsiClassType) {
+                final PsiClass psiClass = ((PsiClassType)psiType).resolve();
+                if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
+                  hasConstructor = true;
+                  break;
+                }
               }
             }
           }
@@ -134,21 +137,6 @@ public class ExtendsClassChecker extends DomCustomAnnotationChecker<ExtendClass>
     return list;
   }
 
-  public static boolean hasDefaultConstructor(PsiClass clazz) {
-    final PsiMethod[] constructors = clazz.getConstructors();
-    if (constructors.length > 0) {
-      for (PsiMethod cls: constructors) {
-        if ((cls.hasModifierProperty(PsiModifier.PUBLIC) || cls.hasModifierProperty(PsiModifier.PROTECTED)) && cls.getParameterList().getParametersCount() == 0) {
-          return true;
-        }
-      }
-    } else {
-      final PsiClass superClass = clazz.getSuperClass();
-      return superClass == null || hasDefaultConstructor(superClass);
-    }
-    return false;
-  }
-
   public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
     final Object valueObject = element.getValue();
     if (!(valueObject instanceof PsiClass)) return Collections.emptyList();