This commit is contained in:
Alexey Kudravtsev
2009-10-28 16:16:04 +03:00
parent 83cecfceb4
commit f81181a974
2 changed files with 25 additions and 14 deletions
@@ -16,6 +16,7 @@
package com.intellij.psi.impl.source.resolve;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.infos.ClassCandidateInfo;
@@ -91,6 +92,13 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
}
private static boolean isOnDemand(PsiElement fileContext, PsiClass psiClass) {
if (fileContext instanceof PsiImportStatementBase && ((PsiImportStatementBase)fileContext).isOnDemand()) return true;
String fqn = psiClass.getQualifiedName();
if (fqn == null) return false;
return "java.lang".equals(StringUtil.getPackageName(fqn));
}
public boolean execute(PsiElement element, ResolveState state) {
if (!(element instanceof PsiClass)) return true;
final PsiClass aClass = (PsiClass)element;
@@ -119,14 +127,11 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
// single import wins over on-demand
if (myCurrentFileContext instanceof PsiImportStatementBase &&
info.getCurrentFileResolveScope() instanceof PsiImportStatementBase) {
PsiImportStatementBase myImport = (PsiImportStatementBase)myCurrentFileContext;
PsiImportStatementBase otherImport = (PsiImportStatementBase)info.getCurrentFileResolveScope();
if (myImport.isOnDemand() && !otherImport.isOnDemand()) return true;
if (!myImport.isOnDemand() && otherImport.isOnDemand()) {
myCandidates.remove(i);
}
boolean myOnDemand = isOnDemand(myCurrentFileContext, aClass);
boolean otherOnDemand = isOnDemand(info.getCurrentFileResolveScope(), otherClass);
if (myOnDemand && !otherOnDemand) return true;
if (!myOnDemand && otherOnDemand) {
myCandidates.remove(i);
}
}
}
@@ -140,7 +145,6 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
if (!accessible) return true;
if (!(myCurrentFileContext instanceof PsiImportStatementBase)) return false;
return true;
}