mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull
This commit is contained in:
@@ -124,7 +124,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCollectInformation(final ProgressIndicator progress) {
|
||||
public void doCollectInformation(@NotNull final ProgressIndicator progress) {
|
||||
DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
|
||||
final FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)daemonCodeAnalyzer).getFileStatusMap();
|
||||
final List<HighlightInfo> highlights = new ArrayList<HighlightInfo>();
|
||||
@@ -190,7 +190,9 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
|
||||
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable, @NotNull final PsiFile file, @NotNull final Editor editor) {
|
||||
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
|
||||
@NotNull final PsiFile file,
|
||||
@NotNull final Editor editor) {
|
||||
final long stamp = editor.getDocument().getModificationStamp();
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -220,7 +222,9 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
// returns true if error highlight was created
|
||||
private boolean collectHighlights(@NotNull Collection<PsiElement> elements, @NotNull final List<HighlightInfo> result, @NotNull ProgressIndicator progress) throws ProcessCanceledException {
|
||||
private boolean collectHighlights(@NotNull Collection<PsiElement> elements,
|
||||
@NotNull final List<HighlightInfo> result,
|
||||
@NotNull ProgressIndicator progress) throws ProcessCanceledException {
|
||||
ApplicationManager.getApplication().assertReadAccessAllowed();
|
||||
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
|
||||
@@ -244,15 +248,15 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
|
||||
myDeadCodeInfoType = myDeadCodeKey == null ? null : new HighlightInfoType.HighlightInfoTypeImpl(profile.getErrorLevel(myDeadCodeKey, myFile).getSeverity(), HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
|
||||
myDeadCodeInfoType = myDeadCodeKey == null
|
||||
? null
|
||||
: new HighlightInfoType.HighlightInfoTypeImpl(profile.getErrorLevel(myDeadCodeKey, myFile).getSeverity(),
|
||||
HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
|
||||
|
||||
GlobalUsageHelper helper = new GlobalUsageHelper() {
|
||||
@Override
|
||||
public boolean shouldCheckUsages(@NotNull PsiMember member) {
|
||||
if (myInLibrary) return false;
|
||||
if (!myDeadCodeEnabled) return false;
|
||||
if (myDeadCodeInspection.isEntryPoint(member)) return false;
|
||||
return true;
|
||||
return !myInLibrary && myDeadCodeEnabled && !myDeadCodeInspection.isEntryPoint(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,28 +309,28 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
if (PsiUtilCore.hasErrorElementChild(parent)) return null;
|
||||
|
||||
if (parent instanceof PsiLocalVariable && myUnusedSymbolInspection.LOCAL_VARIABLE) {
|
||||
return processLocalVariable((PsiLocalVariable)parent, progress);
|
||||
return processLocalVariable((PsiLocalVariable)parent, identifier, progress);
|
||||
}
|
||||
if (parent instanceof PsiField && myUnusedSymbolInspection.FIELD) {
|
||||
return processField((PsiField)parent, identifier, progress, helper);
|
||||
}
|
||||
if (parent instanceof PsiParameter && myUnusedSymbolInspection.PARAMETER) {
|
||||
if (InspectionManagerEx.isSuppressed(identifier, UnusedParametersInspection.SHORT_NAME)) return null;
|
||||
return processParameter((PsiParameter)parent, progress);
|
||||
return processParameter((PsiParameter)parent, identifier, progress);
|
||||
}
|
||||
if (parent instanceof PsiMethod && myUnusedSymbolInspection.METHOD) {
|
||||
return processMethod((PsiMethod)parent, progress, helper);
|
||||
return processMethod((PsiMethod)parent, identifier, progress, helper);
|
||||
}
|
||||
if (parent instanceof PsiClass && myUnusedSymbolInspection.CLASS) {
|
||||
return processClass((PsiClass)parent, progress, helper);
|
||||
return processClass((PsiClass)parent, identifier, progress, helper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processLocalVariable(PsiLocalVariable variable, ProgressIndicator progress) {
|
||||
PsiIdentifier identifier = variable.getNameIdentifier();
|
||||
if (identifier == null) return null;
|
||||
private HighlightInfo processLocalVariable(@NotNull PsiLocalVariable variable,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress) {
|
||||
if (variable instanceof PsiResourceVariable && PsiUtil.isIgnoredName(variable.getName())) return null;
|
||||
if (isImplicitUsage(variable, progress)) return null;
|
||||
|
||||
@@ -404,7 +408,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processField(final PsiField field, final PsiIdentifier identifier, ProgressIndicator progress, GlobalUsageHelper helper) {
|
||||
private HighlightInfo processField(@NotNull final PsiField field,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress,
|
||||
@NotNull GlobalUsageHelper helper) {
|
||||
if (field.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
if (!myRefCountHolder.isReferenced(field) && !isImplicitUsage(field, progress)) {
|
||||
if (HighlightUtil.isSerializationImplicitlyUsedField(field)) {
|
||||
@@ -449,7 +456,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return null;
|
||||
}
|
||||
else if (isFieldUnused(field, progress, helper)) {
|
||||
return formatUnusedSymbolHighlightInfo("field.is.not.used", field, "fields", myDeadCodeKey, myDeadCodeInfoType);
|
||||
return formatUnusedSymbolHighlightInfo("field.is.not.used", field, "fields", myDeadCodeKey, myDeadCodeInfoType, identifier);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -479,7 +486,9 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processParameter(PsiParameter parameter, ProgressIndicator progress) {
|
||||
private HighlightInfo processParameter(@NotNull PsiParameter parameter,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress) {
|
||||
PsiElement declarationScope = parameter.getDeclarationScope();
|
||||
if (declarationScope instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)declarationScope;
|
||||
@@ -494,7 +503,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
!HighlightMethodUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
!PsiClassImplUtil.isMainMethod(method)) {
|
||||
if (UnusedSymbolLocalInspection.isInjected(method)) return null;
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, progress);
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, identifier, progress);
|
||||
if (highlightInfo != null) {
|
||||
final ArrayList<IntentionAction> options = new ArrayList<IntentionAction>();
|
||||
options.addAll(IntentionManager.getInstance().getStandardIntentionOptions(myUnusedSymbolKey, myFile));
|
||||
@@ -509,7 +518,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
}
|
||||
else if (declarationScope instanceof PsiForeachStatement && !PsiUtil.isIgnoredName(parameter.getName())) {
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, progress);
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, identifier, progress);
|
||||
if (highlightInfo != null) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new RenameToIgnoredFix(parameter), myUnusedSymbolKey);
|
||||
return highlightInfo;
|
||||
@@ -520,10 +529,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo checkUnusedParameter(final PsiParameter parameter, ProgressIndicator progress) {
|
||||
private HighlightInfo checkUnusedParameter(@NotNull PsiParameter parameter,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress) {
|
||||
if (!myRefCountHolder.isReferenced(parameter) && !isImplicitUsage(parameter, progress)) {
|
||||
PsiIdentifier identifier = parameter.getNameIdentifier();
|
||||
assert identifier != null;
|
||||
String message = JavaErrorMessages.message("parameter.is.not.used", identifier.getText());
|
||||
return createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL);
|
||||
}
|
||||
@@ -531,7 +540,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processMethod(final PsiMethod method, ProgressIndicator progress, GlobalUsageHelper helper) {
|
||||
private HighlightInfo processMethod(@NotNull final PsiMethod method,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress,
|
||||
@NotNull GlobalUsageHelper helper) {
|
||||
if (isMethodReferenced(method, progress, helper)) return null;
|
||||
HighlightInfoType highlightInfoType;
|
||||
HighlightDisplayKey highlightDisplayKey;
|
||||
@@ -548,7 +560,6 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
String symbolName = HighlightMessageUtil.getSymbolName(method, PsiSubstitutor.EMPTY);
|
||||
String message = JavaErrorMessages.message(key, symbolName);
|
||||
PsiIdentifier identifier = method.getNameIdentifier();
|
||||
final HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, highlightInfoType);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SafeDeleteFix(method), highlightDisplayKey);
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes(method, new Processor<String>() {
|
||||
@@ -655,7 +666,10 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processClass(PsiClass aClass, ProgressIndicator progress, GlobalUsageHelper helper) {
|
||||
private HighlightInfo processClass(@NotNull PsiClass aClass,
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress,
|
||||
@NotNull GlobalUsageHelper helper) {
|
||||
if (isClassUsed(aClass, progress, helper)) return null;
|
||||
|
||||
String pattern;
|
||||
@@ -683,7 +697,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
highlightDisplayKey = myDeadCodeKey;
|
||||
highlightInfoType = myDeadCodeInfoType;
|
||||
}
|
||||
return formatUnusedSymbolHighlightInfo(pattern, aClass, "classes", highlightDisplayKey, highlightInfoType);
|
||||
return formatUnusedSymbolHighlightInfo(pattern, aClass, "classes", highlightDisplayKey, highlightInfoType, identifier);
|
||||
}
|
||||
|
||||
public static boolean isClassUsed(PsiClass aClass, ProgressIndicator progress, GlobalUsageHelper helper) {
|
||||
@@ -706,14 +720,14 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return !weAreSureThereAreNoUsages(aClass, progress, helper);
|
||||
}
|
||||
|
||||
private static HighlightInfo formatUnusedSymbolHighlightInfo(@PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String pattern,
|
||||
final PsiNameIdentifierOwner aClass,
|
||||
final String element,
|
||||
final HighlightDisplayKey highlightDisplayKey,
|
||||
final HighlightInfoType highlightInfoType) {
|
||||
private static HighlightInfo formatUnusedSymbolHighlightInfo(@NotNull @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String pattern,
|
||||
@NotNull final PsiNameIdentifierOwner aClass,
|
||||
@NotNull final String element,
|
||||
@NotNull HighlightDisplayKey highlightDisplayKey,
|
||||
@NotNull HighlightInfoType highlightInfoType,
|
||||
@NotNull PsiElement identifier) {
|
||||
String symbolName = aClass.getName();
|
||||
String message = JavaErrorMessages.message(pattern, symbolName);
|
||||
PsiElement identifier = aClass.getNameIdentifier();
|
||||
final HighlightInfo highlightInfo = createUnusedSymbolInfo(identifier, message, highlightInfoType);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new SafeDeleteFix(aClass), highlightDisplayKey);
|
||||
SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes((PsiModifierListOwner)aClass, new Processor<String>() {
|
||||
@@ -727,7 +741,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HighlightInfo processImport(PsiImportStatementBase importStatement, HighlightDisplayKey unusedImportKey) {
|
||||
private HighlightInfo processImport(@NotNull PsiImportStatementBase importStatement, @NotNull HighlightDisplayKey unusedImportKey) {
|
||||
// jsp include directive hack
|
||||
if (importStatement instanceof JspxImportStatement && ((JspxImportStatement)importStatement).isForeignFileImport()) return null;
|
||||
|
||||
@@ -764,7 +778,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return null;
|
||||
}
|
||||
|
||||
private HighlightInfo registerRedundantImport(PsiImportStatementBase importStatement, HighlightDisplayKey unusedImportKey) {
|
||||
private HighlightInfo registerRedundantImport(@NotNull PsiImportStatementBase importStatement, @NotNull HighlightDisplayKey unusedImportKey) {
|
||||
HighlightInfo info = HighlightInfo.createHighlightInfo(JavaHighlightInfoTypes.UNUSED_IMPORT, importStatement, InspectionsBundle.message("unused.import.statement"));
|
||||
|
||||
QuickFixAction.registerQuickFixAction(info, new OptimizeImportsFix(), unusedImportKey);
|
||||
@@ -787,7 +801,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return !errors && codeAnalyzer.canChangeFileSilently(myFile);
|
||||
}
|
||||
|
||||
private boolean containsErrorsPreventingOptimize(PsiFile file) {
|
||||
private boolean containsErrorsPreventingOptimize(@NotNull PsiFile file) {
|
||||
// ignore unresolved imports errors
|
||||
PsiImportList importList = ((PsiJavaFile)file).getImportList();
|
||||
final TextRange importsRange = importList == null ? TextRange.EMPTY_RANGE : importList.getTextRange();
|
||||
@@ -804,7 +818,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
return hasErrorsExceptUnresolvedImports;
|
||||
}
|
||||
|
||||
private static boolean isIntentionalPrivateConstructor(PsiMethod method, PsiClass containingClass) {
|
||||
private static boolean isIntentionalPrivateConstructor(@NotNull PsiMethod method, PsiClass containingClass) {
|
||||
return method.isConstructor() &&
|
||||
method.getParameterList().getParametersCount() == 0 &&
|
||||
containingClass != null &&
|
||||
|
||||
@@ -42,8 +42,9 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class AbstractQualifiedReference<T extends AbstractQualifiedReference<T>> extends ASTWrapperPsiElement implements PsiPolyVariantReference, PsiQualifiedReference {
|
||||
private static final ResolveCache.PolyVariantResolver<AbstractQualifiedReference> MY_RESOLVER = new ResolveCache.PolyVariantResolver<AbstractQualifiedReference>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(final AbstractQualifiedReference expression, final boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull final AbstractQualifiedReference expression, final boolean incompleteCode) {
|
||||
return expression.resolveInner();
|
||||
}
|
||||
};
|
||||
|
||||
+2
-1
@@ -606,8 +606,9 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
|
||||
private static class MyResolver implements ResolveCache.PolyVariantResolver<JavaClassReference> {
|
||||
private static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] resolve(JavaClassReference javaClassReference, boolean incompleteCode) {
|
||||
public JavaResolveResult[] resolve(@NotNull JavaClassReference javaClassReference, boolean incompleteCode) {
|
||||
return new JavaResolveResult[]{javaClassReference.doAdvancedResolve()};
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -108,8 +108,9 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P
|
||||
private static class Resolver implements ResolveCache.PolyVariantResolver<ClsJavaCodeReferenceElementImpl> {
|
||||
public static final Resolver INSTANCE = new Resolver();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] resolve(ClsJavaCodeReferenceElementImpl ref, boolean incompleteCode) {
|
||||
public JavaResolveResult[] resolve(@NotNull ClsJavaCodeReferenceElementImpl ref, boolean incompleteCode) {
|
||||
final JavaResolveResult resolveResult = ref.advancedResolveImpl();
|
||||
return resolveResult.getElement() == null ? JavaResolveResult.EMPTY_ARRAY : new JavaResolveResult[] {resolveResult};
|
||||
}
|
||||
|
||||
+2
-1
@@ -226,8 +226,9 @@ public class PsiImportStaticReferenceElementImpl extends CompositePsiElement imp
|
||||
private static final class OurGenericsResolver implements ResolveCache.PolyVariantResolver<PsiImportStaticReferenceElementImpl> {
|
||||
private static final OurGenericsResolver INSTANCE = new OurGenericsResolver();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] resolve(final PsiImportStaticReferenceElementImpl referenceElement, final boolean incompleteCode) {
|
||||
public JavaResolveResult[] resolve(@NotNull final PsiImportStaticReferenceElementImpl referenceElement, final boolean incompleteCode) {
|
||||
final PsiElement qualifier = referenceElement.getQualifier();
|
||||
if (!(qualifier instanceof PsiJavaCodeReferenceElement)) return JavaResolveResult.EMPTY_ARRAY;
|
||||
final PsiElement target = ((PsiJavaCodeReferenceElement)qualifier).resolve();
|
||||
|
||||
+2
-1
@@ -344,8 +344,9 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] resolve(final PsiJavaReference ref, final boolean incompleteCode) {
|
||||
public JavaResolveResult[] resolve(@NotNull final PsiJavaReference ref, final boolean incompleteCode) {
|
||||
final JavaResolveResult[] result = _resolve(ref, incompleteCode);
|
||||
if (result.length > 0 && result[0].getElement() instanceof PsiClass) {
|
||||
final PsiType[] parameters = ((PsiJavaCodeReferenceElement)ref).getTypeParameters();
|
||||
|
||||
+13
-6
@@ -51,7 +51,10 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.CharTable;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -187,9 +190,11 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
private static final class OurGenericsResolver implements ResolveCache.PolyVariantResolver<PsiJavaReference> {
|
||||
private static final OurGenericsResolver INSTANCE = new OurGenericsResolver();
|
||||
|
||||
@NotNull
|
||||
private static JavaResolveResult[] _resolve(boolean incompleteCode, PsiReferenceExpressionImpl expression) {
|
||||
CompositeElement treeParent = expression.getTreeParent();
|
||||
IElementType parentType = treeParent != null ? treeParent.getElementType() : null;
|
||||
IElementType parentType = treeParent == null ? null : treeParent.getElementType();
|
||||
|
||||
final JavaResolveResult[] result = expression.resolve(parentType);
|
||||
|
||||
if (incompleteCode && parentType != JavaElementType.REFERENCE_EXPRESSION && result.length == 0) {
|
||||
@@ -199,7 +204,8 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaResolveResult[] resolve(PsiJavaReference ref, boolean incompleteCode) {
|
||||
@NotNull
|
||||
public JavaResolveResult[] resolve(@NotNull PsiJavaReference ref, boolean incompleteCode) {
|
||||
final JavaResolveResult[] result = _resolve(incompleteCode, (PsiReferenceExpressionImpl)ref);
|
||||
if (result.length > 0 && result[0].getElement() instanceof PsiClass) {
|
||||
final PsiType[] parameters = ((PsiJavaCodeReferenceElement)ref).getTypeParameters();
|
||||
@@ -215,10 +221,8 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaResolveResult[] resolve(IElementType parentType) {
|
||||
if (parentType == null) {
|
||||
parentType = getTreeParent() != null ? getTreeParent().getElementType() : null;
|
||||
}
|
||||
if (parentType == JavaElementType.REFERENCE_EXPRESSION) {
|
||||
JavaResolveResult[] result = resolveToVariable();
|
||||
if (result.length > 0) {
|
||||
@@ -240,6 +244,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
return resolveToVariable();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaResolveResult[] resolveToMethod() {
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)getParent();
|
||||
final MethodResolverProcessor processor = new MethodResolverProcessor(methodCall);
|
||||
@@ -252,6 +257,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
return processor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaResolveResult[] resolveToPackage() {
|
||||
final String packageName = getCachedTextSkipWhiteSpaceAndComments();
|
||||
final PsiManager manager = getManager();
|
||||
@@ -277,6 +283,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
|
||||
return processor.getResult();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaResolveResult[] resolveToVariable() {
|
||||
final VariableResolverProcessor processor = new VariableResolverProcessor(this);
|
||||
PsiScopesUtil.resolveAndWalk(processor, this, null);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.scope.NameHint;
|
||||
import com.intellij.psi.scope.PsiConflictResolver;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -74,6 +75,7 @@ public class ConflictFilterProcessor extends FilterScopeProcessor<CandidateInfo>
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaResolveResult[] getResult() {
|
||||
if (myCachedResult == null) {
|
||||
final List<CandidateInfo> conflicts = getResults();
|
||||
|
||||
@@ -74,6 +74,7 @@ public class PsiElementResolveResult implements ResolveResult{
|
||||
(myElement instanceof PsiNamedElement ? ((PsiNamedElement)myElement).getName() : myElement.getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveResult[] createResults(@Nullable Collection<? extends PsiElement> elements) {
|
||||
if (elements == null || elements.isEmpty()) return EMPTY_ARRAY;
|
||||
|
||||
@@ -85,6 +86,7 @@ public class PsiElementResolveResult implements ResolveResult{
|
||||
return results;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveResult[] createResults(@Nullable PsiElement[] elements) {
|
||||
if (elements == null || elements.length == 0) return EMPTY_ARRAY;
|
||||
|
||||
|
||||
@@ -55,9 +55,12 @@ public class ResolveCache {
|
||||
}
|
||||
|
||||
public interface AbstractResolver<TRef extends PsiReference,TResult> {
|
||||
TResult resolve(TRef ref, boolean incompleteCode);
|
||||
TResult resolve(@NotNull TRef ref, boolean incompleteCode);
|
||||
}
|
||||
public interface PolyVariantResolver<T extends PsiPolyVariantReference> extends AbstractResolver<T,ResolveResult[]> {
|
||||
@Override
|
||||
@NotNull
|
||||
ResolveResult[] resolve(@NotNull T t, boolean incompleteCode);
|
||||
}
|
||||
|
||||
public interface Resolver extends AbstractResolver<PsiReference,PsiElement>{
|
||||
|
||||
+2
-1
@@ -57,8 +57,9 @@ public abstract class PsiPolyVariantCachingReference implements PsiPolyVariantRe
|
||||
private static class MyResolver implements ResolveCache.PolyVariantResolver<PsiPolyVariantReference> {
|
||||
private static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(PsiPolyVariantReference reference, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull PsiPolyVariantReference reference, boolean incompleteCode) {
|
||||
return ((PsiPolyVariantCachingReference)reference).resolveInner(incompleteCode);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.intellij.psi.ElementManipulators;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.source.resolve.ResolveCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public abstract class CachingReference implements PsiReference, EmptyResolveMess
|
||||
private static final MyResolver INSTANCE = new MyResolver();
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiElement resolve(PsiReference ref, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference ref, boolean incompleteCode) {
|
||||
return ((CachingReference)ref).resolveInner();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -139,6 +139,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
return innerResolve(getFileReferenceSet().isCaseSensitive());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ResolveResult[] innerResolve(boolean caseSensitive) {
|
||||
final String referenceText = getText();
|
||||
if (referenceText.isEmpty() && myIndex == 0) {
|
||||
@@ -586,8 +587,9 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
static class MyResolver implements ResolveCache.PolyVariantResolver<FileReference> {
|
||||
static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(FileReference ref, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull FileReference ref, boolean incompleteCode) {
|
||||
return ref.innerResolve(ref.getFileReferenceSet().isCaseSensitive());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -102,8 +102,9 @@ public class AndroidResourceReference extends PsiReferenceBase.Poly<XmlElement>
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
return ResolveCache.getInstance(myElement.getProject())
|
||||
.resolveWithCaching(this, new ResolveCache.PolyVariantResolver<AndroidResourceReference>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(AndroidResourceReference reference, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull AndroidResourceReference reference, boolean incompleteCode) {
|
||||
return resolveInner();
|
||||
}
|
||||
}, false, incompleteCode);
|
||||
|
||||
@@ -63,13 +63,15 @@ public class OnClickConverter extends Converter<String> implements CustomReferen
|
||||
public ResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
return ResolveCache.getInstance(myElement.getProject())
|
||||
.resolveWithCaching(this, new ResolveCache.PolyVariantResolver<MyReference>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(MyReference myReference, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull MyReference myReference, boolean incompleteCode) {
|
||||
return resolveInner();
|
||||
}
|
||||
}, false, incompleteCode);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ResolveResult[] resolveInner() {
|
||||
final String methodName = myElement.getValue();
|
||||
if (methodName == null) {
|
||||
|
||||
@@ -250,7 +250,7 @@ public class PackageClassConverter extends ResolvingConverter<PsiClass> implemen
|
||||
return ResolveCache.getInstance(myElement.getProject()).resolveWithCaching(this, new ResolveCache.Resolver() {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve(PsiReference reference, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference reference, boolean incompleteCode) {
|
||||
return resolveInner();
|
||||
}
|
||||
}, false, false);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class AntDomMacrodefAttributeReference extends AntDomReferenceBase{
|
||||
|
||||
static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
public PsiElement resolve(PsiReference psiReference, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
|
||||
final PsiElement element = psiReference.getElement();
|
||||
if (element == null) {
|
||||
return null;
|
||||
|
||||
@@ -186,7 +186,8 @@ public class AntDomPropertyReference extends PsiPolyVariantReferenceBase<PsiElem
|
||||
private static class MyResolver implements ResolveCache.PolyVariantResolver<AntDomPropertyReference> {
|
||||
static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
public ResolveResult[] resolve(AntDomPropertyReference antDomPropertyReference, boolean incompleteCode) {
|
||||
@NotNull
|
||||
public ResolveResult[] resolve(@NotNull AntDomPropertyReference antDomPropertyReference, boolean incompleteCode) {
|
||||
final List<ResolveResult> result = new ArrayList<ResolveResult>();
|
||||
final AntDomProject project = antDomPropertyReference.myInvocationContextElement.getParentOfType(AntDomProject.class, true);
|
||||
if (project != null) {
|
||||
|
||||
@@ -198,7 +198,7 @@ class AntDomTargetReference extends AntDomReferenceBase implements BindablePsiRe
|
||||
private static class MyResolver implements ResolveCache.Resolver {
|
||||
static final MyResolver INSTANCE = new MyResolver();
|
||||
|
||||
public PsiElement resolve(PsiReference psiReference, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
|
||||
final TargetResolver.Result result = ((AntDomTargetReference)psiReference).doResolve(psiReference.getCanonicalText());
|
||||
if (result == null) {
|
||||
return null;
|
||||
|
||||
+2
-1
@@ -199,8 +199,9 @@ public class GrAssignmentExpressionImpl extends GrExpressionImpl implements GrAs
|
||||
|
||||
private static final ResolveCache.PolyVariantResolver<GrAssignmentExpressionImpl> RESOLVER =
|
||||
new ResolveCache.PolyVariantResolver<GrAssignmentExpressionImpl>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GroovyResolveResult[] resolve(GrAssignmentExpressionImpl assignmentExpression, boolean incompleteCode) {
|
||||
public GroovyResolveResult[] resolve(@NotNull GrAssignmentExpressionImpl assignmentExpression, boolean incompleteCode) {
|
||||
final IElementType opType = assignmentExpression.getOperationToken();
|
||||
if (opType == null || opType == GroovyTokenTypes.mASSIGN) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
|
||||
+2
-1
@@ -44,8 +44,9 @@ public abstract class GrBinaryExpressionImpl extends GrExpressionImpl implements
|
||||
|
||||
private static final ResolveCache.PolyVariantResolver<GrBinaryExpressionImpl> RESOLVER =
|
||||
new ResolveCache.PolyVariantResolver<GrBinaryExpressionImpl>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GroovyResolveResult[] resolve(GrBinaryExpressionImpl binary, boolean incompleteCode) {
|
||||
public GroovyResolveResult[] resolve(@NotNull GrBinaryExpressionImpl binary, boolean incompleteCode) {
|
||||
final IElementType opType = binary.getOperationTokenType();
|
||||
|
||||
final PsiType lType = binary.getLeftOperand().getType();
|
||||
|
||||
+4
-1
@@ -231,6 +231,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
* priority: inside class C: local variable, c.method, c.property, c.getter
|
||||
* in other places: local variable, c.method, c.getter, c.property
|
||||
*/
|
||||
@NotNull
|
||||
private GroovyResolveResult[] resolveMethodOrProperty(boolean allVariants, @Nullable GrExpression upToArgument, boolean genericsMatter) {
|
||||
final String name = getReferenceName();
|
||||
if (name == null) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
@@ -467,7 +468,8 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
private static final ResolveCache.PolyVariantResolver<GrReferenceExpressionImpl> POLY_RESOLVER =
|
||||
new ResolveCache.PolyVariantResolver<GrReferenceExpressionImpl>() {
|
||||
public GroovyResolveResult[] resolve(GrReferenceExpressionImpl refExpr, boolean incompleteCode) {
|
||||
@NotNull
|
||||
public GroovyResolveResult[] resolve(@NotNull GrReferenceExpressionImpl refExpr, boolean incompleteCode) {
|
||||
return refExpr.doPolyResolve(incompleteCode, true);
|
||||
}
|
||||
};
|
||||
@@ -635,6 +637,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private GroovyResolveResult[] doPolyResolve(boolean incompleteCode, boolean genericsMatter) {
|
||||
String name = getReferenceName();
|
||||
if (name == null) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
+2
-1
@@ -112,8 +112,9 @@ public abstract class GrThisSuperReferenceExpressionBase extends GrExpressionImp
|
||||
}
|
||||
|
||||
static class OurResolver implements ResolveCache.PolyVariantResolver<GrThisSuperReferenceExpressionBase> {
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(GrThisSuperReferenceExpressionBase ref, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull GrThisSuperReferenceExpressionBase ref, boolean incompleteCode) {
|
||||
final PsiElement resolved = ref.resolveInner();
|
||||
if (resolved == null) return ResolveResult.EMPTY_ARRAY;
|
||||
return new ResolveResult[]{new GroovyResolveResultImpl(resolved, true)};
|
||||
|
||||
+2
-1
@@ -74,8 +74,9 @@ public class GrUnaryExpressionImpl extends GrExpressionImpl implements GrUnaryEx
|
||||
|
||||
private static final ResolveCache.PolyVariantResolver<GrUnaryExpressionImpl> OUR_RESOLVER =
|
||||
new ResolveCache.PolyVariantResolver<GrUnaryExpressionImpl>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GroovyResolveResult[] resolve(GrUnaryExpressionImpl unary, boolean incompleteCode) {
|
||||
public GroovyResolveResult[] resolve(@NotNull GrUnaryExpressionImpl unary, boolean incompleteCode) {
|
||||
final GrExpression operand = unary.getOperand();
|
||||
if (operand == null) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
|
||||
+2
-1
@@ -132,8 +132,9 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp
|
||||
};
|
||||
private static final ResolveCache.PolyVariantResolver<MyReference> RESOLVER =
|
||||
new ResolveCache.PolyVariantResolver<MyReference>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public GroovyResolveResult[] resolve(MyReference index, boolean incompleteCode) {
|
||||
public GroovyResolveResult[] resolve(@NotNull MyReference index, boolean incompleteCode) {
|
||||
return index.getElement().resolveImpl(incompleteCode, null);
|
||||
}
|
||||
};
|
||||
|
||||
+2
-1
@@ -85,8 +85,9 @@ public class GrSafeCastExpressionImpl extends GrExpressionImpl implements GrSafe
|
||||
|
||||
|
||||
private static final class OurResolver implements ResolveCache.PolyVariantResolver<GrSafeCastExpressionImpl> {
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveResult[] resolve(GrSafeCastExpressionImpl cast, boolean incompleteCode) {
|
||||
public ResolveResult[] resolve(@NotNull GrSafeCastExpressionImpl cast, boolean incompleteCode) {
|
||||
PsiType type = cast.getOperand().getType();
|
||||
if (type == null) {
|
||||
return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
+2
-2
@@ -362,8 +362,8 @@ public class GrCodeReferenceElementImpl extends GrReferenceElementImpl<GrCodeRef
|
||||
|
||||
private static class OurResolver implements ResolveCache.PolyVariantResolver<GrCodeReferenceElementImpl> {
|
||||
|
||||
@Nullable
|
||||
public GroovyResolveResult[] resolve(GrCodeReferenceElementImpl reference, boolean incompleteCode) {
|
||||
@NotNull
|
||||
public GroovyResolveResult[] resolve(@NotNull GrCodeReferenceElementImpl reference, boolean incompleteCode) {
|
||||
if (reference.getReferenceName() == null) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
final GroovyResolveResult[] results = _resolve(reference, reference.getManager(), reference.getKind(false));
|
||||
if (results == null) return results;
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class XsltVariableContext implements VariableContext<XsltVariable> {
|
||||
|
||||
private final ResolveCache.Resolver RESOLVER = new ResolveCache.Resolver() {
|
||||
@Nullable
|
||||
public PsiElement resolve(PsiReference psiReference, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference psiReference, boolean incompleteCode) {
|
||||
return resolveInner((XPathVariableReference)psiReference);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ abstract class SimpleAttributeReference implements PsiReference {
|
||||
public final PsiElement resolve() {
|
||||
return ResolveCache.getInstance(myAttribute.getProject()).resolveWithCaching(this, new ResolveCache.Resolver() {
|
||||
@Nullable
|
||||
public PsiElement resolve(PsiReference psiReference, boolean b) {
|
||||
public PsiElement resolve(@NotNull PsiReference psiReference, boolean b) {
|
||||
return resolveImpl();
|
||||
}
|
||||
}, false, false);
|
||||
|
||||
+1
-1
@@ -546,7 +546,7 @@ public class SchemaReferencesProvider extends PsiReferenceProvider {
|
||||
|
||||
private static class MyResolver implements ResolveCache.Resolver {
|
||||
static MyResolver INSTANCE = new MyResolver();
|
||||
public PsiElement resolve(PsiReference ref, boolean incompleteCode) {
|
||||
public PsiElement resolve(@NotNull PsiReference ref, boolean incompleteCode) {
|
||||
return ((TypeOrElementOrAttributeReference)ref).resolveInner();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user