mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Resolve in overlapping single type and on-demand static imports fixed
This commit is contained in:
+2
-1
@@ -209,7 +209,8 @@ public class PsiImportStaticReferenceElementImpl extends CompositePsiElement imp
|
||||
@NotNull
|
||||
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final ResolveCache resolveCache = getManager().getResolveCache();
|
||||
return (JavaResolveResult[])resolveCache.resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode);
|
||||
final ResolveResult[] results = resolveCache.resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode);
|
||||
return results instanceof JavaResolveResult[] ? (JavaResolveResult[])results : JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
private static final class OurGenericsResolver implements ResolveCache.PolyVariantResolver<PsiImportStaticReferenceElementImpl> {
|
||||
|
||||
@@ -34,8 +34,8 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
|
||||
import com.intellij.psi.impl.source.resolve.ClassCollectingProcessor;
|
||||
import com.intellij.psi.impl.source.resolve.ClassResolverProcessor;
|
||||
import com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.scope.JavaScopeProcessorEvent;
|
||||
@@ -51,7 +51,6 @@ import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -60,13 +59,13 @@ import java.util.List;
|
||||
public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJavaFile {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.PsiJavaFileBaseImpl");
|
||||
|
||||
private final CachedValue<MostlySingularMultiMap<String, ClassCollectingProcessor.ResultWithContext>> myResolveCache;
|
||||
@NonNls private static final String[] IMPLICIT_IMPORTS = { CommonClassNames.DEFAULT_PACKAGE };
|
||||
|
||||
@NonNls private static final String[] IMPLICIT_IMPORTS = { "java.lang" };
|
||||
private final CachedValue<MostlySingularMultiMap<String, SymbolCollectingProcessor.ResultWithContext>> myResolveCache;
|
||||
|
||||
protected PsiJavaFileBaseImpl(IElementType elementType, IElementType contentElementType, FileViewProvider viewProvider) {
|
||||
super(elementType, contentElementType, viewProvider);
|
||||
myResolveCache = CachedValuesManager.getManager(myManager.getProject()).createCachedValue(new MyCacheBuilder(), false);
|
||||
myResolveCache = CachedValuesManager.getManager(myManager.getProject()).createCachedValue(new MyCacheBuilder(this), false);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException"})
|
||||
@@ -109,10 +108,9 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
return stub.getChildrenByType(JavaStubElementTypes.IMPORT_LIST, PsiImportList.ARRAY_FACTORY)[0];
|
||||
}
|
||||
|
||||
ASTNode node = calcTreeElement().findChildByType(JavaElementType.IMPORT_LIST);
|
||||
assert node != null;
|
||||
|
||||
return (PsiImportList)node.getPsi();
|
||||
final ASTNode node = calcTreeElement().findChildByType(JavaElementType.IMPORT_LIST);
|
||||
assert node != null : getFileType();
|
||||
return SourceTreeToPsiMap.treeToPsiNotNull(node);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -185,50 +183,32 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
|
||||
private static class StaticImportFilteringProcessor implements PsiScopeProcessor {
|
||||
private final PsiScopeProcessor myDelegate;
|
||||
private String myNameToFilter;
|
||||
private boolean myIsProcessingOnDemand;
|
||||
private final Collection<String> myHiddenNames = new HashSet<String>();
|
||||
private final Collection<PsiElement> myCollectedElements = new HashSet<PsiElement>();
|
||||
|
||||
private StaticImportFilteringProcessor(PsiScopeProcessor delegate, String nameToFilter) {
|
||||
public StaticImportFilteringProcessor(final PsiScopeProcessor delegate) {
|
||||
myDelegate = delegate;
|
||||
myNameToFilter = nameToFilter;
|
||||
}
|
||||
|
||||
public void setNameToFilter(@Nullable String nameToFilter) {
|
||||
myNameToFilter = nameToFilter;
|
||||
}
|
||||
|
||||
public <T> T getHint(Key<T> hintKey) {
|
||||
public <T> T getHint(final Key<T> hintKey) {
|
||||
return myDelegate.getHint(hintKey);
|
||||
}
|
||||
|
||||
public void handleEvent(Event event, Object associated) {
|
||||
@Override
|
||||
public void handleEvent(final Event event, final Object associated) {
|
||||
if (JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT.equals(event)) {
|
||||
if (associated instanceof PsiImportStaticStatement) {
|
||||
final PsiImportStaticStatement importStaticStatement = (PsiImportStaticStatement)associated;
|
||||
if (importStaticStatement.isOnDemand()) {
|
||||
myIsProcessingOnDemand = true;
|
||||
}
|
||||
else {
|
||||
myIsProcessingOnDemand = false;
|
||||
myHiddenNames.add(importStaticStatement.getReferenceName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
myIsProcessingOnDemand = false;
|
||||
final PsiImportStaticStatement importStaticStatement = (PsiImportStaticStatement)associated;
|
||||
myIsProcessingOnDemand = importStaticStatement.isOnDemand();
|
||||
if (!myIsProcessingOnDemand) {
|
||||
myHiddenNames.add(importStaticStatement.getReferenceName());
|
||||
}
|
||||
}
|
||||
|
||||
myDelegate.handleEvent(event, associated);
|
||||
}
|
||||
|
||||
public boolean execute(PsiElement element, ResolveState state) {
|
||||
public boolean execute(final PsiElement element, final ResolveState state) {
|
||||
if (element instanceof PsiModifierListOwner && ((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (myNameToFilter != null &&
|
||||
!(element instanceof PsiNamedElement && myNameToFilter.equals(((PsiNamedElement)element).getName()))) {
|
||||
return true;
|
||||
}
|
||||
if (element instanceof PsiNamedElement && myIsProcessingOnDemand) {
|
||||
final String name = ((PsiNamedElement)element).getName();
|
||||
if (myHiddenNames.contains(name)) return true;
|
||||
@@ -241,12 +221,15 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
}
|
||||
}
|
||||
|
||||
public boolean processDeclarations(@NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, PsiElement lastParent, @NotNull PsiElement place){
|
||||
public boolean processDeclarations(@NotNull final PsiScopeProcessor processor,
|
||||
@NotNull final ResolveState state,
|
||||
PsiElement lastParent,
|
||||
@NotNull PsiElement place) {
|
||||
if (processor instanceof ClassResolverProcessor && isPhysical() &&
|
||||
(getUserData(BATCH_REFERENCE_PROCESSING) == Boolean.TRUE || myResolveCache.hasUpToDateValue())) {
|
||||
final ClassResolverProcessor hint = (ClassResolverProcessor)processor;
|
||||
String name = hint.getName(state);
|
||||
MostlySingularMultiMap<String, ClassCollectingProcessor.ResultWithContext> cache = myResolveCache.getValue();
|
||||
MostlySingularMultiMap<String, SymbolCollectingProcessor.ResultWithContext> cache = myResolveCache.getValue();
|
||||
MyResolveCacheProcessor cacheProcessor = new MyResolveCacheProcessor(processor, state);
|
||||
return name != null ? cache.processForKey(name, cacheProcessor) : cache.processAllValues(cacheProcessor);
|
||||
}
|
||||
@@ -254,29 +237,30 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
return processDeclarationsNoGuess(processor, state, lastParent, place);
|
||||
}
|
||||
|
||||
private boolean processDeclarationsNoGuess(PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place){
|
||||
private boolean processDeclarationsNoGuess(PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place) {
|
||||
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
|
||||
final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
|
||||
final NameHint nameHint = processor.getHint(NameHint.KEY);
|
||||
final String name = nameHint != null ? nameHint.getName(state) : null;
|
||||
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)){
|
||||
final PsiImportList importList = getImportList();
|
||||
|
||||
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
|
||||
final PsiClass[] classes = getClasses();
|
||||
for (PsiClass aClass : classes) {
|
||||
if (!processor.execute(aClass, state)) return false;
|
||||
}
|
||||
|
||||
PsiImportList importList = getImportList();
|
||||
PsiImportStatement[] importStatements = importList.getImportStatements();
|
||||
final PsiImportStatement[] importStatements = importList.getImportStatements();
|
||||
|
||||
//Single-type processing
|
||||
// single-type processing
|
||||
for (PsiImportStatement statement : importStatements) {
|
||||
if (!statement.isOnDemand()) {
|
||||
if (name != null) {
|
||||
String refText = statement.getQualifiedName();
|
||||
final String refText = statement.getQualifiedName();
|
||||
if (refText == null || !refText.endsWith(name)) continue;
|
||||
}
|
||||
|
||||
PsiElement resolved = statement.resolve();
|
||||
final PsiElement resolved = statement.resolve();
|
||||
if (resolved instanceof PsiClass) {
|
||||
processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, statement);
|
||||
if (!processor.execute(resolved, state)) return false;
|
||||
@@ -286,18 +270,17 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, null);
|
||||
|
||||
// check in current package
|
||||
String packageName = getPackageName();
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(myManager.getProject()).findPackage(packageName);
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(myManager.getProject()).findPackage(getPackageName());
|
||||
if (aPackage != null) {
|
||||
if (!aPackage.processDeclarations(processor, state, null, place)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//On demand processing
|
||||
// on-demand processing
|
||||
for (PsiImportStatement statement : importStatements) {
|
||||
if (statement.isOnDemand()) {
|
||||
PsiElement resolved = statement.resolve();
|
||||
final PsiElement resolved = statement.resolve();
|
||||
if (resolved != null) {
|
||||
processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, statement);
|
||||
processOnDemandTarget(resolved, processor, state, place);
|
||||
@@ -306,55 +289,43 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
}
|
||||
}
|
||||
|
||||
//if(classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)){
|
||||
// final PsiPackage rootPackage = JavaPsiFacade.getInstance(getProject()).findPackage("");
|
||||
// processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, rootPackage);
|
||||
// if(rootPackage != null) rootPackage.processDeclarations(processor, state, null, place);
|
||||
//}
|
||||
|
||||
final PsiImportList importList = getImportList();
|
||||
final PsiImportStaticStatement[] importStaticStatements = importList.getImportStaticStatements();
|
||||
if (importStaticStatements.length > 0) {
|
||||
final StaticImportFilteringProcessor staticImportProcessor = new StaticImportFilteringProcessor(processor, null);
|
||||
|
||||
boolean forCompletion = Boolean.TRUE.equals(processor.getHint(JavaCompletionProcessor.JAVA_COMPLETION));
|
||||
final StaticImportFilteringProcessor staticImportProcessor = new StaticImportFilteringProcessor(processor);
|
||||
final boolean forCompletion = Boolean.TRUE == processor.getHint(JavaCompletionProcessor.JAVA_COMPLETION);
|
||||
|
||||
// single member processing
|
||||
for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
|
||||
if (!importStaticStatement.isOnDemand() && !forCompletion) {
|
||||
final String referenceName = importStaticStatement.getReferenceName();
|
||||
final PsiClass targetElement = importStaticStatement.resolveTargetClass();
|
||||
if (targetElement != null) {
|
||||
staticImportProcessor.setNameToFilter(referenceName);
|
||||
if (importStaticStatement.isOnDemand() || forCompletion) continue;
|
||||
final PsiJavaCodeReferenceElement reference = importStaticStatement.getImportReference();
|
||||
if (reference != null) {
|
||||
final JavaResolveResult[] results = reference.multiResolve(false);
|
||||
if (results.length > 0) {
|
||||
staticImportProcessor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, importStaticStatement);
|
||||
final boolean result = targetElement.processDeclarations(staticImportProcessor, state, lastParent, place);
|
||||
if (!result) return false;
|
||||
for (JavaResolveResult result : results) {
|
||||
if (!staticImportProcessor.execute(result.getElement(), state)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// on-demand processing
|
||||
for (PsiImportStaticStatement importStaticStatement : importStaticStatements) {
|
||||
if (importStaticStatement.isOnDemand()) {
|
||||
final PsiClass targetElement = importStaticStatement.resolveTargetClass();
|
||||
if (targetElement != null) {
|
||||
staticImportProcessor.setNameToFilter(null);
|
||||
staticImportProcessor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, importStaticStatement);
|
||||
final boolean result = targetElement.processDeclarations(staticImportProcessor, state, lastParent, place);
|
||||
if (!result) return false;
|
||||
}
|
||||
if (!importStaticStatement.isOnDemand()) continue;
|
||||
final PsiClass targetElement = importStaticStatement.resolveTargetClass();
|
||||
if (targetElement != null) {
|
||||
staticImportProcessor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, importStaticStatement);
|
||||
if (!targetElement.processDeclarations(staticImportProcessor, state, lastParent, place)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
staticImportProcessor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, null);
|
||||
}
|
||||
|
||||
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)){
|
||||
if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
|
||||
processor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, null);
|
||||
|
||||
PsiJavaCodeReferenceElement[] implicitlyImported = getImplicitlyImportedPackageReferences();
|
||||
final PsiJavaCodeReferenceElement[] implicitlyImported = getImplicitlyImportedPackageReferences();
|
||||
for (PsiJavaCodeReferenceElement aImplicitlyImported : implicitlyImported) {
|
||||
PsiElement resolved = aImplicitlyImported.resolve();
|
||||
final PsiElement resolved = aImplicitlyImported.resolve();
|
||||
if (resolved != null) {
|
||||
if (!processOnDemandTarget(resolved, processor, state, place)) return false;
|
||||
}
|
||||
@@ -364,7 +335,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean processOnDemandTarget (PsiElement target, PsiScopeProcessor processor, ResolveState substitutor, PsiElement place) {
|
||||
private static boolean processOnDemandTarget(PsiElement target, PsiScopeProcessor processor, ResolveState substitutor, PsiElement place) {
|
||||
if (target instanceof PsiPackage) {
|
||||
if (!target.processDeclarations(processor, substitutor, null, place)) {
|
||||
return false;
|
||||
@@ -474,17 +445,21 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
return defaultLanguageLevel;
|
||||
}
|
||||
|
||||
private class MyCacheBuilder implements CachedValueProvider<MostlySingularMultiMap<String, ClassCollectingProcessor.ResultWithContext>> {
|
||||
public Result<MostlySingularMultiMap<String, ClassCollectingProcessor.ResultWithContext>> compute() {
|
||||
ClassCollectingProcessor p = new ClassCollectingProcessor();
|
||||
processDeclarationsNoGuess(p, ResolveState.initial(),
|
||||
PsiJavaFileBaseImpl.this,
|
||||
PsiJavaFileBaseImpl.this);
|
||||
return new Result<MostlySingularMultiMap<String, ClassCollectingProcessor.ResultWithContext>>(p.getResults(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
|
||||
private static class MyCacheBuilder implements CachedValueProvider<MostlySingularMultiMap<String, SymbolCollectingProcessor.ResultWithContext>> {
|
||||
private final PsiJavaFileBaseImpl myFile;
|
||||
|
||||
public MyCacheBuilder(PsiJavaFileBaseImpl file) {
|
||||
myFile = file;
|
||||
}
|
||||
|
||||
public Result<MostlySingularMultiMap<String, SymbolCollectingProcessor.ResultWithContext>> compute() {
|
||||
SymbolCollectingProcessor p = new SymbolCollectingProcessor();
|
||||
myFile.processDeclarationsNoGuess(p, ResolveState.initial(), myFile, myFile);
|
||||
return Result.create(p.getResults(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyResolveCacheProcessor implements Processor<ClassCollectingProcessor.ResultWithContext> {
|
||||
private static class MyResolveCacheProcessor implements Processor<SymbolCollectingProcessor.ResultWithContext> {
|
||||
private final PsiScopeProcessor myProcessor;
|
||||
private final ResolveState myState;
|
||||
|
||||
@@ -493,7 +468,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
myState = state;
|
||||
}
|
||||
|
||||
public boolean process(ClassCollectingProcessor.ResultWithContext result) {
|
||||
public boolean process(SymbolCollectingProcessor.ResultWithContext result) {
|
||||
myProcessor.handleEvent(JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT, result.getFileContext());
|
||||
return myProcessor.execute(result.getElement(), myState);
|
||||
}
|
||||
|
||||
@@ -93,17 +93,18 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
|
||||
}
|
||||
|
||||
private static boolean isImported(PsiElement fileContext) {
|
||||
return fileContext instanceof PsiImportStatement;
|
||||
return fileContext instanceof PsiImportStatementBase;
|
||||
}
|
||||
|
||||
private boolean isOnDemand(PsiElement fileContext, PsiClass psiClass) {
|
||||
if (isImported(fileContext)) {
|
||||
return ((PsiImportStatementBase)fileContext).isOnDemand();
|
||||
}
|
||||
|
||||
String fqn = psiClass.getQualifiedName();
|
||||
if (fqn == null) return false;
|
||||
String packageName = StringUtil.getPackageName(fqn);
|
||||
if ("java.lang".equals(packageName)) return true;
|
||||
if (CommonClassNames.DEFAULT_PACKAGE.equals(packageName)) return true;
|
||||
|
||||
// class from my package imported implicitly
|
||||
PsiFile file = myPlace == null ? null : FileContextUtil.getContextFile(myPlace);
|
||||
@@ -138,7 +139,9 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
|
||||
// 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.DOMINATED_BY;
|
||||
}
|
||||
if (!isDefault && otherDefault) {
|
||||
return Domination.DOMINATES;
|
||||
}
|
||||
@@ -146,7 +149,9 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
|
||||
// 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.DOMINATED_BY;
|
||||
}
|
||||
if (!myOnDemand && otherOnDemand) {
|
||||
return Domination.DOMINATES;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -173,7 +173,7 @@ public class JavaResolveUtil {
|
||||
final ResolveState state,
|
||||
final PsiElement place,
|
||||
PsiManager manager) {
|
||||
PsiPackage langPackage = JavaPsiFacade.getInstance(manager.getProject()).findPackage("java.lang");
|
||||
PsiPackage langPackage = JavaPsiFacade.getInstance(manager.getProject()).findPackage(CommonClassNames.DEFAULT_PACKAGE);
|
||||
if (langPackage != null) {
|
||||
if (!langPackage.processDeclarations(processor, state, null, place)) return false;
|
||||
}
|
||||
|
||||
+9
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,10 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.psi.impl.source.resolve;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -28,17 +24,22 @@ import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.scope.JavaScopeProcessorEvent;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
|
||||
public class ClassCollectingProcessor extends BaseScopeProcessor implements ElementClassHint {
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class SymbolCollectingProcessor extends BaseScopeProcessor implements ElementClassHint {
|
||||
private final MostlySingularMultiMap<String, ResultWithContext> myResult = new MostlySingularMultiMap<String, ResultWithContext>();
|
||||
private PsiElement myCurrentFileContext = null;
|
||||
|
||||
@Override
|
||||
public <T> T getHint(Key<T> hintKey) {
|
||||
if (hintKey == KEY) return (T)this;
|
||||
if (hintKey == KEY) {
|
||||
//noinspection unchecked
|
||||
return (T)this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleEvent(Event event, Object associated) {
|
||||
if (event == JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT) {
|
||||
+2
-2
@@ -22,8 +22,8 @@ import static <error descr="Field 'IF' is ambiguous in a single static import">x
|
||||
class Usage {
|
||||
void use() {
|
||||
m(Base1.F); //Base1.m(int)
|
||||
m(F); //Base2.m(float)
|
||||
F.class.getName(); // Base2.F
|
||||
m(F); //Base2.m(float), float Base2.F
|
||||
F.class.getName(); // class Base2.F
|
||||
m(<error descr="Reference to 'IF' is ambiguous, both 'field I1.IF' and 'field I2.IF' match">IF</error>);
|
||||
}
|
||||
}
|
||||
+2
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import x.E;
|
||||
import static x.Base1.*;
|
||||
import static x.Base2.*;
|
||||
|
||||
@@ -20,5 +21,6 @@ class UsageOnDemand {
|
||||
void use() {
|
||||
m(1); //Base1.m(int)
|
||||
m(1.0f); //Base2.m(float)
|
||||
E.class.getName();
|
||||
}
|
||||
}
|
||||
+1
@@ -20,4 +20,5 @@ public class Base2 extends Base1 {
|
||||
public static void m(float f) { }
|
||||
public static class F { }
|
||||
public interface II extends I1, I2 { }
|
||||
public enum E { }
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package x;
|
||||
|
||||
public class E { }
|
||||
@@ -21,6 +21,8 @@ import org.jetbrains.annotations.NonNls;
|
||||
* @author peter
|
||||
*/
|
||||
public interface CommonClassNames {
|
||||
@NonNls String DEFAULT_PACKAGE = "java.lang";
|
||||
|
||||
@NonNls String JAVA_LANG_OBJECT = "java.lang.Object";
|
||||
@NonNls String JAVA_LANG_CLASS = "java.lang.Class";
|
||||
@NonNls String JAVA_LANG_ENUM = "java.lang.Enum";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,16 +22,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PsiScopeProcessor {
|
||||
interface Event {
|
||||
Event SET_DECLARATION_HOLDER = new Event() {
|
||||
};
|
||||
Event SET_DECLARATION_HOLDER = new Event() { };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element candidate element.
|
||||
* @param state current state of resolver.
|
||||
* @return false to stop processing.
|
||||
*/
|
||||
boolean execute(PsiElement element, ResolveState state);
|
||||
|
||||
@Nullable
|
||||
<T> T getHint(Key<T> hintKey);
|
||||
void handleEvent(Event event, Object associated);
|
||||
|
||||
void handleEvent(Event event, @Nullable Object associated);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,16 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.psi.scope;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
|
||||
public abstract class BaseScopeProcessor implements PsiScopeProcessor{
|
||||
|
||||
public abstract class BaseScopeProcessor implements PsiScopeProcessor {
|
||||
public <T> T getHint(Key<T> hintKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleEvent(Event event, Object associated){}
|
||||
public void handleEvent(Event event, Object associated) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user