IDEADEV-41940
authorAlexey Kudravtsev <cdr@intellij.com>
Fri, 11 Dec 2009 10:42:03 +0000 (13:42 +0300)
committerunknown <cdr@.Labs.IntelliJ.Net>
Wed, 13 Jan 2010 13:42:57 +0000 (16:42 +0300)
java/java-impl/src/com/intellij/psi/impl/file/PsiPackageImpl.java
java/java-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TextEditorBackgroundHighlighter.java
platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java

index d07867db765d6f68d9bd49c2dda6548556b441a7..49ebc4cf45b3a318c4e2495f7cb75524217f5dcf 100644 (file)
@@ -552,8 +552,7 @@ public class PsiPackageImpl extends PsiElementBase implements PsiPackage {
 
   private boolean processClassesByName(PsiScopeProcessor processor, ResolveState state, PsiElement place, GlobalSearchScope scope, String className) {
     final PsiClass[] classes = findClassesByName(className, scope);
-    if (!processClasses(processor, state, place, classes)) return true;
-    return false;
+    return !processClasses(processor, state, place, classes);
   }
 
   private boolean processClasses(PsiScopeProcessor processor, ResolveState state, PsiElement place, PsiClass[] classes) {
@@ -599,7 +598,7 @@ public class PsiPackageImpl extends PsiElementBase implements PsiPackage {
 
   private class PackageAnnotationValueProvider implements CachedValueProvider<PsiModifierList> {
     @NonNls private static final String PACKAGE_INFO_FILE = "package-info.java";
-    private final Object[] OOCB_DEPENDENCY = new Object[] { PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT };
+    private final Object[] OOCB_DEPENDENCY = { PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT };
 
     public Result<PsiModifierList> compute() {
       List<PsiModifierList> list = new ArrayList<PsiModifierList>();
index ff5fdaa291f9a715017137d97b09c0ccc671e788..0f1332beac434d27e931183894cf188baad781b1 100644 (file)
@@ -107,6 +107,50 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
     return file instanceof PsiJavaFile && ((PsiJavaFile)file).getPackageName().equals(packageName);
   }
 
+  private static enum Domination {
+    DOMINATES, DOMINATED_BY, EQUAL
+  }
+
+  private Domination dominates(PsiClass aClass, boolean accessible, String fqName, ClassCandidateInfo info) {
+    final PsiClass otherClass = info.getElement();
+    assert otherClass != null;
+    String otherQName = otherClass.getQualifiedName();
+    if (fqName.equals(otherQName)) {
+      return Domination.DOMINATED_BY;
+    }
+    final PsiClass containingclass1 = aClass.getContainingClass();
+    final PsiClass containingclass2 = otherClass.getContainingClass();
+    if (containingclass1 != null && containingclass2 != null && containingclass2.isInheritor(containingclass1, true)) {
+      //shadowing
+      return Domination.DOMINATED_BY;
+    }
+
+    boolean infoAccessible = info.isAccessible();
+    if (infoAccessible && !accessible) {
+      return Domination.DOMINATED_BY;
+    }
+    if (!infoAccessible && accessible) {
+      return Domination.DOMINATES;
+    }
+
+    // single import wins over on-demand
+    boolean myOnDemand = isOnDemand(myCurrentFileContext, aClass);
+    boolean otherOnDemand = isOnDemand(info.getCurrentFileResolveScope(), otherClass);
+    if (myOnDemand && !otherOnDemand) return Domination.DOMINATED_BY;
+    if (!myOnDemand && otherOnDemand) {
+      return Domination.DOMINATES;
+    }
+
+    // everything wins over class from default package
+    boolean isDefault = StringUtil.getPackageName(fqName).length() == 0;
+    boolean otherDefault = otherQName != null && StringUtil.getPackageName(otherQName).length() == 0;
+    if (isDefault && !otherDefault) return Domination.DOMINATED_BY;
+    if (!isDefault && otherDefault) {
+      return Domination.DOMINATES;
+    }
+    return Domination.EQUAL;
+  }
+
   public boolean execute(PsiElement element, ResolveState state) {
     if (!(element instanceof PsiClass)) return true;
     final PsiClass aClass = (PsiClass)element;
@@ -123,32 +167,12 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
       if (fqName != null) {
         for (int i = myCandidates.size()-1; i>=0; i--) {
           ClassCandidateInfo info = myCandidates.get(i);
-          final PsiClass otherClass = info.getElement();
-          assert otherClass != null;
-          if (fqName.equals(otherClass.getQualifiedName())) {
-            return true;
-          }
-          final PsiClass containingclass1 = aClass.getContainingClass();
-          final PsiClass containingclass2 = otherClass.getContainingClass();
-          if (containingclass1 != null && containingclass2 != null && containingclass2.isInheritor(containingclass1, true)) {
-            //shadowing
-            return true;
-          }
 
-          boolean infoAccessible = info.isAccessible();
-          if (infoAccessible && !accessible) {
+          Domination domination = dominates(aClass, accessible, fqName, info);
+          if (domination == Domination.DOMINATED_BY) {
             return true;
           }
-          if (!infoAccessible && accessible) {
-            myCandidates.remove(i);
-            continue;
-          }
-
-          // single import wins over on-demand
-          boolean myOnDemand = isOnDemand(myCurrentFileContext, aClass);
-          boolean otherOnDemand = isOnDemand(info.getCurrentFileResolveScope(), otherClass);
-          if (myOnDemand && !otherOnDemand) return true;
-          if (!myOnDemand && otherOnDemand) {
+          else if (domination == Domination.DOMINATES) {
             myCandidates.remove(i);
           }
         }
index 268a4a26dcd4b01068eeb16d660035b288ae83e0..be263c876532f434d5f447cdda20b9adb57440d6 100644 (file)
@@ -79,7 +79,7 @@ public class TextEditorBackgroundHighlighter implements BackgroundEditorHighligh
     }
   }
 
-  private List<TextEditorHighlightingPass> getPasses(int[] passesToIgnore) {
+  public List<TextEditorHighlightingPass> getPasses(int[] passesToIgnore) {
     if (myProject.isDisposed()) return Collections.emptyList();
     PsiDocumentManager.getInstance(myProject).commitAllDocuments();
     renewFile();
index 44f99146b3f597c557137c965f456038021a3bce..29d91279756a967ed51202f4da1235f15dfe1035 100644 (file)
@@ -65,6 +65,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.extensions.ExtensionsArea;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
+import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.fileTypes.FileTypeManager;
 import com.intellij.openapi.module.Module;
@@ -1090,8 +1091,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
     }
     fileStatusMap.allowDirt(allowDirt);
     try {
-      TextEditorHighlightingPassRegistrarEx registrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project);
-      final List<TextEditorHighlightingPass> passes = registrar.instantiatePasses(file, editor, toIgnore);
+      TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter)TextEditorProvider.getInstance().getTextEditor(editor).getBackgroundHighlighter();
+      final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
       final ProgressIndicator progress = new DaemonProgressIndicator();
       ProgressManager.getInstance().runProcess(new Runnable() {
         public void run() {