mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull, eliminate moronic null checks
This commit is contained in:
+1
-1
@@ -1080,7 +1080,7 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
|
||||
|
||||
@Override
|
||||
public void visitLiteralExpression(PsiLiteralExpression expression) {
|
||||
final HighlightInfo parsingError = HighlightUtil.checkLiteralExpressionParsingError(expression, null, null);
|
||||
final HighlightInfo parsingError = HighlightUtil.checkLiteralExpressionParsingError(expression, PsiUtil.getLanguageLevel(expression), null);
|
||||
if (parsingError != null) {
|
||||
throwEvaluateException(parsingError.getDescription());
|
||||
return;
|
||||
|
||||
+31
-30
@@ -38,6 +38,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -56,7 +57,7 @@ public class AnnotationsHighlightUtil {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.codeInsight.daemon.impl.analysis.AnnotationsHighlightUtil");
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkNameValuePair(PsiNameValuePair pair) {
|
||||
static HighlightInfo checkNameValuePair(@NotNull PsiNameValuePair pair) {
|
||||
PsiReference ref = pair.getReference();
|
||||
if (ref == null) return null;
|
||||
PsiMethod method = (PsiMethod)ref.resolve();
|
||||
@@ -84,15 +85,17 @@ public class AnnotationsHighlightUtil {
|
||||
PsiType returnType = method.getReturnType();
|
||||
assert returnType != null : method;
|
||||
PsiAnnotationMemberValue value = pair.getValue();
|
||||
HighlightInfo info = checkMemberValueType(value, returnType);
|
||||
if (info != null) return info;
|
||||
if (value != null) {
|
||||
HighlightInfo info = checkMemberValueType(value, returnType);
|
||||
if (info != null) return info;
|
||||
}
|
||||
|
||||
return checkDuplicateAttribute(pair);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkDuplicateAttribute(PsiNameValuePair pair) {
|
||||
private static HighlightInfo checkDuplicateAttribute(@NotNull PsiNameValuePair pair) {
|
||||
PsiAnnotationParameterList annotation = (PsiAnnotationParameterList)pair.getParent();
|
||||
PsiNameValuePair[] attributes = annotation.getAttributes();
|
||||
for (PsiNameValuePair attribute : attributes) {
|
||||
@@ -108,14 +111,8 @@ public class AnnotationsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String formatReference(PsiJavaCodeReferenceElement ref) {
|
||||
return ref.getCanonicalText();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMemberValueType(@Nullable PsiAnnotationMemberValue value, PsiType expectedType) {
|
||||
if (value == null) return null;
|
||||
|
||||
static HighlightInfo checkMemberValueType(@NotNull PsiAnnotationMemberValue value, @NotNull PsiType expectedType) {
|
||||
if (expectedType instanceof PsiClassType && expectedType.equalsToText(CommonClassNames.JAVA_LANG_CLASS)) {
|
||||
if (!(value instanceof PsiClassObjectAccessExpression)) {
|
||||
String description = JavaErrorMessages.message("annotation.non.class.literal.attribute.value");
|
||||
@@ -140,7 +137,8 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
String description = JavaErrorMessages.message("incompatible.types", JavaHighlightUtil.formatType(expectedType), formatReference(nameRef) );
|
||||
String description = JavaErrorMessages.message("incompatible.types", JavaHighlightUtil.formatType(expectedType),
|
||||
nameRef.getCanonicalText());
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
@@ -232,7 +230,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
// returns contained element
|
||||
private static PsiClass contained(PsiClass annotationType) {
|
||||
private static PsiClass contained(@NotNull PsiClass annotationType) {
|
||||
if (!annotationType.isAnnotationType()) return null;
|
||||
PsiMethod[] values = annotationType.findMethodsByName("value", false);
|
||||
if (values.length != 1) return null;
|
||||
@@ -261,7 +259,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMissingAttributes(PsiAnnotation annotation) {
|
||||
static HighlightInfo checkMissingAttributes(@NotNull PsiAnnotation annotation) {
|
||||
PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
|
||||
if (nameRef == null) return null;
|
||||
PsiClass aClass = (PsiClass)nameRef.resolve();
|
||||
@@ -312,7 +310,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkConstantExpression(PsiExpression expression) {
|
||||
static HighlightInfo checkConstantExpression(@NotNull PsiExpression expression) {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (PsiUtil.isAnnotationMethod(parent) || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue) {
|
||||
if (!PsiUtil.isConstantExpression(expression)) {
|
||||
@@ -325,7 +323,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkValidAnnotationType(PsiType type, PsiTypeElement typeElement) {
|
||||
static HighlightInfo checkValidAnnotationType(@Nullable PsiType type, @NotNull PsiTypeElement typeElement) {
|
||||
if (type != null && type.accept(AnnotationReturnTypeVisitor.INSTANCE).booleanValue()) {
|
||||
return null;
|
||||
}
|
||||
@@ -404,14 +402,14 @@ public class AnnotationsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo annotationError(PsiAnnotation annotation, String message) {
|
||||
private static HighlightInfo annotationError(@NotNull PsiAnnotation annotation, @NotNull String message) {
|
||||
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(message).create();
|
||||
QuickFixAction.registerQuickFixAction(info, new DeleteAnnotationAction(annotation));
|
||||
return info;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkReferenceTarget(PsiAnnotation annotation, @Nullable PsiJavaCodeReferenceElement ref) {
|
||||
private static HighlightInfo checkReferenceTarget(@NotNull PsiAnnotation annotation, @Nullable PsiJavaCodeReferenceElement ref) {
|
||||
if (ref == null) return null;
|
||||
PsiElement refTarget = ref.resolve();
|
||||
if (refTarget == null) return null;
|
||||
@@ -433,7 +431,7 @@ public class AnnotationsHighlightUtil {
|
||||
return message != null ? annotationError(annotation, message) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Contract("null->null; !null->!null")
|
||||
private static PsiJavaCodeReferenceElement getOutermostReferenceElement(@Nullable PsiJavaCodeReferenceElement ref) {
|
||||
if (ref == null) return null;
|
||||
|
||||
@@ -445,7 +443,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkAnnotationType(PsiAnnotation annotation) {
|
||||
static HighlightInfo checkAnnotationType(@NotNull PsiAnnotation annotation) {
|
||||
PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
|
||||
if (nameReferenceElement != null) {
|
||||
PsiElement resolved = nameReferenceElement.resolve();
|
||||
@@ -458,7 +456,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkCyclicMemberType(PsiTypeElement typeElement, PsiClass aClass) {
|
||||
static HighlightInfo checkCyclicMemberType(@NotNull PsiTypeElement typeElement, @NotNull PsiClass aClass) {
|
||||
PsiType type = typeElement.getType();
|
||||
Set<PsiClass> checked = new HashSet<>();
|
||||
if (cyclicDependencies(aClass, type, checked, aClass.getManager())) {
|
||||
@@ -468,7 +466,10 @@ public class AnnotationsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean cyclicDependencies(PsiClass aClass, PsiType type, @NotNull Set<PsiClass> checked,@NotNull PsiManager manager) {
|
||||
private static boolean cyclicDependencies(@NotNull PsiClass aClass,
|
||||
@Nullable PsiType type,
|
||||
@NotNull Set<PsiClass> checked,
|
||||
@NotNull PsiManager manager) {
|
||||
final PsiClass resolvedClass = PsiUtil.resolveClassInType(type);
|
||||
if (resolvedClass != null && resolvedClass.isAnnotationType()) {
|
||||
if (aClass == resolvedClass) {
|
||||
@@ -502,7 +503,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkAnnotationDeclaration(final PsiElement parent, final PsiReferenceList list) {
|
||||
static HighlightInfo checkAnnotationDeclaration(@Nullable PsiElement parent, @NotNull PsiReferenceList list) {
|
||||
if (PsiUtil.isAnnotationMethod(parent)) {
|
||||
PsiAnnotationMethod method = (PsiAnnotationMethod)parent;
|
||||
if (list == method.getThrowsList()) {
|
||||
@@ -520,7 +521,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkPackageAnnotationContainingFile(PsiPackageStatement statement, PsiFile file) {
|
||||
static HighlightInfo checkPackageAnnotationContainingFile(@NotNull PsiPackageStatement statement, @NotNull PsiFile file) {
|
||||
PsiModifierList annotationList = statement.getAnnotationList();
|
||||
if (annotationList != null && !PsiPackage.PACKAGE_INFO_FILE.equals(file.getName())) {
|
||||
String message = JavaErrorMessages.message("invalid.package.annotation.containing.file");
|
||||
@@ -530,7 +531,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkTargetAnnotationDuplicates(PsiAnnotation annotation) {
|
||||
static HighlightInfo checkTargetAnnotationDuplicates(@NotNull PsiAnnotation annotation) {
|
||||
PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
|
||||
if (nameRef == null) return null;
|
||||
|
||||
@@ -578,7 +579,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkRepeatableAnnotation(PsiAnnotation annotation) {
|
||||
static HighlightInfo checkRepeatableAnnotation(@NotNull PsiAnnotation annotation) {
|
||||
String qualifiedName = annotation.getQualifiedName();
|
||||
if (!CommonClassNames.JAVA_LANG_ANNOTATION_REPEATABLE.equals(qualifiedName)) return null;
|
||||
|
||||
@@ -645,7 +646,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkReceiverPlacement(PsiReceiverParameter parameter) {
|
||||
static HighlightInfo checkReceiverPlacement(@NotNull PsiReceiverParameter parameter) {
|
||||
PsiElement owner = parameter.getParent().getParent();
|
||||
if (owner == null) return null;
|
||||
|
||||
@@ -670,7 +671,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkReceiverType(PsiReceiverParameter parameter) {
|
||||
static HighlightInfo checkReceiverType(@NotNull PsiReceiverParameter parameter) {
|
||||
PsiElement owner = parameter.getParent().getParent();
|
||||
if (!(owner instanceof PsiMethod)) return null;
|
||||
|
||||
@@ -698,7 +699,7 @@ public class AnnotationsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isStatic(PsiModifierListOwner owner) {
|
||||
private static boolean isStatic(@Nullable PsiModifierListOwner owner) {
|
||||
if (owner == null) return false;
|
||||
if (owner instanceof PsiClass && ClassUtil.isTopLevelClass((PsiClass)owner)) return true;
|
||||
PsiModifierList modifierList = owner.getModifierList();
|
||||
@@ -769,7 +770,7 @@ public class AnnotationsHighlightUtil {
|
||||
private static class DeleteAnnotationAction implements IntentionAction {
|
||||
private final PsiAnnotation myAnnotation;
|
||||
|
||||
private DeleteAnnotationAction(PsiAnnotation annotation) {
|
||||
private DeleteAnnotationAction(@NotNull PsiAnnotation annotation) {
|
||||
myAnnotation = annotation;
|
||||
}
|
||||
|
||||
|
||||
+80
-84
@@ -47,16 +47,10 @@ public class GenericsHighlightUtil {
|
||||
private GenericsHighlightUtil() { }
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkInferredTypeArguments(PsiTypeParameterListOwner listOwner,
|
||||
PsiElement call,
|
||||
PsiSubstitutor substitutor) {
|
||||
return checkInferredTypeArguments(listOwner.getTypeParameters(), call, substitutor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkInferredTypeArguments(PsiTypeParameter[] typeParameters,
|
||||
PsiElement call,
|
||||
PsiSubstitutor substitutor) {
|
||||
static HighlightInfo checkInferredTypeArguments(@NotNull PsiTypeParameterListOwner listOwner,
|
||||
@NotNull PsiElement call,
|
||||
@NotNull PsiSubstitutor substitutor) {
|
||||
PsiTypeParameter[] typeParameters = listOwner.getTypeParameters();
|
||||
final Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor,
|
||||
call, false);
|
||||
if (inferredTypeArgument != null) {
|
||||
@@ -81,9 +75,9 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkParameterizedReferenceTypeArguments(final PsiElement resolved,
|
||||
final PsiJavaCodeReferenceElement referenceElement,
|
||||
final PsiSubstitutor substitutor,
|
||||
static HighlightInfo checkParameterizedReferenceTypeArguments(@Nullable PsiElement resolved,
|
||||
@NotNull PsiJavaCodeReferenceElement referenceElement,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull JavaSdkVersion javaSdkVersion) {
|
||||
if (!(resolved instanceof PsiTypeParameterListOwner)) return null;
|
||||
final PsiTypeParameterListOwner typeParameterListOwner = (PsiTypeParameterListOwner)resolved;
|
||||
@@ -91,9 +85,9 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkReferenceTypeArgumentList(final PsiTypeParameterListOwner typeParameterListOwner,
|
||||
final PsiReferenceParameterList referenceParameterList,
|
||||
final PsiSubstitutor substitutor,
|
||||
static HighlightInfo checkReferenceTypeArgumentList(@NotNull PsiTypeParameterListOwner typeParameterListOwner,
|
||||
@Nullable PsiReferenceParameterList referenceParameterList,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
boolean registerIntentions,
|
||||
@NotNull JavaSdkVersion javaSdkVersion) {
|
||||
PsiDiamondType.DiamondInferenceResult inferenceResult = null;
|
||||
@@ -146,7 +140,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
if (description != null) {
|
||||
final HighlightInfo highlightInfo =
|
||||
HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(referenceParameterList).descriptionAndTooltip(description).create();
|
||||
if (registerIntentions) {
|
||||
if (typeParameterListOwner instanceof PsiClass) {
|
||||
@@ -190,14 +184,14 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean hasSuperMethodsWithTypeParams(PsiMethod method) {
|
||||
private static boolean hasSuperMethodsWithTypeParams(@NotNull PsiMethod method) {
|
||||
for (PsiMethod superMethod : method.findDeepestSuperMethods()) {
|
||||
if (superMethod.hasTypeParameters()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static PsiType detectExpectedType(PsiReferenceParameterList referenceParameterList) {
|
||||
private static PsiType detectExpectedType(@NotNull PsiReferenceParameterList referenceParameterList) {
|
||||
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(referenceParameterList, PsiNewExpression.class);
|
||||
LOG.assertTrue(newExpression != null);
|
||||
final PsiElement parent = newExpression.getParent();
|
||||
@@ -237,11 +231,11 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkTypeParameterWithinItsBound(PsiTypeParameter classParameter,
|
||||
final PsiSubstitutor substitutor,
|
||||
final PsiType type,
|
||||
final PsiElement typeElement2Highlight,
|
||||
PsiReferenceParameterList referenceParameterList) {
|
||||
private static HighlightInfo checkTypeParameterWithinItsBound(@NotNull PsiTypeParameter classParameter,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull PsiType type,
|
||||
@NotNull PsiElement typeElement2Highlight,
|
||||
@Nullable PsiReferenceParameterList referenceParameterList) {
|
||||
final PsiClass referenceClass = type instanceof PsiClassType ? ((PsiClassType)type).resolve() : null;
|
||||
final PsiType psiType = substitutor.substitute(classParameter);
|
||||
if (psiType instanceof PsiClassType && !(PsiUtil.resolveClassInType(psiType) instanceof PsiTypeParameter)) {
|
||||
@@ -278,7 +272,8 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String typeParameterListOwnerDescription(final PsiTypeParameterListOwner typeParameterListOwner) {
|
||||
@NotNull
|
||||
private static String typeParameterListOwnerDescription(@NotNull PsiTypeParameterListOwner typeParameterListOwner) {
|
||||
if (typeParameterListOwner instanceof PsiClass) {
|
||||
return HighlightUtil.formatClass((PsiClass)typeParameterListOwner);
|
||||
}
|
||||
@@ -291,7 +286,8 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static String typeParameterListOwnerCategoryDescription(final PsiTypeParameterListOwner typeParameterListOwner) {
|
||||
@NotNull
|
||||
private static String typeParameterListOwnerCategoryDescription(@NotNull PsiTypeParameterListOwner typeParameterListOwner) {
|
||||
if (typeParameterListOwner instanceof PsiClass) {
|
||||
return JavaErrorMessages.message("generics.holder.type");
|
||||
}
|
||||
@@ -330,23 +326,22 @@ public class GenericsHighlightUtil {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
static HighlightInfo checkInterfaceMultipleInheritance(PsiClass aClass) {
|
||||
static HighlightInfo checkInterfaceMultipleInheritance(@NotNull PsiClass aClass) {
|
||||
final PsiClassType[] types = aClass.getSuperTypes();
|
||||
if (types.length < 2) return null;
|
||||
Map<PsiClass, PsiSubstitutor> inheritedClasses = new HashMap<>();
|
||||
final TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
|
||||
return checkInterfaceMultipleInheritance(aClass,
|
||||
aClass,
|
||||
PsiSubstitutor.EMPTY, inheritedClasses,
|
||||
PsiSubstitutor.EMPTY, new HashMap<>(),
|
||||
new HashSet<>(), textRange);
|
||||
}
|
||||
|
||||
private static HighlightInfo checkInterfaceMultipleInheritance(PsiClass aClass,
|
||||
PsiElement place,
|
||||
PsiSubstitutor derivedSubstitutor,
|
||||
Map<PsiClass, PsiSubstitutor> inheritedClasses,
|
||||
Set<PsiClass> visited,
|
||||
TextRange textRange) {
|
||||
private static HighlightInfo checkInterfaceMultipleInheritance(@NotNull PsiClass aClass,
|
||||
@NotNull PsiElement place,
|
||||
@NotNull PsiSubstitutor derivedSubstitutor,
|
||||
@NotNull Map<PsiClass, PsiSubstitutor> inheritedClasses,
|
||||
@NotNull Set<PsiClass> visited,
|
||||
@NotNull TextRange textRange) {
|
||||
final List<PsiClassType.ClassResolveResult> superTypes = PsiClassImplUtil.getScopeCorrectedSuperTypes(aClass, place.getResolveScope());
|
||||
for (PsiClassType.ClassResolveResult result : superTypes) {
|
||||
final PsiClass superClass = result.getElement();
|
||||
@@ -382,6 +377,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static Collection<HighlightInfo> checkOverrideEquivalentMethods(@NotNull PsiClass aClass) {
|
||||
List<HighlightInfo> result = new ArrayList<>();
|
||||
final Collection<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
|
||||
@@ -403,7 +399,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
return result.isEmpty() ? null : result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(@NotNull LanguageLevel languageLevel,
|
||||
@@ -510,11 +506,11 @@ public class GenericsHighlightUtil {
|
||||
unrelatedMethodContainingClass.isInheritor(defaultMethodContainingClass, true);
|
||||
}
|
||||
|
||||
private static boolean hasNotOverriddenAbstract(List<PsiClass> defaultContainingClasses, @NotNull PsiClass abstractMethodContainingClass) {
|
||||
private static boolean hasNotOverriddenAbstract(@NotNull List<PsiClass> defaultContainingClasses, @NotNull PsiClass abstractMethodContainingClass) {
|
||||
return defaultContainingClasses.stream().noneMatch(containingClass -> belongToOneHierarchy(containingClass, abstractMethodContainingClass));
|
||||
}
|
||||
|
||||
private static String hasUnrelatedDefaults(List<PsiClass> defaults) {
|
||||
private static String hasUnrelatedDefaults(@NotNull List<PsiClass> defaults) {
|
||||
if (defaults.size() > 1) {
|
||||
PsiClass[] defaultClasses = defaults.toArray(PsiClass.EMPTY_ARRAY);
|
||||
ArrayList<PsiClass> classes = new ArrayList<>(defaults);
|
||||
@@ -619,10 +615,10 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkSameErasureNotSubSignatureOrSameClass(final MethodSignatureBackedByPsiMethod signatureToCheck,
|
||||
final HierarchicalMethodSignature superSignature,
|
||||
final PsiClass aClass,
|
||||
final PsiMethod superMethod) {
|
||||
private static HighlightInfo checkSameErasureNotSubSignatureOrSameClass(@NotNull MethodSignatureBackedByPsiMethod signatureToCheck,
|
||||
@NotNull HierarchicalMethodSignature superSignature,
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull PsiMethod superMethod) {
|
||||
final PsiMethod checkMethod = signatureToCheck.getMethod();
|
||||
if (superMethod.equals(checkMethod)) return null;
|
||||
PsiClass checkContainingClass = checkMethod.getContainingClass();
|
||||
@@ -691,7 +687,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
private static HighlightInfo getSameErasureMessage(final boolean sameClass, @NotNull PsiMethod method, @NotNull PsiMethod superMethod,
|
||||
TextRange textRange) {
|
||||
@NotNull TextRange textRange) {
|
||||
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ?
|
||||
"generics.methods.have.same.erasure.hide" :
|
||||
@@ -700,7 +696,7 @@ public class GenericsHighlightUtil {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
static HighlightInfo checkTypeParameterInstantiation(PsiNewExpression expression) {
|
||||
static HighlightInfo checkTypeParameterInstantiation(@NotNull PsiNewExpression expression) {
|
||||
PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
if (classReference == null) return null;
|
||||
final JavaResolveResult result = classReference.advancedResolve(false);
|
||||
@@ -713,7 +709,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkWildcardUsage(PsiTypeElement typeElement) {
|
||||
static HighlightInfo checkWildcardUsage(@NotNull PsiTypeElement typeElement) {
|
||||
PsiType type = typeElement.getType();
|
||||
if (type instanceof PsiWildcardType) {
|
||||
if (typeElement.getParent() instanceof PsiReferenceParameterList) {
|
||||
@@ -745,7 +741,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkReferenceTypeUsedAsTypeArgument(PsiTypeElement typeElement, LanguageLevel level) {
|
||||
static HighlightInfo checkReferenceTypeUsedAsTypeArgument(@NotNull PsiTypeElement typeElement, @NotNull LanguageLevel level) {
|
||||
final PsiType type = typeElement.getType();
|
||||
if (type != PsiType.NULL && type instanceof PsiPrimitiveType ||
|
||||
type instanceof PsiWildcardType && ((PsiWildcardType)type).getBound() instanceof PsiPrimitiveType) {
|
||||
@@ -777,8 +773,8 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkForeachExpressionTypeIsIterable(PsiExpression expression) {
|
||||
if (expression == null || expression.getType() == null) return null;
|
||||
static HighlightInfo checkForeachExpressionTypeIsIterable(@NotNull PsiExpression expression) {
|
||||
if (expression.getType() == null) return null;
|
||||
final PsiType itemType = JavaGenericsUtil.getCollectionItemType(expression);
|
||||
if (itemType == null) {
|
||||
String description = JavaErrorMessages.message("foreach.not.applicable",
|
||||
@@ -840,7 +836,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkEnumInstantiation(PsiElement expression, PsiClass aClass) {
|
||||
static HighlightInfo checkEnumInstantiation(@NotNull PsiElement expression, @Nullable PsiClass aClass) {
|
||||
if (aClass != null && aClass.isEnum() &&
|
||||
(!(expression instanceof PsiNewExpression) ||
|
||||
((PsiNewExpression)expression).getArrayDimensions().length == 0 && ((PsiNewExpression)expression).getArrayInitializer() == null)) {
|
||||
@@ -851,7 +847,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkGenericArrayCreation(PsiElement element, PsiType type) {
|
||||
static HighlightInfo checkGenericArrayCreation(@NotNull PsiElement element, @Nullable PsiType type) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
if (!JavaGenericsUtil.isReifiableType(((PsiArrayType)type).getComponentType())) {
|
||||
String description = JavaErrorMessages.message("generic.array.creation");
|
||||
@@ -867,7 +863,7 @@ public class GenericsHighlightUtil {
|
||||
PsiTypeParameter.EMPTY_ARRAY,
|
||||
PsiSubstitutor.EMPTY);
|
||||
|
||||
static boolean isEnumSyntheticMethod(MethodSignature methodSignature, Project project) {
|
||||
static boolean isEnumSyntheticMethod(@NotNull MethodSignature methodSignature, @NotNull Project project) {
|
||||
if (methodSignature.equals(ourValuesEnumSyntheticMethod)) return true;
|
||||
final PsiType javaLangString = PsiType.getJavaLangString(PsiManager.getInstance(project), GlobalSearchScope.allScope(project));
|
||||
final MethodSignature valueOfMethod = MethodSignatureUtil.createMethodSignature("valueOf", new PsiType[]{javaLangString}, PsiTypeParameter.EMPTY_ARRAY,
|
||||
@@ -876,7 +872,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkTypeParametersList(PsiTypeParameterList list, PsiTypeParameter[] parameters, @NotNull LanguageLevel level) {
|
||||
static HighlightInfo checkTypeParametersList(@NotNull PsiTypeParameterList list, @NotNull PsiTypeParameter[] parameters, @NotNull LanguageLevel level) {
|
||||
final PsiElement parent = list.getParent();
|
||||
if (parent instanceof PsiClass && ((PsiClass)parent).isEnum()) {
|
||||
String description = JavaErrorMessages.message("generics.enum.may.not.have.type.parameters");
|
||||
@@ -917,7 +913,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Collection<HighlightInfo> checkCatchParameterIsClass(PsiParameter parameter) {
|
||||
static Collection<HighlightInfo> checkCatchParameterIsClass(@NotNull PsiParameter parameter) {
|
||||
if (!(parameter.getDeclarationScope() instanceof PsiCatchSection)) return null;
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
|
||||
@@ -933,7 +929,7 @@ public class GenericsHighlightUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
static HighlightInfo checkInstanceOfGenericType(PsiInstanceOfExpression expression) {
|
||||
static HighlightInfo checkInstanceOfGenericType(@NotNull PsiInstanceOfExpression expression) {
|
||||
final PsiTypeElement checkTypeElement = expression.getCheckType();
|
||||
if (checkTypeElement == null) return null;
|
||||
return isIllegalForInstanceOf(checkTypeElement.getType(), checkTypeElement);
|
||||
@@ -943,7 +939,7 @@ public class GenericsHighlightUtil {
|
||||
* 15.20.2 Type Comparison Operator instanceof
|
||||
* ReferenceType mentioned after the instanceof operator is reifiable
|
||||
*/
|
||||
private static HighlightInfo isIllegalForInstanceOf(PsiType type, final PsiTypeElement typeElement) {
|
||||
private static HighlightInfo isIllegalForInstanceOf(@Nullable PsiType type, @NotNull PsiTypeElement typeElement) {
|
||||
final PsiClass resolved = PsiUtil.resolveClassInClassTypeOnly(type);
|
||||
if (resolved instanceof PsiTypeParameter) {
|
||||
String description = JavaErrorMessages.message("generics.cannot.instanceof.type.parameters");
|
||||
@@ -958,7 +954,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkClassObjectAccessExpression(PsiClassObjectAccessExpression expression) {
|
||||
static HighlightInfo checkClassObjectAccessExpression(@NotNull PsiClassObjectAccessExpression expression) {
|
||||
PsiType type = expression.getOperand().getType();
|
||||
if (type instanceof PsiClassType) {
|
||||
return canSelectFrom((PsiClassType)type, expression.getOperand());
|
||||
@@ -974,7 +970,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo canSelectFrom(PsiClassType type, PsiTypeElement operand) {
|
||||
private static HighlightInfo canSelectFrom(@NotNull PsiClassType type, @NotNull PsiTypeElement operand) {
|
||||
PsiClass aClass = type.resolve();
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
String description = JavaErrorMessages.message("cannot.select.dot.class.from.type.variable");
|
||||
@@ -1027,7 +1023,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkSafeVarargsAnnotation(PsiMethod method, LanguageLevel languageLevel) {
|
||||
static HighlightInfo checkSafeVarargsAnnotation(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
|
||||
PsiModifierList list = method.getModifierList();
|
||||
final PsiAnnotation safeVarargsAnnotation = list.findAnnotation(CommonClassNames.JAVA_LANG_SAFE_VARARGS);
|
||||
if (safeVarargsAnnotation == null) {
|
||||
@@ -1071,7 +1067,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSafeVarargsNoOverridingCondition(PsiMethod method, LanguageLevel languageLevel) {
|
||||
public static boolean isSafeVarargsNoOverridingCondition(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
|
||||
return method.hasModifierProperty(PsiModifier.FINAL) ||
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
method.isConstructor() ||
|
||||
@@ -1102,7 +1098,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkEnumSuperConstructorCall(PsiMethodCallExpression expr) {
|
||||
static HighlightInfo checkEnumSuperConstructorCall(@NotNull PsiMethodCallExpression expr) {
|
||||
PsiReferenceExpression methodExpression = expr.getMethodExpression();
|
||||
final PsiElement refNameElement = methodExpression.getReferenceNameElement();
|
||||
if (refNameElement != null && PsiKeyword.SUPER.equals(refNameElement.getText())) {
|
||||
@@ -1134,7 +1130,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static List<HighlightInfo> checkEnumConstantModifierList(PsiModifierList modifierList) {
|
||||
static List<HighlightInfo> checkEnumConstantModifierList(@NotNull PsiModifierList modifierList) {
|
||||
List<HighlightInfo> list = null;
|
||||
PsiElement[] children = modifierList.getChildren();
|
||||
for (PsiElement child : children) {
|
||||
@@ -1150,7 +1146,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkParametersAllowed(PsiReferenceParameterList refParamList) {
|
||||
static HighlightInfo checkParametersAllowed(@NotNull PsiReferenceParameterList refParamList) {
|
||||
final PsiElement parent = refParamList.getParent();
|
||||
if (parent instanceof PsiReferenceExpression) {
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
@@ -1164,7 +1160,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkParametersOnRaw(PsiReferenceParameterList refParamList) {
|
||||
static HighlightInfo checkParametersOnRaw(@NotNull PsiReferenceParameterList refParamList) {
|
||||
JavaResolveResult resolveResult = null;
|
||||
PsiElement parent = refParamList.getParent();
|
||||
PsiElement qualifier = null;
|
||||
@@ -1223,7 +1219,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkCannotInheritFromEnum(PsiClass superClass, PsiElement elementToHighlight) {
|
||||
static HighlightInfo checkCannotInheritFromEnum(@NotNull PsiClass superClass, @NotNull PsiElement elementToHighlight) {
|
||||
HighlightInfo errorResult = null;
|
||||
if (Comparing.strEqual("java.lang.Enum", superClass.getQualifiedName())) {
|
||||
String message = JavaErrorMessages.message("classes.extends.enum");
|
||||
@@ -1233,7 +1229,7 @@ public class GenericsHighlightUtil {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
static HighlightInfo checkGenericCannotExtendException(PsiReferenceList list) {
|
||||
static HighlightInfo checkGenericCannotExtendException(@NotNull PsiReferenceList list) {
|
||||
PsiElement parent = list.getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
PsiClass klass = (PsiClass)parent;
|
||||
@@ -1272,7 +1268,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkGenericCannotExtendException(PsiAnonymousClass anonymousClass) {
|
||||
static HighlightInfo checkGenericCannotExtendException(@NotNull PsiAnonymousClass anonymousClass) {
|
||||
if (hasGenericSignature(anonymousClass) &&
|
||||
InheritanceUtil.isInheritor(anonymousClass, true, CommonClassNames.JAVA_LANG_THROWABLE)) {
|
||||
String message = JavaErrorMessages.message("generic.extend.exception");
|
||||
@@ -1281,7 +1277,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean hasGenericSignature(PsiClass klass) {
|
||||
private static boolean hasGenericSignature(@NotNull PsiClass klass) {
|
||||
PsiClass containingClass = klass;
|
||||
while (containingClass != null && PsiUtil.isLocalOrAnonymousClass(containingClass)) {
|
||||
if (containingClass.hasTypeParameters()) return true;
|
||||
@@ -1290,7 +1286,7 @@ public class GenericsHighlightUtil {
|
||||
return containingClass != null && PsiUtil.typeParametersIterator(containingClass).hasNext();
|
||||
}
|
||||
|
||||
static HighlightInfo checkEnumMustNotBeLocal(final PsiClass aClass) {
|
||||
static HighlightInfo checkEnumMustNotBeLocal(@NotNull PsiClass aClass) {
|
||||
if (!aClass.isEnum()) return null;
|
||||
PsiElement parent = aClass.getParent();
|
||||
if (!(parent instanceof PsiClass || parent instanceof PsiFile || parent instanceof PsiClassLevelDeclarationStatement)) {
|
||||
@@ -1301,7 +1297,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkSelectStaticClassFromParameterizedType(final PsiElement resolved, final PsiJavaCodeReferenceElement ref) {
|
||||
static HighlightInfo checkSelectStaticClassFromParameterizedType(@Nullable PsiElement resolved, @NotNull PsiJavaCodeReferenceElement ref) {
|
||||
if (resolved instanceof PsiClass && ((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiElement qualifier = ref.getQualifier();
|
||||
if (qualifier instanceof PsiJavaCodeReferenceElement) {
|
||||
@@ -1316,7 +1312,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkCannotInheritFromTypeParameter(final PsiClass superClass, final PsiJavaCodeReferenceElement toHighlight) {
|
||||
static HighlightInfo checkCannotInheritFromTypeParameter(@Nullable PsiClass superClass, @NotNull PsiJavaCodeReferenceElement toHighlight) {
|
||||
if (superClass instanceof PsiTypeParameter) {
|
||||
String description = JavaErrorMessages.message("class.cannot.inherit.from.its.type.parameter");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(toHighlight).descriptionAndTooltip(description).create();
|
||||
@@ -1327,7 +1323,7 @@ public class GenericsHighlightUtil {
|
||||
/**
|
||||
* http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.8
|
||||
*/
|
||||
static HighlightInfo checkRawOnParameterizedType(@NotNull PsiJavaCodeReferenceElement parent, PsiElement resolved) {
|
||||
static HighlightInfo checkRawOnParameterizedType(@NotNull PsiJavaCodeReferenceElement parent, @Nullable PsiElement resolved) {
|
||||
PsiReferenceParameterList list = parent.getParameterList();
|
||||
if (list == null || list.getTypeArguments().length > 0) return null;
|
||||
final PsiElement qualifier = parent.getQualifier();
|
||||
@@ -1342,7 +1338,7 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkCannotPassInner(PsiJavaCodeReferenceElement ref) {
|
||||
static HighlightInfo checkCannotPassInner(@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
if (ref.getParent() instanceof PsiTypeElement) {
|
||||
final PsiClass psiClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
|
||||
if (psiClass == null) return null;
|
||||
@@ -1376,8 +1372,8 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiClass unqualifiedNestedClassReferenceAccessedViaContainingClassInheritance(PsiClass containingClass,
|
||||
PsiReferenceList referenceList) {
|
||||
private static PsiClass unqualifiedNestedClassReferenceAccessedViaContainingClassInheritance(@NotNull PsiClass containingClass,
|
||||
@Nullable PsiReferenceList referenceList) {
|
||||
if (referenceList != null) {
|
||||
for (PsiJavaCodeReferenceElement referenceElement : referenceList.getReferenceElements()) {
|
||||
if (!referenceElement.isQualified()) {
|
||||
@@ -1428,7 +1424,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static HighlightInfo checkInferredIntersections(PsiSubstitutor substitutor, TextRange ref) {
|
||||
static HighlightInfo checkInferredIntersections(@NotNull PsiSubstitutor substitutor, @NotNull TextRange ref) {
|
||||
for (Map.Entry<PsiTypeParameter, PsiType> typeEntry : substitutor.getSubstitutionMap().entrySet()) {
|
||||
final String parameterName = typeEntry.getKey().getName();
|
||||
final PsiType type = typeEntry.getValue();
|
||||
@@ -1455,9 +1451,9 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkClassSupersAccessibility(PsiClass aClass,
|
||||
GlobalSearchScope resolveScope,
|
||||
TextRange range,
|
||||
private static HighlightInfo checkClassSupersAccessibility(@NotNull PsiClass aClass,
|
||||
@NotNull GlobalSearchScope resolveScope,
|
||||
@NotNull TextRange range,
|
||||
boolean checkParameters) {
|
||||
final JavaPsiFacade factory = JavaPsiFacade.getInstance(aClass.getProject());
|
||||
for (PsiClassType superType : aClass.getSuperTypes()) {
|
||||
@@ -1516,11 +1512,11 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String isTypeAccessible(PsiType type,
|
||||
Set<PsiClass> classes,
|
||||
private static String isTypeAccessible(@Nullable PsiType type,
|
||||
@NotNull Set<PsiClass> classes,
|
||||
boolean checkParameters,
|
||||
GlobalSearchScope resolveScope,
|
||||
JavaPsiFacade factory) {
|
||||
@NotNull GlobalSearchScope resolveScope,
|
||||
@NotNull JavaPsiFacade factory) {
|
||||
final PsiClass aClass = PsiUtil.resolveClassInType(type);
|
||||
if (aClass != null && classes.add(aClass)) {
|
||||
VirtualFile vFile = PsiUtilCore.getVirtualFile(aClass);
|
||||
@@ -1561,13 +1557,13 @@ public class GenericsHighlightUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkTypeParameterOverrideEquivalentMethods(PsiClass aClass, LanguageLevel level) {
|
||||
static HighlightInfo checkTypeParameterOverrideEquivalentMethods(@NotNull PsiClass aClass, @NotNull LanguageLevel level) {
|
||||
if (aClass instanceof PsiTypeParameter && level.isAtLeast(LanguageLevel.JDK_1_7)) {
|
||||
final PsiReferenceList extendsList = aClass.getExtendsList();
|
||||
if (extendsList != null && extendsList.getReferenceElements().length > 1) {
|
||||
//todo suppress erased methods which come from the same class
|
||||
final Collection<HighlightInfo> result = checkOverrideEquivalentMethods(aClass);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
if (!result.isEmpty()) {
|
||||
return result.iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
+51
-54
@@ -68,12 +68,12 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkClassWithAbstractMethods(PsiClass aClass, TextRange range) {
|
||||
private static HighlightInfo checkClassWithAbstractMethods(@NotNull PsiClass aClass, @NotNull TextRange range) {
|
||||
return checkClassWithAbstractMethods(aClass, aClass, range);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassWithAbstractMethods(PsiClass aClass, PsiElement implementsFixElement, TextRange range) {
|
||||
static HighlightInfo checkClassWithAbstractMethods(@NotNull PsiClass aClass, @NotNull PsiElement implementsFixElement, @NotNull TextRange range) {
|
||||
PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(aClass);
|
||||
|
||||
if (abstractMethod == null) {
|
||||
@@ -112,7 +112,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassMustBeAbstract(final PsiClass aClass, final TextRange textRange) {
|
||||
static HighlightInfo checkClassMustBeAbstract(@NotNull PsiClass aClass, @NotNull TextRange textRange) {
|
||||
if (aClass.isEnum()) {
|
||||
if (hasEnumConstantsWithInitializer(aClass)) return null;
|
||||
}
|
||||
@@ -123,10 +123,10 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkInstantiationOfAbstractClass(PsiClass aClass, @NotNull PsiElement highlightElement) {
|
||||
static HighlightInfo checkInstantiationOfAbstractClass(@NotNull PsiClass aClass, @NotNull PsiElement highlightElement) {
|
||||
HighlightInfo errorResult = null;
|
||||
if (aClass != null && aClass.hasModifierProperty(PsiModifier.ABSTRACT)
|
||||
&& (!(highlightElement instanceof PsiNewExpression) || !(((PsiNewExpression)highlightElement).getType() instanceof PsiArrayType))) {
|
||||
if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) &&
|
||||
(!(highlightElement instanceof PsiNewExpression) || !(((PsiNewExpression)highlightElement).getType() instanceof PsiArrayType))) {
|
||||
String baseClassName = aClass.getName();
|
||||
String message = JavaErrorMessages.message("abstract.cannot.be.instantiated", baseClassName);
|
||||
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(highlightElement).descriptionAndTooltip(message).create();
|
||||
@@ -143,7 +143,7 @@ public class HighlightClassUtil {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
public static boolean hasEnumConstantsWithInitializer(@NotNull PsiClass aClass) {
|
||||
static boolean hasEnumConstantsWithInitializer(@NotNull PsiClass aClass) {
|
||||
return CachedValuesManager.getCachedValue(aClass, () -> {
|
||||
PsiField[] fields = aClass.getFields();
|
||||
for (PsiField field : fields) {
|
||||
@@ -157,7 +157,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkDuplicateTopLevelClass(PsiClass aClass) {
|
||||
static HighlightInfo checkDuplicateTopLevelClass(@NotNull PsiClass aClass) {
|
||||
if (!(aClass.getParent() instanceof PsiFile)) return null;
|
||||
String qualifiedName = aClass.getQualifiedName();
|
||||
if (qualifiedName == null) return null;
|
||||
@@ -195,8 +195,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkDuplicateNestedClass(PsiClass aClass) {
|
||||
if (aClass == null) return null;
|
||||
static HighlightInfo checkDuplicateNestedClass(@NotNull PsiClass aClass) {
|
||||
PsiElement parent = aClass;
|
||||
if (aClass.getParent() instanceof PsiDeclarationStatement) {
|
||||
parent = aClass.getParent();
|
||||
@@ -239,7 +238,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkPublicClassInRightFile(PsiClass aClass) {
|
||||
static HighlightInfo checkPublicClassInRightFile(@NotNull PsiClass aClass) {
|
||||
PsiFile containingFile = aClass.getContainingFile();
|
||||
if (aClass.getParent() != containingFile || !aClass.hasModifierProperty(PsiModifier.PUBLIC) || !(containingFile instanceof PsiJavaFile)) return null;
|
||||
PsiJavaFile file = (PsiJavaFile)containingFile;
|
||||
@@ -271,9 +270,9 @@ public class HighlightClassUtil {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
static HighlightInfo checkVarClassConflict(PsiClass psiClass, PsiIdentifier identifier) {
|
||||
static HighlightInfo checkVarClassConflict(@NotNull PsiClass psiClass, @NotNull PsiIdentifier identifier) {
|
||||
String className = psiClass.getName();
|
||||
if (className != null && PsiKeyword.VAR.equals(className)) {
|
||||
if (PsiKeyword.VAR.equals(className)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.descriptionAndTooltip("'var' is a restricted local variable type and cannot be used for type declarations")
|
||||
.range(identifier)
|
||||
@@ -324,19 +323,19 @@ public class HighlightClassUtil {
|
||||
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(keyword).descriptionAndTooltip(message).create();
|
||||
|
||||
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createModifierListFix(field, PsiModifier.STATIC, false, false));
|
||||
registerMakeInnerClassStatic(result, field.getContainingClass());
|
||||
registerMakeInnerClassStatic(field.getContainingClass(), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void registerMakeInnerClassStatic(HighlightInfo result, PsiClass aClass) {
|
||||
private static void registerMakeInnerClassStatic(@Nullable PsiClass aClass, @Nullable HighlightInfo result) {
|
||||
if (aClass != null && aClass.getContainingClass() != null) {
|
||||
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.STATIC, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkStaticMethodDeclarationInInnerClass(PsiKeyword keyword) {
|
||||
private static HighlightInfo checkStaticMethodDeclarationInInnerClass(@NotNull PsiKeyword keyword) {
|
||||
if (getEnclosingStaticClass(keyword, PsiMethod.class) == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -345,12 +344,12 @@ public class HighlightClassUtil {
|
||||
String message = JavaErrorMessages.message("static.declaration.in.inner.class");
|
||||
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(keyword).descriptionAndTooltip(message).create();
|
||||
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, false, false));
|
||||
registerMakeInnerClassStatic(result, (PsiClass)keyword.getParent().getParent().getParent());
|
||||
registerMakeInnerClassStatic((PsiClass)keyword.getParent().getParent().getParent(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkStaticInitializerDeclarationInInnerClass(PsiKeyword keyword) {
|
||||
private static HighlightInfo checkStaticInitializerDeclarationInInnerClass(@NotNull PsiKeyword keyword) {
|
||||
if (getEnclosingStaticClass(keyword, PsiClassInitializer.class) == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -359,7 +358,7 @@ public class HighlightClassUtil {
|
||||
String message = JavaErrorMessages.message("static.declaration.in.inner.class");
|
||||
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(keyword).descriptionAndTooltip(message).create();
|
||||
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createModifierListFix(initializer, PsiModifier.STATIC, false, false));
|
||||
registerMakeInnerClassStatic(result, (PsiClass)keyword.getParent().getParent().getParent());
|
||||
registerMakeInnerClassStatic((PsiClass)keyword.getParent().getParent().getParent(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -375,7 +374,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkStaticClassDeclarationInInnerClass(PsiKeyword keyword) {
|
||||
private static HighlightInfo checkStaticClassDeclarationInInnerClass(@NotNull PsiKeyword keyword) {
|
||||
// keyword points to 'class' or 'interface' or 'enum'
|
||||
if (new PsiMatcherImpl(keyword)
|
||||
.parent(PsiMatchers.hasClass(PsiClass.class))
|
||||
@@ -410,12 +409,12 @@ public class HighlightClassUtil {
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.STATIC, false, false));
|
||||
}
|
||||
PsiClass containingClass = aClass.getContainingClass();
|
||||
registerMakeInnerClassStatic(info, containingClass);
|
||||
registerMakeInnerClassStatic(containingClass, info);
|
||||
return info;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkStaticDeclarationInInnerClass(PsiKeyword keyword) {
|
||||
static HighlightInfo checkStaticDeclarationInInnerClass(@NotNull PsiKeyword keyword) {
|
||||
HighlightInfo errorResult = checkStaticFieldDeclarationInInnerClass(keyword);
|
||||
if (errorResult != null) return errorResult;
|
||||
errorResult = checkStaticMethodDeclarationInInnerClass(keyword);
|
||||
@@ -428,7 +427,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkExtendsAllowed(PsiReferenceList list) {
|
||||
static HighlightInfo checkExtendsAllowed(@NotNull PsiReferenceList list) {
|
||||
if (list.getParent() instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)list.getParent();
|
||||
if (aClass.isEnum()) {
|
||||
@@ -443,7 +442,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkImplementsAllowed(PsiReferenceList list) {
|
||||
static HighlightInfo checkImplementsAllowed(@NotNull PsiReferenceList list) {
|
||||
if (list.getParent() instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)list.getParent();
|
||||
if (aClass.isInterface()) {
|
||||
@@ -464,9 +463,9 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkExtendsClassAndImplementsInterface(PsiReferenceList referenceList,
|
||||
JavaResolveResult resolveResult,
|
||||
PsiJavaCodeReferenceElement ref) {
|
||||
static HighlightInfo checkExtendsClassAndImplementsInterface(@NotNull PsiReferenceList referenceList,
|
||||
@NotNull JavaResolveResult resolveResult,
|
||||
@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
PsiClass aClass = (PsiClass)referenceList.getParent();
|
||||
boolean isImplements = referenceList.equals(aClass.getImplementsList());
|
||||
boolean isInterface = aClass.isInterface();
|
||||
@@ -485,7 +484,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkCannotInheritFromFinal(PsiClass superClass, PsiElement elementToHighlight) {
|
||||
static HighlightInfo checkCannotInheritFromFinal(@NotNull PsiClass superClass, @NotNull PsiElement elementToHighlight) {
|
||||
HighlightInfo errorResult = null;
|
||||
if (superClass.hasModifierProperty(PsiModifier.FINAL) || superClass.isEnum()) {
|
||||
String message = JavaErrorMessages.message("inheritance.from.final.class", superClass.getQualifiedName(), superClass.isEnum() ? PsiKeyword.ENUM : PsiKeyword.FINAL);
|
||||
@@ -498,7 +497,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkAnonymousInheritFinal(PsiNewExpression expression) {
|
||||
static HighlightInfo checkAnonymousInheritFinal(@NotNull PsiNewExpression expression) {
|
||||
PsiAnonymousClass aClass = PsiTreeUtil.getChildOfType(expression, PsiAnonymousClass.class);
|
||||
if (aClass == null) return null;
|
||||
PsiClassType baseClassReference = aClass.getBaseClassType();
|
||||
@@ -508,7 +507,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String checkDefaultConstructorThrowsException(PsiMethod constructor, @NotNull PsiClassType[] handledExceptions) {
|
||||
private static String checkDefaultConstructorThrowsException(@NotNull PsiMethod constructor, @NotNull PsiClassType[] handledExceptions) {
|
||||
PsiClassType[] referencedTypes = constructor.getThrowsList().getReferencedTypes();
|
||||
List<PsiClassType> exceptions = new ArrayList<>();
|
||||
for (PsiClassType referencedType : referencedTypes) {
|
||||
@@ -524,7 +523,7 @@ public class HighlightClassUtil {
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassDoesNotCallSuperConstructorOrHandleExceptions(@NotNull PsiClass aClass,
|
||||
RefCountHolder refCountHolder,
|
||||
@NotNull RefCountHolder refCountHolder,
|
||||
@NotNull PsiResolveHelper resolveHelper) {
|
||||
if (aClass.isEnum()) return null;
|
||||
// check only no-ctr classes. Problem with specific constructor will be highlighted inside it
|
||||
@@ -535,7 +534,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
static HighlightInfo checkBaseClassDefaultConstructorProblem(@NotNull PsiClass aClass,
|
||||
RefCountHolder refCountHolder,
|
||||
@NotNull RefCountHolder refCountHolder,
|
||||
@NotNull PsiResolveHelper resolveHelper,
|
||||
@NotNull TextRange range,
|
||||
@NotNull PsiClassType[] handledExceptions) {
|
||||
@@ -581,9 +580,7 @@ public class HighlightClassUtil {
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createCreateConstructorMatchingSuperFix(aClass));
|
||||
return info;
|
||||
}
|
||||
if (refCountHolder != null) {
|
||||
refCountHolder.registerLocallyReferenced(constructor);
|
||||
}
|
||||
refCountHolder.registerLocallyReferenced(constructor);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -596,7 +593,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkInterfaceCannotBeLocal(PsiClass aClass) {
|
||||
static HighlightInfo checkInterfaceCannotBeLocal(@NotNull PsiClass aClass) {
|
||||
if (PsiUtil.isLocalClass(aClass)) {
|
||||
TextRange range = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
|
||||
String description = JavaErrorMessages.message("interface.cannot.be.local");
|
||||
@@ -606,7 +603,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkCyclicInheritance(PsiClass aClass) {
|
||||
static HighlightInfo checkCyclicInheritance(@NotNull PsiClass aClass) {
|
||||
PsiClass circularClass = getCircularClass(aClass, new HashSet<>());
|
||||
if (circularClass != null) {
|
||||
String description = JavaErrorMessages.message("cyclic.inheritance", HighlightUtil.formatClass(circularClass));
|
||||
@@ -617,7 +614,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiClass getCircularClass(PsiClass aClass, Collection<PsiClass> usedClasses) {
|
||||
public static PsiClass getCircularClass(@NotNull PsiClass aClass, @NotNull Collection<PsiClass> usedClasses) {
|
||||
if (usedClasses.contains(aClass)) {
|
||||
return aClass;
|
||||
}
|
||||
@@ -642,7 +639,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkExtendsDuplicate(PsiJavaCodeReferenceElement element, PsiElement resolved, @NotNull PsiFile containingFile) {
|
||||
static HighlightInfo checkExtendsDuplicate(@NotNull PsiJavaCodeReferenceElement element, @Nullable PsiElement resolved, @NotNull PsiFile containingFile) {
|
||||
if (!(element.getParent() instanceof PsiReferenceList)) return null;
|
||||
PsiReferenceList list = (PsiReferenceList)element.getParent();
|
||||
if (!(list.getParent() instanceof PsiClass)) return null;
|
||||
@@ -665,7 +662,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassAlreadyImported(PsiClass aClass, PsiElement elementToHighlight) {
|
||||
static HighlightInfo checkClassAlreadyImported(@NotNull PsiClass aClass, @NotNull PsiElement elementToHighlight) {
|
||||
PsiFile file = aClass.getContainingFile();
|
||||
if (!(file instanceof PsiJavaFile)) return null;
|
||||
PsiJavaFile javaFile = (PsiJavaFile)file;
|
||||
@@ -686,7 +683,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassExtendsOnlyOneClass(PsiReferenceList list) {
|
||||
static HighlightInfo checkClassExtendsOnlyOneClass(@NotNull PsiReferenceList list) {
|
||||
PsiClassType[] referencedTypes = list.getReferencedTypes();
|
||||
PsiElement parent = list.getParent();
|
||||
if (!(parent instanceof PsiClass)) return null;
|
||||
@@ -703,14 +700,14 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkThingNotAllowedInInterface(PsiElement element, PsiClass aClass) {
|
||||
static HighlightInfo checkThingNotAllowedInInterface(@NotNull PsiElement element, @Nullable PsiClass aClass) {
|
||||
if (aClass == null || !aClass.isInterface()) return null;
|
||||
String description = JavaErrorMessages.message("not.allowed.in.interface");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkQualifiedNew(PsiNewExpression expression, PsiType type, PsiClass aClass) {
|
||||
static HighlightInfo checkQualifiedNew(@NotNull PsiNewExpression expression, @Nullable PsiType type, @Nullable PsiClass aClass) {
|
||||
PsiExpression qualifier = expression.getQualifier();
|
||||
if (qualifier == null) return null;
|
||||
if (type instanceof PsiArrayType) {
|
||||
@@ -749,7 +746,7 @@ public class HighlightClassUtil {
|
||||
* @param resolved extendRef resolved
|
||||
*/
|
||||
@Nullable
|
||||
static HighlightInfo checkClassExtendsForeignInnerClass(final PsiJavaCodeReferenceElement extendRef, final PsiElement resolved) {
|
||||
static HighlightInfo checkClassExtendsForeignInnerClass(@NotNull PsiJavaCodeReferenceElement extendRef, final PsiElement resolved) {
|
||||
PsiElement parent = extendRef.getParent();
|
||||
if (!(parent instanceof PsiReferenceList)) {
|
||||
return null;
|
||||
@@ -818,7 +815,7 @@ public class HighlightClassUtil {
|
||||
/**
|
||||
* 15.9 Class Instance Creation Expressions | 15.9.2 Determining Enclosing Instances
|
||||
*/
|
||||
private static boolean qualifiedNewCalledInConstructors(final PsiClass aClass) {
|
||||
private static boolean qualifiedNewCalledInConstructors(@NotNull PsiClass aClass) {
|
||||
PsiMethod[] constructors = aClass.getConstructors();
|
||||
if (constructors.length == 0) return false;
|
||||
for (PsiMethod constructor : constructors) {
|
||||
@@ -844,7 +841,7 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkCreateInnerClassFromStaticContext(PsiNewExpression expression, PsiType type, PsiClass aClass) {
|
||||
static HighlightInfo checkCreateInnerClassFromStaticContext(@NotNull PsiNewExpression expression, @Nullable PsiType type, @Nullable PsiClass aClass) {
|
||||
if (type == null || type instanceof PsiArrayType || type instanceof PsiPrimitiveType) return null;
|
||||
if (aClass == null) return null;
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
@@ -857,9 +854,9 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static HighlightInfo checkCreateInnerClassFromStaticContext(PsiElement element,
|
||||
public static HighlightInfo checkCreateInnerClassFromStaticContext(@NotNull PsiElement element,
|
||||
@Nullable PsiExpression qualifier,
|
||||
PsiClass aClass) {
|
||||
@Nullable PsiClass aClass) {
|
||||
PsiElement placeToSearchEnclosingFrom;
|
||||
if (qualifier != null) {
|
||||
PsiType qType = qualifier.getType();
|
||||
@@ -872,9 +869,9 @@ public class HighlightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkCreateInnerClassFromStaticContext(PsiElement element,
|
||||
PsiElement placeToSearchEnclosingFrom,
|
||||
PsiClass aClass) {
|
||||
static HighlightInfo checkCreateInnerClassFromStaticContext(@NotNull PsiElement element,
|
||||
@Nullable PsiElement placeToSearchEnclosingFrom,
|
||||
@Nullable PsiClass aClass) {
|
||||
if (aClass == null || !PsiUtil.isInnerClass(aClass)) return null;
|
||||
PsiClass outerClass = aClass.getContainingClass();
|
||||
if (outerClass == null) return null;
|
||||
@@ -912,13 +909,13 @@ public class HighlightClassUtil {
|
||||
@Nullable
|
||||
static HighlightInfo reportIllegalEnclosingUsage(PsiElement place,
|
||||
@Nullable PsiClass aClass,
|
||||
PsiClass outerClass,
|
||||
PsiElement elementToHighlight) {
|
||||
@Nullable PsiClass outerClass,
|
||||
@NotNull PsiElement elementToHighlight) {
|
||||
if (outerClass != null && !PsiTreeUtil.isContextAncestor(outerClass, place, false)) {
|
||||
String description = JavaErrorMessages.message("is.not.an.enclosing.class", HighlightUtil.formatClass(outerClass));
|
||||
HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(elementToHighlight).descriptionAndTooltip(description).create();
|
||||
registerMakeInnerClassStatic(highlightInfo, aClass);
|
||||
registerMakeInnerClassStatic(aClass, highlightInfo);
|
||||
return highlightInfo;
|
||||
}
|
||||
PsiModifierListOwner staticParent = PsiUtil.getEnclosingStaticElement(place, outerClass);
|
||||
|
||||
+7
-13
@@ -15,14 +15,12 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.Processor;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -138,8 +136,7 @@ public class HighlightControlFlowUtil {
|
||||
PsiCodeBlock ctrBody = constructor.getBody();
|
||||
if (ctrBody == null) return false;
|
||||
final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
|
||||
for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) {
|
||||
PsiMethod redirectedConstructor = redirectedConstructors.get(j);
|
||||
for (PsiMethod redirectedConstructor : redirectedConstructors) {
|
||||
final PsiCodeBlock body = redirectedConstructor.getBody();
|
||||
if (body != null && variableDefinitelyAssignedIn(field, body)) continue nextConstructor;
|
||||
}
|
||||
@@ -154,7 +151,7 @@ public class HighlightControlFlowUtil {
|
||||
|
||||
private static boolean isFieldInitializedInClassInitializer(@NotNull PsiField field,
|
||||
boolean isFieldStatic,
|
||||
Stream<PsiClassInitializer> initializers) {
|
||||
@NotNull Stream<PsiClassInitializer> initializers) {
|
||||
return initializers.anyMatch(initializer -> initializer.hasModifierProperty(PsiModifier.STATIC) == isFieldStatic
|
||||
&& variableDefinitelyAssignedIn(field, initializer.getBody()));
|
||||
}
|
||||
@@ -162,7 +159,7 @@ public class HighlightControlFlowUtil {
|
||||
private static boolean isFieldInitializedInOtherFieldInitializer(@NotNull PsiClass aClass,
|
||||
@NotNull PsiField field,
|
||||
final boolean fieldStatic,
|
||||
final Condition<PsiField> condition) {
|
||||
@NotNull Condition<PsiField> condition) {
|
||||
PsiField[] fields = aClass.getFields();
|
||||
for (PsiField psiField : fields) {
|
||||
if (psiField != field
|
||||
@@ -304,8 +301,7 @@ public class HighlightControlFlowUtil {
|
||||
if (variable.hasModifierProperty(PsiModifier.STATIC)) return null;
|
||||
// as a last chance, field may be initialized in this() call
|
||||
final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
|
||||
for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) {
|
||||
PsiMethod redirectedConstructor = redirectedConstructors.get(j);
|
||||
for (PsiMethod redirectedConstructor : redirectedConstructors) {
|
||||
// variable must be initialized before its usage
|
||||
//???
|
||||
//if (startOffset < redirectedConstructor.getTextRange().getStartOffset()) continue;
|
||||
@@ -357,8 +353,7 @@ public class HighlightControlFlowUtil {
|
||||
}
|
||||
// as a last chance, field may be initialized in this() call
|
||||
final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
|
||||
for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) {
|
||||
PsiMethod redirectedConstructor = redirectedConstructors.get(j);
|
||||
for (PsiMethod redirectedConstructor : redirectedConstructors) {
|
||||
// variable must be initialized before its usage
|
||||
if (offset < redirectedConstructor.getTextRange().getStartOffset()) continue;
|
||||
PsiCodeBlock redirectedBody = redirectedConstructor.getBody();
|
||||
@@ -540,9 +535,8 @@ public class HighlightControlFlowUtil {
|
||||
final PsiMethod ctr = codeBlock.getParent() instanceof PsiMethod ?
|
||||
(PsiMethod)codeBlock.getParent() : null;
|
||||
// assignment to final field in several constructors threatens us only if these are linked (there is this() call in the beginning)
|
||||
final List<PsiMethod> redirectedConstructors = ctr != null && ctr.isConstructor() ? JavaHighlightUtil.getChainedConstructors(ctr) : null;
|
||||
for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) {
|
||||
PsiMethod redirectedConstructor = redirectedConstructors.get(j);
|
||||
final List<PsiMethod> redirectedConstructors = ctr != null && ctr.isConstructor() ? JavaHighlightUtil.getChainedConstructors(ctr) : Collections.emptyList();
|
||||
for (PsiMethod redirectedConstructor : redirectedConstructors) {
|
||||
PsiCodeBlock body = redirectedConstructor.getBody();
|
||||
if (body != null && variableDefinitelyAssignedIn(variable, body)) {
|
||||
alreadyAssigned = true;
|
||||
|
||||
+126
-113
@@ -41,12 +41,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.openapi.util.Pair.pair;
|
||||
|
||||
/**
|
||||
* @author cdr
|
||||
* @since Aug 14, 2002
|
||||
*/
|
||||
public class HighlightMethodUtil {
|
||||
private static final QuickFixFactory QUICK_FIX_FACTORY = QuickFixFactory.getInstance();
|
||||
private static final String MISMATCH_COLOR = UIUtil.isUnderDarcula() ? "ff6464" : "red";
|
||||
@@ -54,7 +48,8 @@ public class HighlightMethodUtil {
|
||||
|
||||
private HighlightMethodUtil() { }
|
||||
|
||||
static String createClashMethodMessage(PsiMethod method1, PsiMethod method2, boolean showContainingClasses) {
|
||||
@NotNull
|
||||
static String createClashMethodMessage(@NotNull PsiMethod method1, @NotNull PsiMethod method2, boolean showContainingClasses) {
|
||||
if (showContainingClasses) {
|
||||
PsiClass class1 = method1.getContainingClass();
|
||||
PsiClass class2 = method2.getContainingClass();
|
||||
@@ -92,11 +87,11 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo isWeaker(PsiMethod method,
|
||||
PsiModifierList modifierList,
|
||||
String accessModifier,
|
||||
private static HighlightInfo isWeaker(@NotNull PsiMethod method,
|
||||
@NotNull PsiModifierList modifierList,
|
||||
@NotNull String accessModifier,
|
||||
int accessLevel,
|
||||
PsiMethod superMethod,
|
||||
@NotNull PsiMethod superMethod,
|
||||
boolean includeRealPositionInfo) {
|
||||
int superAccessLevel = PsiUtil.getAccessLevel(superMethod.getModifierList());
|
||||
if (accessLevel < superAccessLevel) {
|
||||
@@ -169,14 +164,13 @@ public class HighlightMethodUtil {
|
||||
|
||||
private static HighlightInfo checkSuperMethodSignature(@NotNull PsiMethod superMethod,
|
||||
@NotNull MethodSignatureBackedByPsiMethod superMethodSignature,
|
||||
PsiType superReturnType,
|
||||
@NotNull PsiType superReturnType,
|
||||
@NotNull PsiMethod method,
|
||||
@NotNull MethodSignatureBackedByPsiMethod methodSignature,
|
||||
@NotNull PsiType returnType,
|
||||
@NotNull String detailMessage,
|
||||
@NotNull TextRange range,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
if (superReturnType == null) return null;
|
||||
final PsiClass superContainingClass = superMethod.getContainingClass();
|
||||
if (superContainingClass != null &&
|
||||
CommonClassNames.JAVA_LANG_OBJECT.equals(superContainingClass.getQualifiedName()) &&
|
||||
@@ -232,8 +226,8 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
|
||||
static HighlightInfo checkMethodOverridesFinal(MethodSignatureBackedByPsiMethod methodSignature,
|
||||
List<HierarchicalMethodSignature> superMethodSignatures) {
|
||||
static HighlightInfo checkMethodOverridesFinal(@NotNull MethodSignatureBackedByPsiMethod methodSignature,
|
||||
@NotNull List<HierarchicalMethodSignature> superMethodSignatures) {
|
||||
PsiMethod method = methodSignature.getMethod();
|
||||
for (MethodSignatureBackedByPsiMethod superMethodSignature : superMethodSignatures) {
|
||||
PsiMethod superMethod = superMethodSignature.getMethod();
|
||||
@@ -243,7 +237,7 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkSuperMethodIsFinal(PsiMethod method, PsiMethod superMethod) {
|
||||
private static HighlightInfo checkSuperMethodIsFinal(@NotNull PsiMethod method, @NotNull PsiMethod superMethod) {
|
||||
// strange things happen when super method is from Object and method from interface
|
||||
if (superMethod.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
PsiClass superClass = superMethod.getContainingClass();
|
||||
@@ -260,10 +254,10 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkMethodIncompatibleThrows(MethodSignatureBackedByPsiMethod methodSignature,
|
||||
List<HierarchicalMethodSignature> superMethodSignatures,
|
||||
static HighlightInfo checkMethodIncompatibleThrows(@NotNull MethodSignatureBackedByPsiMethod methodSignature,
|
||||
@NotNull List<HierarchicalMethodSignature> superMethodSignatures,
|
||||
boolean includeRealPositionInfo,
|
||||
PsiClass analyzedClass) {
|
||||
@NotNull PsiClass analyzedClass) {
|
||||
PsiMethod method = methodSignature.getMethod();
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) return null;
|
||||
@@ -324,14 +318,15 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
// return number of exception which was not declared in super method or -1
|
||||
private static int getExtraExceptionNum(final MethodSignature methodSignature,
|
||||
final MethodSignatureBackedByPsiMethod superSignature,
|
||||
List<PsiClassType> checkedExceptions, PsiSubstitutor substitutorForDerivedClass) {
|
||||
private static int getExtraExceptionNum(@NotNull MethodSignature methodSignature,
|
||||
@NotNull MethodSignatureBackedByPsiMethod superSignature,
|
||||
@NotNull List<PsiClassType> checkedExceptions,
|
||||
@NotNull PsiSubstitutor substitutorForDerivedClass) {
|
||||
PsiMethod superMethod = superSignature.getMethod();
|
||||
PsiSubstitutor substitutorForMethod = MethodSignatureUtil.getSuperMethodSignatureSubstitutor(methodSignature, superSignature);
|
||||
for (int i = 0; i < checkedExceptions.size(); i++) {
|
||||
final PsiClassType checkedEx = checkedExceptions.get(i);
|
||||
final PsiType substituted = substitutorForMethod != null ? substitutorForMethod.substitute(checkedEx) : TypeConversionUtil.erasure(checkedEx);
|
||||
final PsiType substituted = substitutorForMethod == null ? TypeConversionUtil.erasure(checkedEx) : substitutorForMethod.substitute(checkedEx);
|
||||
PsiType exception = substitutorForDerivedClass.substitute(substituted);
|
||||
if (!isMethodThrows(superMethod, substitutorForMethod, exception, substitutorForDerivedClass)) {
|
||||
return i;
|
||||
@@ -340,7 +335,10 @@ public class HighlightMethodUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static boolean isMethodThrows(PsiMethod method, @Nullable PsiSubstitutor substitutorForMethod, PsiType exception, PsiSubstitutor substitutorForDerivedClass) {
|
||||
private static boolean isMethodThrows(@NotNull PsiMethod method,
|
||||
@Nullable PsiSubstitutor substitutorForMethod,
|
||||
PsiType exception,
|
||||
@NotNull PsiSubstitutor substitutorForDerivedClass) {
|
||||
PsiClassType[] thrownExceptions = method.getThrowsList().getReferencedTypes();
|
||||
for (PsiClassType thrownException1 : thrownExceptions) {
|
||||
PsiType thrownException = substitutorForMethod != null ? substitutorForMethod.substitute(thrownException1) : TypeConversionUtil.erasure(thrownException1);
|
||||
@@ -508,8 +506,8 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
private static void registerTargetTypeFixesBasedOnApplicabilityInference(@NotNull PsiMethodCallExpression methodCall,
|
||||
MethodCandidateInfo resolveResult,
|
||||
PsiMethod resolved,
|
||||
@NotNull MethodCandidateInfo resolveResult,
|
||||
@NotNull PsiMethod resolved,
|
||||
HighlightInfo highlightInfo) {
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodCall.getParent());
|
||||
PsiVariable variable = null;
|
||||
@@ -537,10 +535,10 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static HighlightInfo checkStaticInterfaceCallQualifier(PsiReferenceExpression referenceToMethod,
|
||||
JavaResolveResult resolveResult,
|
||||
TextRange fixRange,
|
||||
PsiClass containingClass) {
|
||||
static HighlightInfo checkStaticInterfaceCallQualifier(@NotNull PsiReferenceExpression referenceToMethod,
|
||||
@NotNull JavaResolveResult resolveResult,
|
||||
@NotNull TextRange fixRange,
|
||||
@NotNull PsiClass containingClass) {
|
||||
String message = checkStaticInterfaceMethodCallQualifier(referenceToMethod, resolveResult.getCurrentFileResolveScope(), containingClass);
|
||||
if (message != null) {
|
||||
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).descriptionAndTooltip(message).range(fixRange).create();
|
||||
@@ -553,7 +551,9 @@ public class HighlightMethodUtil {
|
||||
|
||||
/* see also PsiReferenceExpressionImpl.hasValidQualifier() */
|
||||
@Nullable
|
||||
private static String checkStaticInterfaceMethodCallQualifier(PsiReferenceExpression ref, PsiElement scope, PsiClass containingClass) {
|
||||
private static String checkStaticInterfaceMethodCallQualifier(@NotNull PsiReferenceExpression ref,
|
||||
@Nullable PsiElement scope,
|
||||
@NotNull PsiClass containingClass) {
|
||||
PsiExpression qualifierExpression = ref.getQualifierExpression();
|
||||
if (qualifierExpression == null && (scope instanceof PsiImportStaticStatement || PsiTreeUtil.isAncestor(containingClass, ref, true))) {
|
||||
return null;
|
||||
@@ -583,9 +583,9 @@ public class HighlightMethodUtil {
|
||||
return JavaErrorMessages.message("static.interface.method.call.qualifier");
|
||||
}
|
||||
|
||||
private static void registerMethodReturnFixAction(HighlightInfo highlightInfo,
|
||||
MethodCandidateInfo candidate,
|
||||
PsiCall methodCall) {
|
||||
private static void registerMethodReturnFixAction(@NotNull HighlightInfo highlightInfo,
|
||||
@NotNull MethodCandidateInfo candidate,
|
||||
@NotNull PsiCall methodCall) {
|
||||
if (methodCall.getParent() instanceof PsiReturnStatement) {
|
||||
final PsiMethod containerMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class, true, PsiLambdaExpression.class);
|
||||
if (containerMethod != null) {
|
||||
@@ -654,10 +654,10 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean isDummyConstructorCall(PsiMethodCallExpression methodCall,
|
||||
PsiResolveHelper resolveHelper,
|
||||
PsiExpressionList list,
|
||||
PsiReferenceExpression referenceToMethod) {
|
||||
static boolean isDummyConstructorCall(@NotNull PsiMethodCallExpression methodCall,
|
||||
@NotNull PsiResolveHelper resolveHelper,
|
||||
@NotNull PsiExpressionList list,
|
||||
@NotNull PsiReferenceExpression referenceToMethod) {
|
||||
boolean isDummy = false;
|
||||
boolean isThisOrSuper = referenceToMethod.getReferenceNameElement() instanceof PsiKeyword;
|
||||
if (isThisOrSuper) {
|
||||
@@ -812,7 +812,8 @@ public class HighlightMethodUtil {
|
||||
return info;
|
||||
}
|
||||
|
||||
private static Pair<MethodCandidateInfo, MethodCandidateInfo> findCandidates(JavaResolveResult[] resolveResults) {
|
||||
@NotNull
|
||||
private static Pair<MethodCandidateInfo, MethodCandidateInfo> findCandidates(@NotNull JavaResolveResult[] resolveResults) {
|
||||
MethodCandidateInfo methodCandidate1 = null;
|
||||
MethodCandidateInfo methodCandidate2 = null;
|
||||
for (JavaResolveResult result : resolveResults) {
|
||||
@@ -828,10 +829,11 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return pair(methodCandidate1, methodCandidate2);
|
||||
return Pair.pair(methodCandidate1, methodCandidate2);
|
||||
}
|
||||
|
||||
private static MethodCandidateInfo[] toMethodCandidates(JavaResolveResult[] resolveResults) {
|
||||
@NotNull
|
||||
private static MethodCandidateInfo[] toMethodCandidates(@NotNull JavaResolveResult[] resolveResults) {
|
||||
List<MethodCandidateInfo> candidateList = new ArrayList<>(resolveResults.length);
|
||||
for (JavaResolveResult result : resolveResults) {
|
||||
if (!(result instanceof MethodCandidateInfo)) continue;
|
||||
@@ -842,9 +844,9 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
private static void registerMethodCallIntentions(@Nullable HighlightInfo highlightInfo,
|
||||
PsiMethodCallExpression methodCall,
|
||||
PsiExpressionList list,
|
||||
PsiResolveHelper resolveHelper) {
|
||||
@NotNull PsiMethodCallExpression methodCall,
|
||||
@NotNull PsiExpressionList list,
|
||||
@NotNull PsiResolveHelper resolveHelper) {
|
||||
TextRange fixRange = getFixRange(methodCall);
|
||||
final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression();
|
||||
if (qualifierExpression instanceof PsiReferenceExpression) {
|
||||
@@ -891,10 +893,10 @@ public class HighlightMethodUtil {
|
||||
ChangeStringLiteralToCharInMethodCallFix.registerFixes(candidates, methodCall, highlightInfo);
|
||||
}
|
||||
|
||||
private static void registerMethodAccessLevelIntentions(CandidateInfo[] methodCandidates,
|
||||
PsiMethodCallExpression methodCall,
|
||||
PsiExpressionList exprList,
|
||||
HighlightInfo highlightInfo) {
|
||||
private static void registerMethodAccessLevelIntentions(@NotNull CandidateInfo[] methodCandidates,
|
||||
@NotNull PsiMethodCallExpression methodCall,
|
||||
@NotNull PsiExpressionList exprList,
|
||||
@Nullable HighlightInfo highlightInfo) {
|
||||
for (CandidateInfo methodCandidate : methodCandidates) {
|
||||
PsiMethod method = (PsiMethod)methodCandidate.getElement();
|
||||
if (!methodCandidate.isAccessible() && PsiUtil.isApplicable(method, methodCandidate.getSubstitutor(), exprList)) {
|
||||
@@ -904,7 +906,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String createAmbiguousMethodHtmlTooltip(MethodCandidateInfo[] methodCandidates) {
|
||||
private static String createAmbiguousMethodHtmlTooltip(@NotNull MethodCandidateInfo[] methodCandidates) {
|
||||
return JavaErrorMessages.message("ambiguous.method.html.tooltip",
|
||||
methodCandidates[0].getElement().getParameterList().getParametersCount() + 2,
|
||||
createAmbiguousMethodHtmlTooltipMethodRow(methodCandidates[0]),
|
||||
@@ -913,14 +915,16 @@ public class HighlightMethodUtil {
|
||||
getContainingClassName(methodCandidates[1]));
|
||||
}
|
||||
|
||||
private static String getContainingClassName(final MethodCandidateInfo methodCandidate) {
|
||||
@NotNull
|
||||
private static String getContainingClassName(@NotNull MethodCandidateInfo methodCandidate) {
|
||||
PsiMethod method = methodCandidate.getElement();
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
return containingClass == null ? method.getContainingFile().getName() : HighlightUtil.formatClass(containingClass, false);
|
||||
}
|
||||
|
||||
@Language("HTML")
|
||||
private static String createAmbiguousMethodHtmlTooltipMethodRow(final MethodCandidateInfo methodCandidate) {
|
||||
@NotNull
|
||||
private static String createAmbiguousMethodHtmlTooltipMethodRow(@NotNull MethodCandidateInfo methodCandidate) {
|
||||
PsiMethod method = methodCandidate.getElement();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiSubstitutor substitutor = methodCandidate.getSubstitutor();
|
||||
@@ -937,7 +941,8 @@ public class HighlightMethodUtil {
|
||||
return ms.toString();
|
||||
}
|
||||
|
||||
private static String createMismatchedArgumentsHtmlTooltip(MethodCandidateInfo info, PsiExpressionList list) {
|
||||
@NotNull
|
||||
private static String createMismatchedArgumentsHtmlTooltip(@NotNull MethodCandidateInfo info, @NotNull PsiExpressionList list) {
|
||||
PsiMethod method = info.getElement();
|
||||
PsiSubstitutor substitutor = info.getSubstitutor();
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
@@ -946,12 +951,12 @@ public class HighlightMethodUtil {
|
||||
return createMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass);
|
||||
}
|
||||
|
||||
private static String createShortMismatchedArgumentsHtmlTooltip(PsiExpressionList list,
|
||||
private static String createShortMismatchedArgumentsHtmlTooltip(@NotNull PsiExpressionList list,
|
||||
@Nullable MethodCandidateInfo info,
|
||||
PsiParameter[] parameters,
|
||||
String methodName,
|
||||
PsiSubstitutor substitutor,
|
||||
PsiClass aClass) {
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull String methodName,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull PsiClass aClass) {
|
||||
PsiExpression[] expressions = list.getExpressions();
|
||||
int cols = Math.max(parameters.length, expressions.length);
|
||||
|
||||
@@ -969,11 +974,13 @@ public class HighlightMethodUtil {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String escTrim(@NotNull String s) {
|
||||
return XmlStringUtil.escapeString(trimNicely(s));
|
||||
}
|
||||
|
||||
private static String trimNicely(String s) {
|
||||
@NotNull
|
||||
private static String trimNicely(@NotNull String s) {
|
||||
if (s.length() <= 40) return s;
|
||||
|
||||
List<TextRange> wordIndices = StringUtil.getWordIndicesIn(s);
|
||||
@@ -996,24 +1003,26 @@ public class HighlightMethodUtil {
|
||||
return StringUtil.last(s, 40, true).toString();
|
||||
}
|
||||
|
||||
private static String createMismatchedArgumentsHtmlTooltip(PsiExpressionList list,
|
||||
MethodCandidateInfo info,
|
||||
PsiParameter[] parameters,
|
||||
String methodName,
|
||||
PsiSubstitutor substitutor,
|
||||
PsiClass aClass) {
|
||||
@NotNull
|
||||
private static String createMismatchedArgumentsHtmlTooltip(@NotNull PsiExpressionList list,
|
||||
@Nullable MethodCandidateInfo info,
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull String methodName,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull PsiClass aClass) {
|
||||
return Math.max(parameters.length, list.getExpressionCount()) <= 2
|
||||
? createShortMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass)
|
||||
: createLongMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass);
|
||||
}
|
||||
|
||||
@Language("HTML")
|
||||
private static String createLongMismatchedArgumentsHtmlTooltip(PsiExpressionList list,
|
||||
@NotNull
|
||||
private static String createLongMismatchedArgumentsHtmlTooltip(@NotNull PsiExpressionList list,
|
||||
@Nullable MethodCandidateInfo info,
|
||||
PsiParameter[] parameters,
|
||||
String methodName,
|
||||
PsiSubstitutor substitutor,
|
||||
PsiClass aClass) {
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull String methodName,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull PsiClass aClass) {
|
||||
PsiExpression[] expressions = list.getExpressions();
|
||||
|
||||
StringBuilder s = new StringBuilder()
|
||||
@@ -1085,9 +1094,10 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
@Language("HTML")
|
||||
private static String createMismatchedArgsHtmlTooltipArgumentsRow(PsiExpression[] expressions,
|
||||
PsiParameter[] parameters,
|
||||
PsiSubstitutor substitutor,
|
||||
@NotNull
|
||||
private static String createMismatchedArgsHtmlTooltipArgumentsRow(@NotNull PsiExpression[] expressions,
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
int cols) {
|
||||
StringBuilder ms = new StringBuilder();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
@@ -1114,9 +1124,10 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
@Language("HTML")
|
||||
private static String createMismatchedArgsHtmlTooltipParamsRow(PsiParameter[] parameters,
|
||||
PsiSubstitutor substitutor,
|
||||
PsiExpression[] expressions) {
|
||||
@NotNull
|
||||
private static String createMismatchedArgsHtmlTooltipParamsRow(@NotNull PsiParameter[] parameters,
|
||||
@NotNull PsiSubstitutor substitutor,
|
||||
@NotNull PsiExpression[] expressions) {
|
||||
StringBuilder ms = new StringBuilder();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
@@ -1132,9 +1143,9 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
private static boolean showShortType(int i,
|
||||
PsiParameter[] parameters,
|
||||
PsiExpression[] expressions,
|
||||
PsiSubstitutor substitutor) {
|
||||
@NotNull PsiParameter[] parameters,
|
||||
@NotNull PsiExpression[] expressions,
|
||||
@NotNull PsiSubstitutor substitutor) {
|
||||
PsiExpression expression = i < expressions.length ? expressions[i] : null;
|
||||
if (expression == null) return true;
|
||||
PsiType paramType = i < parameters.length && parameters[i] != null
|
||||
@@ -1145,7 +1156,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
|
||||
static HighlightInfo checkMethodMustHaveBody(PsiMethod method, PsiClass aClass) {
|
||||
static HighlightInfo checkMethodMustHaveBody(@NotNull PsiMethod method, @Nullable PsiClass aClass) {
|
||||
HighlightInfo errorResult = null;
|
||||
if (method.getBody() == null
|
||||
&& !method.hasModifierProperty(PsiModifier.ABSTRACT)
|
||||
@@ -1167,7 +1178,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
|
||||
static HighlightInfo checkAbstractMethodInConcreteClass(PsiMethod method, PsiElement elementToHighlight) {
|
||||
static HighlightInfo checkAbstractMethodInConcreteClass(@NotNull PsiMethod method, @NotNull PsiElement elementToHighlight) {
|
||||
HighlightInfo errorResult = null;
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT)
|
||||
@@ -1207,10 +1218,10 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkDuplicateMethod(PsiClass aClass,
|
||||
static HighlightInfo checkDuplicateMethod(@NotNull PsiClass aClass,
|
||||
@NotNull PsiMethod method,
|
||||
@NotNull MostlySingularMultiMap<MethodSignature, PsiMethod> duplicateMethods) {
|
||||
if (aClass == null || method instanceof ExternallyDefinedPsiElement) return null;
|
||||
if (method instanceof ExternallyDefinedPsiElement) return null;
|
||||
MethodSignature methodSignature = method.getSignature(PsiSubstitutor.EMPTY);
|
||||
int methodCount = 1;
|
||||
List<PsiMethod> methods = (List<PsiMethod>)duplicateMethods.get(methodSignature);
|
||||
@@ -1325,9 +1336,9 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
|
||||
static HighlightInfo checkConstructorCallsBaseClassConstructor(PsiMethod constructor,
|
||||
RefCountHolder refCountHolder,
|
||||
PsiResolveHelper resolveHelper) {
|
||||
static HighlightInfo checkConstructorCallsBaseClassConstructor(@NotNull PsiMethod constructor,
|
||||
@NotNull RefCountHolder refCountHolder,
|
||||
@NotNull PsiResolveHelper resolveHelper) {
|
||||
if (!constructor.isConstructor()) return null;
|
||||
PsiClass aClass = constructor.getContainingClass();
|
||||
if (aClass == null) return null;
|
||||
@@ -1390,13 +1401,12 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkStaticMethodOverride(PsiClass aClass,
|
||||
PsiMethod method,
|
||||
private static HighlightInfo checkStaticMethodOverride(@NotNull PsiClass aClass,
|
||||
@NotNull PsiMethod method,
|
||||
boolean isMethodStatic,
|
||||
PsiClass superClass,
|
||||
PsiMethod superMethod,
|
||||
PsiFile containingFile) {
|
||||
if (superMethod == null) return null;
|
||||
@NotNull PsiClass superClass,
|
||||
@NotNull PsiMethod superMethod,
|
||||
@NotNull PsiFile containingFile) {
|
||||
PsiManager manager = containingFile.getManager();
|
||||
PsiModifierList superModifierList = superMethod.getModifierList();
|
||||
PsiModifierList modifierList = method.getModifierList();
|
||||
@@ -1443,8 +1453,8 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo checkInterfaceInheritedMethodsReturnTypes(List<? extends MethodSignatureBackedByPsiMethod> superMethodSignatures,
|
||||
LanguageLevel languageLevel) {
|
||||
private static HighlightInfo checkInterfaceInheritedMethodsReturnTypes(@NotNull List<? extends MethodSignatureBackedByPsiMethod> superMethodSignatures,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
if (superMethodSignatures.size() < 2) return null;
|
||||
final MethodSignatureBackedByPsiMethod[] returnTypeSubstitutable = {superMethodSignatures.get(0)};
|
||||
for (int i = 1; i < superMethodSignatures.size(); i++) {
|
||||
@@ -1486,7 +1496,9 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static HighlightInfo checkOverrideEquivalentInheritedMethods(PsiClass aClass, PsiFile containingFile, @NotNull LanguageLevel languageLevel) {
|
||||
static HighlightInfo checkOverrideEquivalentInheritedMethods(@NotNull PsiClass aClass,
|
||||
@NotNull PsiFile containingFile,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
String description = null;
|
||||
boolean appendImplementMethodFix = true;
|
||||
final Collection<HierarchicalMethodSignature> visibleSignatures = aClass.getVisibleSignatures();
|
||||
@@ -1558,7 +1570,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
|
||||
static HighlightInfo checkConstructorHandleSuperClassExceptions(PsiMethod method) {
|
||||
static HighlightInfo checkConstructorHandleSuperClassExceptions(@NotNull PsiMethod method) {
|
||||
if (!method.isConstructor()) {
|
||||
return null;
|
||||
}
|
||||
@@ -1604,7 +1616,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
|
||||
static void checkNewExpression(@NotNull PsiNewExpression expression,
|
||||
PsiType type,
|
||||
@Nullable PsiType type,
|
||||
@NotNull HighlightInfoHolder holder,
|
||||
@NotNull JavaSdkVersion javaSdkVersion) {
|
||||
if (!(type instanceof PsiClassType)) return;
|
||||
@@ -1626,7 +1638,7 @@ public class HighlightMethodUtil {
|
||||
static void checkConstructorCall(@NotNull PsiClassType.ClassResolveResult typeResolveResult,
|
||||
@NotNull PsiConstructorCall constructorCall,
|
||||
@NotNull PsiType type,
|
||||
PsiJavaCodeReferenceElement classReference,
|
||||
@Nullable PsiJavaCodeReferenceElement classReference,
|
||||
@NotNull HighlightInfoHolder holder,
|
||||
@NotNull JavaSdkVersion javaSdkVersion) {
|
||||
PsiExpressionList list = constructorCall.getArgumentList();
|
||||
@@ -1756,7 +1768,7 @@ public class HighlightMethodUtil {
|
||||
* then where the last formal parameter type of the invocation type of the method is Fn[],
|
||||
* it is a compile-time error if the type which is the erasure of Fn is not accessible at the point of invocation.
|
||||
*/
|
||||
private static HighlightInfo checkVarargParameterErasureToBeAccessible(MethodCandidateInfo info, PsiCall place) {
|
||||
private static HighlightInfo checkVarargParameterErasureToBeAccessible(@NotNull MethodCandidateInfo info, @NotNull PsiCall place) {
|
||||
final PsiMethod method = info.getElement();
|
||||
if (info.isVarargs() || method.isVarArgs() && !PsiUtil.isLanguageLevel8OrHigher(place)) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
@@ -1776,12 +1788,13 @@ public class HighlightMethodUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void registerFixesOnInvalidConstructorCall(PsiConstructorCall constructorCall,
|
||||
PsiJavaCodeReferenceElement classReference,
|
||||
PsiExpressionList list,
|
||||
PsiClass aClass,
|
||||
PsiMethod[] constructors,
|
||||
JavaResolveResult[] results, PsiElement infoElement,
|
||||
private static void registerFixesOnInvalidConstructorCall(@NotNull PsiConstructorCall constructorCall,
|
||||
@Nullable PsiJavaCodeReferenceElement classReference,
|
||||
@NotNull PsiExpressionList list,
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull PsiMethod[] constructors,
|
||||
@NotNull JavaResolveResult[] results,
|
||||
@NotNull PsiElement infoElement,
|
||||
@NotNull final HighlightInfo info) {
|
||||
QuickFixAction.registerQuickFixActions(
|
||||
info, constructorCall.getTextRange(), QUICK_FIX_FACTORY.createCreateConstructorFromUsageFixes(constructorCall)
|
||||
@@ -1798,9 +1811,9 @@ public class HighlightMethodUtil {
|
||||
ChangeStringLiteralToCharInMethodCallFix.registerFixes(constructors, constructorCall, info);
|
||||
}
|
||||
|
||||
private static HighlightInfo buildAccessProblem(PsiJavaCodeReferenceElement ref,
|
||||
PsiMember resolved,
|
||||
JavaResolveResult result) {
|
||||
private static HighlightInfo buildAccessProblem(@NotNull PsiJavaCodeReferenceElement ref,
|
||||
@NotNull PsiMember resolved,
|
||||
@NotNull JavaResolveResult result) {
|
||||
String description = HighlightUtil.accessProblemDescription(ref, resolved, result);
|
||||
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref).descriptionAndTooltip(description).navigationShift(+1).create();
|
||||
if (result.isStaticsScopeCorrect()) {
|
||||
@@ -1809,8 +1822,7 @@ public class HighlightMethodUtil {
|
||||
return info;
|
||||
}
|
||||
|
||||
private static boolean callingProtectedConstructorFromDerivedClass(PsiConstructorCall place, PsiClass constructorClass) {
|
||||
if (constructorClass == null) return false;
|
||||
private static boolean callingProtectedConstructorFromDerivedClass(@NotNull PsiConstructorCall place, @NotNull PsiClass constructorClass) {
|
||||
// indirect instantiation via anonymous class is ok
|
||||
if (place instanceof PsiNewExpression && ((PsiNewExpression)place).getAnonymousClass() != null) return false;
|
||||
PsiElement curElement = place;
|
||||
@@ -1826,7 +1838,8 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildArgTypesList(PsiExpressionList list) {
|
||||
@NotNull
|
||||
private static String buildArgTypesList(@NotNull PsiExpressionList list) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("(");
|
||||
PsiExpression[] args = list.getExpressions();
|
||||
@@ -1841,7 +1854,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
private static void registerChangeParameterClassFix(@NotNull PsiCall methodCall,
|
||||
@NotNull PsiExpressionList list,
|
||||
HighlightInfo highlightInfo) {
|
||||
@Nullable HighlightInfo highlightInfo) {
|
||||
final JavaResolveResult result = methodCall.resolveMethodGenerics();
|
||||
PsiMethod method = (PsiMethod)result.getElement();
|
||||
final PsiSubstitutor substitutor = result.getSubstitutor();
|
||||
@@ -1869,7 +1882,7 @@ public class HighlightMethodUtil {
|
||||
private static void registerChangeMethodSignatureFromUsageIntentions(@NotNull JavaResolveResult[] candidates,
|
||||
@NotNull PsiExpressionList list,
|
||||
@Nullable HighlightInfo highlightInfo,
|
||||
TextRange fixRange) {
|
||||
@Nullable TextRange fixRange) {
|
||||
if (candidates.length == 0) return;
|
||||
PsiExpression[] expressions = list.getExpressions();
|
||||
for (JavaResolveResult candidate : candidates) {
|
||||
@@ -1879,7 +1892,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
private static void registerChangeMethodSignatureFromUsageIntention(@NotNull PsiExpression[] expressions,
|
||||
@Nullable HighlightInfo highlightInfo,
|
||||
TextRange fixRange,
|
||||
@Nullable TextRange fixRange,
|
||||
@NotNull JavaResolveResult candidate,
|
||||
@NotNull PsiElement context) {
|
||||
if (!candidate.isStaticsScopeCorrect()) return;
|
||||
|
||||
+2
-2
@@ -204,7 +204,7 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfoType getVariableNameHighlightType(@NotNull PsiVariable var, PsiElement elementToHighlight) {
|
||||
private static HighlightInfoType getVariableNameHighlightType(@NotNull PsiVariable var, @NotNull PsiElement elementToHighlight) {
|
||||
if (var instanceof PsiLocalVariable
|
||||
|| var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiForeachStatement) {
|
||||
return JavaHighlightInfoTypes.LOCAL_VARIABLE;
|
||||
@@ -231,7 +231,7 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static HighlightInfoType getClassNameHighlightType(@Nullable PsiClass aClass, @Nullable PsiElement element) {
|
||||
private static HighlightInfoType getClassNameHighlightType(@Nullable PsiClass aClass, @NotNull PsiElement element) {
|
||||
if (element instanceof PsiJavaCodeReferenceElement && element.getParent() instanceof PsiAnonymousClass) {
|
||||
return JavaHighlightInfoTypes.ANONYMOUS_CLASS_NAME;
|
||||
}
|
||||
|
||||
+86
-83
@@ -59,12 +59,6 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.intellij.openapi.util.Pair.pair;
|
||||
|
||||
/**
|
||||
* @author cdr
|
||||
* @since Jul 30, 2002
|
||||
*/
|
||||
public class HighlightUtil extends HighlightUtilBase {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil");
|
||||
|
||||
@@ -134,11 +128,9 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
private HighlightUtil() { }
|
||||
|
||||
@Nullable
|
||||
private static String getIncompatibleModifier(String modifier,
|
||||
@Nullable PsiModifierList modifierList,
|
||||
private static String getIncompatibleModifier(@NotNull String modifier,
|
||||
@NotNull PsiModifierList modifierList,
|
||||
@NotNull Map<String, Set<String>> incompatibleModifiersHash) {
|
||||
if (modifierList == null) return null;
|
||||
|
||||
// modifier is always incompatible with itself
|
||||
PsiElement[] modifiers = modifierList.getChildren();
|
||||
int modifierCount = 0;
|
||||
@@ -274,7 +266,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isIntersection(PsiTypeElement castTypeElement, PsiType castType) {
|
||||
private static boolean isIntersection(@NotNull PsiTypeElement castTypeElement, @NotNull PsiType castType) {
|
||||
if (castType instanceof PsiIntersectionType) return true;
|
||||
return castType instanceof PsiClassType && PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class) != null;
|
||||
}
|
||||
@@ -414,7 +406,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return highlightInfo;
|
||||
}
|
||||
|
||||
static HighlightInfo checkLegalVarReference(PsiJavaCodeReferenceElement ref, @NotNull PsiClass resolved) {
|
||||
static HighlightInfo checkLegalVarReference(@NotNull PsiJavaCodeReferenceElement ref, @NotNull PsiClass resolved) {
|
||||
if (PsiKeyword.VAR.equals(resolved.getName()) && PsiUtil.getLanguageLevel(ref).isAtLeast(LanguageLevel.JDK_10)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.descriptionAndTooltip("Illegal reference to restricted type 'var'")
|
||||
@@ -594,8 +586,9 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
@NotNull
|
||||
private static String getUnhandledExceptionsDescriptor(@NotNull final Collection<PsiClassType> unhandled, @Nullable final String source) {
|
||||
final String exceptions = formatTypes(unhandled);
|
||||
return source != null ? JavaErrorMessages.message("unhandled.close.exceptions", exceptions, unhandled.size(), source)
|
||||
: JavaErrorMessages.message("unhandled.exceptions", exceptions, unhandled.size());
|
||||
return source == null
|
||||
? JavaErrorMessages.message("unhandled.exceptions", exceptions, unhandled.size())
|
||||
: JavaErrorMessages.message("unhandled.close.exceptions", exceptions, unhandled.size(), source);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -752,7 +745,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfoType getUnhandledExceptionHighlightType(PsiElement element) {
|
||||
private static HighlightInfoType getUnhandledExceptionHighlightType(@NotNull PsiElement element) {
|
||||
// JSP top level errors are handled by UnhandledExceptionInJSP inspection
|
||||
if (FileTypeUtils.isInServerPageFile(element)) {
|
||||
PsiMethod targetMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class, true, PsiLambdaExpression.class);
|
||||
@@ -815,8 +808,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Contract("null -> null")
|
||||
private static Map<String, Set<String>> getIncompatibleModifierMap(@Nullable PsiElement modifierListOwner) {
|
||||
if (modifierListOwner == null || PsiUtilCore.hasErrorElementChild(modifierListOwner)) return null;
|
||||
private static Map<String, Set<String>> getIncompatibleModifierMap(@NotNull PsiElement modifierListOwner) {
|
||||
if (PsiUtilCore.hasErrorElementChild(modifierListOwner)) return null;
|
||||
if (modifierListOwner instanceof PsiClass) {
|
||||
return ((PsiClass)modifierListOwner).isInterface() ? ourInterfaceIncompatibleModifiers : ourClassIncompatibleModifiers;
|
||||
}
|
||||
@@ -829,14 +822,19 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static String getIncompatibleModifier(String modifier, @NotNull PsiModifierList modifierList) {
|
||||
Map<String, Set<String>> incompatibleModifierMap = getIncompatibleModifierMap(modifierList.getParent());
|
||||
return incompatibleModifierMap != null ? getIncompatibleModifier(modifier, modifierList, incompatibleModifierMap) : null;
|
||||
static String getIncompatibleModifier(@NotNull String modifier, @NotNull PsiModifierList modifierList) {
|
||||
PsiElement parent = modifierList.getParent();
|
||||
Map<String, Set<String>> incompatibleModifierMap = null;
|
||||
if (parent != null) {
|
||||
incompatibleModifierMap = getIncompatibleModifierMap(parent);
|
||||
}
|
||||
return incompatibleModifierMap == null ? null : getIncompatibleModifier(modifier, modifierList, incompatibleModifierMap);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkNotAllowedModifier(@NotNull PsiKeyword keyword, @NotNull PsiModifierList modifierList) {
|
||||
PsiElement modifierOwner = modifierList.getParent();
|
||||
if (modifierOwner == null) return null;
|
||||
Map<String, Set<String>> incompatibleModifierMap = getIncompatibleModifierMap(modifierOwner);
|
||||
if (incompatibleModifierMap == null) return null;
|
||||
|
||||
@@ -932,7 +930,9 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static HighlightInfo checkLiteralExpressionParsingError(@NotNull PsiLiteralExpression expression, LanguageLevel level, PsiFile file) {
|
||||
public static HighlightInfo checkLiteralExpressionParsingError(@NotNull PsiLiteralExpression expression,
|
||||
@NotNull LanguageLevel level,
|
||||
@Nullable PsiFile file) {
|
||||
PsiElement literal = expression.getFirstChild();
|
||||
assert literal instanceof PsiJavaToken : literal;
|
||||
IElementType type = ((PsiJavaToken)literal).getTokenType();
|
||||
@@ -945,7 +945,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
String text = isInt || isFP ? literal.getText().toLowerCase() : literal.getText();
|
||||
Object value = expression.getValue();
|
||||
|
||||
if (level != null && file != null) {
|
||||
if (file != null) {
|
||||
if (isFP) {
|
||||
if (text.startsWith(PsiLiteralUtil.HEX_PREFIX)) {
|
||||
final HighlightInfo info = checkFeature(expression, Feature.HEX_FP_LITERALS, level, file);
|
||||
@@ -1121,7 +1121,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
")[fd]?");
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkUnderscores(PsiElement expression, String text, boolean isInt) {
|
||||
private static HighlightInfo checkUnderscores(@NotNull PsiElement expression, @NotNull String text, boolean isInt) {
|
||||
String[] parts = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
|
||||
if (isInt) {
|
||||
@@ -1152,7 +1152,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMustBeBoolean(@NotNull PsiExpression expr, PsiType type) {
|
||||
static HighlightInfo checkMustBeBoolean(@NotNull PsiExpression expr, @Nullable PsiType type) {
|
||||
PsiElement parent = expr.getParent();
|
||||
if (parent instanceof PsiIfStatement || parent instanceof PsiWhileStatement ||
|
||||
parent instanceof PsiForStatement && expr.equals(((PsiForStatement)parent).getCondition()) ||
|
||||
@@ -1166,7 +1166,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo createMustBeBooleanInfo(@NotNull PsiExpression expr, PsiType type) {
|
||||
private static HighlightInfo createMustBeBooleanInfo(@NotNull PsiExpression expr, @Nullable PsiType type) {
|
||||
final HighlightInfo info = createIncompatibleTypeHighlightInfo(PsiType.BOOLEAN, type, expr.getTextRange(), 0);
|
||||
if (expr instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expr;
|
||||
@@ -1200,7 +1200,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static List<HighlightInfo> checkExceptionThrownInTry(@NotNull final PsiParameter parameter, @NotNull final Set<PsiClassType> thrownTypes) {
|
||||
static List<HighlightInfo> checkExceptionThrownInTry(@NotNull final PsiParameter parameter,
|
||||
@NotNull final Set<PsiClassType> thrownTypes) {
|
||||
final PsiElement declarationScope = parameter.getDeclarationScope();
|
||||
if (!(declarationScope instanceof PsiCatchSection)) return null;
|
||||
|
||||
@@ -1429,8 +1430,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkUnaryOperatorApplicable(@Nullable PsiJavaToken token, @Nullable PsiExpression expression) {
|
||||
if (token != null && expression != null && !TypeConversionUtil.isUnaryOperatorApplicable(token, expression)) {
|
||||
static HighlightInfo checkUnaryOperatorApplicable(@NotNull PsiJavaToken token, @Nullable PsiExpression expression) {
|
||||
if (expression != null && !TypeConversionUtil.isUnaryOperatorApplicable(token, expression)) {
|
||||
PsiType type = expression.getType();
|
||||
if (type == null) return null;
|
||||
String message = JavaErrorMessages.message("unary.operator.not.applicable", token.getText(), JavaHighlightUtil.formatType(type));
|
||||
@@ -1558,7 +1559,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
static HighlightInfo checkUnqualifiedSuperInDefaultMethod(@NotNull LanguageLevel languageLevel,
|
||||
@NotNull PsiReferenceExpression expr,
|
||||
PsiExpression qualifier) {
|
||||
@Nullable PsiExpression qualifier) {
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && qualifier instanceof PsiSuperExpression) {
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class);
|
||||
if (method != null && method.hasModifierProperty(PsiModifier.DEFAULT) && ((PsiSuperExpression)qualifier).getQualifier() == null) {
|
||||
@@ -1571,7 +1572,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isInsideDefaultMethod(PsiMethod method, PsiClass aClass) {
|
||||
private static boolean isInsideDefaultMethod(@NotNull PsiMethod method, @NotNull PsiClass aClass) {
|
||||
while (method != null && method.getContainingClass() != aClass) {
|
||||
method = PsiTreeUtil.getParentOfType(method, PsiMethod.class, true);
|
||||
}
|
||||
@@ -1590,7 +1591,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
final PsiType superType = expr.getType();
|
||||
if (!(superType instanceof PsiClassType)) return false;
|
||||
final PsiClass superClass = ((PsiClassType)superType).resolve();
|
||||
return superClass != null && aClass.equals(superClass) && PsiUtil.getEnclosingStaticElement(expr, PsiTreeUtil.getParentOfType(expr, PsiClass.class)) == null;
|
||||
return aClass.equals(superClass) && PsiUtil.getEnclosingStaticElement(expr, PsiTreeUtil.getParentOfType(expr, PsiClass.class)) == null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1615,12 +1616,12 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
if (refElement.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
String containerName = getContainerName(refElement, result.getSubstitutor());
|
||||
return pair(JavaErrorMessages.message("private.symbol", symbolName, containerName), null);
|
||||
return Pair.pair(JavaErrorMessages.message("private.symbol", symbolName, containerName), null);
|
||||
}
|
||||
|
||||
if (refElement.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
String containerName = getContainerName(refElement, result.getSubstitutor());
|
||||
return pair(JavaErrorMessages.message("protected.symbol", symbolName, containerName), null);
|
||||
return Pair.pair(JavaErrorMessages.message("protected.symbol", symbolName, containerName), null);
|
||||
}
|
||||
|
||||
PsiClass packageLocalClass = HighlightFixUtil.getPackageLocalClassInTheMiddle(ref);
|
||||
@@ -1631,16 +1632,19 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
if (refElement.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || packageLocalClass != null) {
|
||||
String containerName = getContainerName(refElement, result.getSubstitutor());
|
||||
return pair(JavaErrorMessages.message("package.local.symbol", symbolName, containerName), null);
|
||||
return Pair.pair(JavaErrorMessages.message("package.local.symbol", symbolName, containerName), null);
|
||||
}
|
||||
|
||||
String containerName = getContainerName(refElement, result.getSubstitutor());
|
||||
ErrorWithFixes problem = checkModuleAccess(resolved, ref, symbolName, containerName);
|
||||
if (problem != null) return pair(problem.message, problem.fixes);
|
||||
return pair(JavaErrorMessages.message("visibility.access.problem", symbolName, containerName), null);
|
||||
if (problem != null) return Pair.pair(problem.message, problem.fixes);
|
||||
return Pair.pair(JavaErrorMessages.message("visibility.access.problem", symbolName, containerName), null);
|
||||
}
|
||||
|
||||
private static ErrorWithFixes checkModuleAccess(PsiElement target, PsiElement place, String symbolName, String containerName) {
|
||||
private static ErrorWithFixes checkModuleAccess(@NotNull PsiElement target,
|
||||
@NotNull PsiElement place,
|
||||
@Nullable String symbolName,
|
||||
@Nullable String containerName) {
|
||||
ErrorWithFixes error = null;
|
||||
for (JavaModuleSystem moduleSystem : JavaModuleSystem.EP_NAME.getExtensions()) {
|
||||
if (moduleSystem instanceof JavaModuleSystemEx) {
|
||||
@@ -1658,19 +1662,19 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ErrorWithFixes checkAccess(JavaModuleSystemEx system, PsiElement target, PsiElement place) {
|
||||
private static ErrorWithFixes checkAccess(@NotNull JavaModuleSystemEx system, @NotNull PsiElement target, @NotNull PsiElement place) {
|
||||
if (target instanceof PsiClass) return system.checkAccess((PsiClass)target, place);
|
||||
if (target instanceof PsiPackage) return system.checkAccess(((PsiPackage)target).getQualifiedName(), null, place);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isAccessible(JavaModuleSystem system, PsiElement target, PsiElement place) {
|
||||
private static boolean isAccessible(@NotNull JavaModuleSystem system, @NotNull PsiElement target, @NotNull PsiElement place) {
|
||||
if (target instanceof PsiClass) return system.isAccessible((PsiClass)target, place);
|
||||
if (target instanceof PsiPackage) return system.isAccessible(((PsiPackage)target).getQualifiedName(), null, place);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static PsiElement getContainer(PsiModifierListOwner refElement) {
|
||||
private static PsiElement getContainer(@NotNull PsiModifierListOwner refElement) {
|
||||
for (ContainerProvider provider : ContainerProvider.EP_NAME.getExtensions()) {
|
||||
final PsiElement container = provider.getContainer(refElement);
|
||||
if (container != null) return container;
|
||||
@@ -1678,7 +1682,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return refElement.getParent();
|
||||
}
|
||||
|
||||
private static String getContainerName(PsiModifierListOwner refElement, final PsiSubstitutor substitutor) {
|
||||
private static String getContainerName(@NotNull PsiModifierListOwner refElement, @NotNull PsiSubstitutor substitutor) {
|
||||
final PsiElement container = getContainer(refElement);
|
||||
return container == null ? "?" : HighlightMessageUtil.getSymbolName(container, substitutor);
|
||||
}
|
||||
@@ -1750,7 +1754,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Collection<HighlightInfo> checkArrayInitializer(final PsiExpression initializer, PsiType type) {
|
||||
static Collection<HighlightInfo> checkArrayInitializer(@NotNull PsiExpression initializer, @Nullable PsiType type) {
|
||||
if (!(initializer instanceof PsiArrayInitializerExpression)) return null;
|
||||
if (!(type instanceof PsiArrayType)) return null;
|
||||
|
||||
@@ -1760,7 +1764,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
boolean arrayTypeFixChecked = false;
|
||||
VariableArrayTypeFix fix = null;
|
||||
|
||||
final Collection<HighlightInfo> result = ContainerUtil.newArrayList();
|
||||
final Collection<HighlightInfo> result = new ArrayList<>();
|
||||
final PsiExpression[] initializers = arrayInitializer.getInitializers();
|
||||
for (PsiExpression expression : initializers) {
|
||||
final HighlightInfo info = checkArrayInitializerCompatibleTypes(expression, componentType);
|
||||
@@ -1781,7 +1785,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkArrayInitializerCompatibleTypes(@NotNull PsiExpression initializer, final PsiType componentType) {
|
||||
private static HighlightInfo checkArrayInitializerCompatibleTypes(@NotNull PsiExpression initializer, @NotNull PsiType componentType) {
|
||||
PsiType initializerType = initializer.getType();
|
||||
if (initializerType == null) {
|
||||
String description = JavaErrorMessages.message("illegal.initializer", JavaHighlightUtil.formatType(componentType));
|
||||
@@ -1818,8 +1822,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (parent instanceof PsiVariable) {
|
||||
PsiVariable variable = (PsiVariable)parent;
|
||||
PsiTypeElement typeElement = variable.getTypeElement();
|
||||
boolean disabledForInferredType = typeElement == null || !typeElement.isInferredType();
|
||||
if (disabledForInferredType && variable.getType() instanceof PsiArrayType) return null;
|
||||
boolean isInferredType = typeElement != null && typeElement.isInferredType();
|
||||
if (!isInferredType && variable.getType() instanceof PsiArrayType) return null;
|
||||
}
|
||||
else if (parent instanceof PsiNewExpression || parent instanceof PsiArrayInitializerExpression) {
|
||||
return null;
|
||||
@@ -1930,7 +1934,9 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
public static Boolean isIllegalForwardReferenceToField(@NotNull PsiReferenceExpression expression, @NotNull PsiField referencedField, boolean acceptQualified) {
|
||||
public static Boolean isIllegalForwardReferenceToField(@NotNull PsiReferenceExpression expression,
|
||||
@NotNull PsiField referencedField,
|
||||
boolean acceptQualified) {
|
||||
PsiClass containingClass = referencedField.getContainingClass();
|
||||
if (containingClass == null) return null;
|
||||
if (expression.getContainingFile() != referencedField.getContainingFile()) return null;
|
||||
@@ -1956,7 +1962,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
* @return field that has initializer with this element as subexpression or null if not found
|
||||
*/
|
||||
@Nullable
|
||||
static PsiField findEnclosingFieldInitializer(@Nullable PsiElement element) {
|
||||
static PsiField findEnclosingFieldInitializer(@NotNull PsiElement entry) {
|
||||
PsiElement element = entry;
|
||||
while (element != null) {
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiField) {
|
||||
@@ -1971,7 +1978,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiClassInitializer findParentClassInitializer(@Nullable PsiElement element) {
|
||||
private static PsiClassInitializer findParentClassInitializer(@NotNull PsiElement root) {
|
||||
PsiElement element = root;
|
||||
while (element != null) {
|
||||
if (element instanceof PsiClassInitializer) return (PsiClassInitializer)element;
|
||||
if (element instanceof PsiClass || element instanceof PsiMethod) return null;
|
||||
@@ -1982,8 +1990,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkIllegalType(@Nullable PsiTypeElement typeElement) {
|
||||
if (typeElement == null || typeElement.getParent() instanceof PsiTypeElement) return null;
|
||||
static HighlightInfo checkIllegalType(@NotNull PsiTypeElement typeElement) {
|
||||
if (typeElement.getParent() instanceof PsiTypeElement) return null;
|
||||
|
||||
if (PsiUtil.isInsideJavadocComment(typeElement)) return null;
|
||||
|
||||
@@ -2031,7 +2039,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMemberReferencedBeforeConstructorCalled(@NotNull PsiElement expression,
|
||||
PsiElement resolved,
|
||||
@Nullable PsiElement resolved,
|
||||
@NotNull PsiFile containingFile) {
|
||||
PsiClass referencedClass;
|
||||
String resolvedName;
|
||||
@@ -2136,7 +2144,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
@Nullable
|
||||
private static HighlightInfo checkReferenceToOurInstanceInsideThisOrSuper(@NotNull final PsiElement expression,
|
||||
@NotNull PsiClass referencedClass,
|
||||
final String resolvedName,
|
||||
@Nullable String resolvedName,
|
||||
@NotNull PsiFile containingFile) {
|
||||
if (PsiTreeUtil.getParentOfType(expression, PsiReferenceParameterList.class, true, PsiExpression.class) != null) return null;
|
||||
PsiElement element = expression.getParent();
|
||||
@@ -2212,7 +2220,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfo createMemberReferencedError(final String resolvedName, @NotNull TextRange textRange) {
|
||||
private static HighlightInfo createMemberReferencedError(@NotNull String resolvedName, @NotNull TextRange textRange) {
|
||||
String description = JavaErrorMessages.message("member.referenced.before.constructor.called", resolvedName);
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
}
|
||||
@@ -2257,7 +2265,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return element != null;
|
||||
}
|
||||
|
||||
private static boolean thisOrSuperReference(@Nullable PsiExpression qualifierExpression, PsiClass aClass) {
|
||||
private static boolean thisOrSuperReference(@Nullable PsiExpression qualifierExpression, @NotNull PsiClass aClass) {
|
||||
if (qualifierExpression == null) return true;
|
||||
PsiJavaCodeReferenceElement qualifier;
|
||||
if (qualifierExpression instanceof PsiThisExpression) {
|
||||
@@ -2394,21 +2402,21 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return result.isEmpty() ? null : result;
|
||||
}
|
||||
|
||||
private static boolean checkMultipleTypes(final PsiClass catchClass, @NotNull final List<PsiType> upperCatchTypes) {
|
||||
private static boolean checkMultipleTypes(@NotNull PsiClass catchClass, @NotNull final List<PsiType> upperCatchTypes) {
|
||||
for (int i = upperCatchTypes.size() - 1; i >= 0; i--) {
|
||||
if (checkSingleType(catchClass, upperCatchTypes.get(i))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean checkSingleType(final PsiClass catchClass, final PsiType upperCatchType) {
|
||||
private static boolean checkSingleType(@NotNull PsiClass catchClass, @Nullable PsiType upperCatchType) {
|
||||
final PsiClass upperCatchClass = PsiUtil.resolveClassInType(upperCatchType);
|
||||
return upperCatchClass != null && InheritanceUtil.isInheritorOrSelf(catchClass, upperCatchClass, true);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkTernaryOperatorConditionIsBoolean(@NotNull PsiExpression expression, PsiType type) {
|
||||
static HighlightInfo checkTernaryOperatorConditionIsBoolean(@NotNull PsiExpression expression, @Nullable PsiType type) {
|
||||
if (expression.getParent() instanceof PsiConditionalExpression &&
|
||||
((PsiConditionalExpression)expression.getParent()).getCondition() == expression && !TypeConversionUtil.isBooleanType(type)) {
|
||||
return createMustBeBooleanInfo(expression, type);
|
||||
@@ -2472,7 +2480,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkConditionalExpressionBranchTypesMatch(@NotNull final PsiExpression expression, PsiType type) {
|
||||
static HighlightInfo checkConditionalExpressionBranchTypesMatch(@NotNull final PsiExpression expression, @Nullable PsiType type) {
|
||||
PsiElement parent = expression.getParent();
|
||||
if (!(parent instanceof PsiConditionalExpression)) {
|
||||
return null;
|
||||
@@ -2530,6 +2538,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
.navigationShift(navigationShift).create();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Trinity<PsiType, PsiTypeParameter[], PsiSubstitutor> typeData(PsiType type) {
|
||||
PsiTypeParameter[] parameters = PsiTypeParameter.EMPTY_ARRAY;
|
||||
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
|
||||
@@ -2548,14 +2557,16 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return Trinity.create(type, parameters, substitutor);
|
||||
}
|
||||
|
||||
private static String redIfNotMatch(PsiType type, boolean matches) {
|
||||
@NotNull
|
||||
private static String redIfNotMatch(@Nullable PsiType type, boolean matches) {
|
||||
if (matches) return getFQName(type, false);
|
||||
String color = UIUtil.isUnderDarcula() ? "FF6B68" : "red";
|
||||
return "<font color='" + color +"'><b>" + getFQName(type, true) + "</b></font>";
|
||||
}
|
||||
|
||||
private static String getFQName(PsiType type, boolean longName) {
|
||||
return type != null ? XmlStringUtil.escapeString(longName ? type.getInternalCanonicalText() : type.getPresentableText()) : "";
|
||||
@NotNull
|
||||
private static String getFQName(@Nullable PsiType type, boolean longName) {
|
||||
return type == null ? "" : XmlStringUtil.escapeString(longName ? type.getInternalCanonicalText() : type.getPresentableText());
|
||||
}
|
||||
|
||||
|
||||
@@ -2573,15 +2584,14 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
String description = JavaErrorMessages.message("single.import.class.conflict", formatClass(importedClass));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(description).create();
|
||||
}
|
||||
importedClasses.put(name, pair(null, (PsiClass)element));
|
||||
importedClasses.put(name, Pair.pair(null, (PsiClass)element));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkMustBeThrowable(@Nullable PsiType type, @NotNull PsiElement context, boolean addCastIntention) {
|
||||
if (type == null) return null;
|
||||
static HighlightInfo checkMustBeThrowable(@NotNull PsiType type, @NotNull PsiElement context, boolean addCastIntention) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
|
||||
PsiClassType throwable = factory.createTypeByFQClassName("java.lang.Throwable", context.getResolveScope());
|
||||
if (!TypeConversionUtil.isAssignable(throwable, type)) {
|
||||
@@ -2603,8 +2613,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfo checkMustBeThrowable(@Nullable PsiClass aClass, @NotNull PsiElement context) {
|
||||
if (aClass == null) return null;
|
||||
private static HighlightInfo checkMustBeThrowable(@NotNull PsiClass aClass, @NotNull PsiElement context) {
|
||||
PsiClassType type = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass);
|
||||
return checkMustBeThrowable(type, context, false);
|
||||
}
|
||||
@@ -2726,7 +2735,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiElement findPackagePrefix(PsiJavaCodeReferenceElement ref) {
|
||||
@NotNull
|
||||
private static PsiElement findPackagePrefix(@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
PsiElement candidate = ref;
|
||||
while (candidate instanceof PsiJavaCodeReferenceElement) {
|
||||
if (((PsiJavaCodeReferenceElement)candidate).resolve() instanceof PsiPackage) return candidate;
|
||||
@@ -2822,7 +2832,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkClassReferenceAfterQualifier(@NotNull final PsiReferenceExpression expression, final PsiElement resolved) {
|
||||
static HighlightInfo checkClassReferenceAfterQualifier(@NotNull final PsiReferenceExpression expression, @Nullable PsiElement resolved) {
|
||||
if (!(resolved instanceof PsiClass)) return null;
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
if (qualifier == null) return null;
|
||||
@@ -2903,10 +2913,12 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
REFS_AS_RESOURCE(LanguageLevel.JDK_1_9, "feature.try.with.resources.refs"),
|
||||
MODULES(LanguageLevel.JDK_1_9, "feature.modules");
|
||||
|
||||
@NotNull
|
||||
private final LanguageLevel level;
|
||||
@NotNull
|
||||
private final String key;
|
||||
|
||||
Feature(LanguageLevel level, @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String key) {
|
||||
Feature(@NotNull LanguageLevel level, @NotNull @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String key) {
|
||||
this.level = level;
|
||||
this.key = key;
|
||||
}
|
||||
@@ -2928,7 +2940,10 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getUnsupportedFeatureMessage(PsiElement element, Feature feature, LanguageLevel level, PsiFile file) {
|
||||
private static String getUnsupportedFeatureMessage(@NotNull PsiElement element,
|
||||
@NotNull Feature feature,
|
||||
@NotNull LanguageLevel level,
|
||||
@NotNull PsiFile file) {
|
||||
String name = JavaErrorMessages.message(feature.key);
|
||||
String version = JavaSdkVersion.fromLanguageLevel(level).getDescription();
|
||||
String message = JavaErrorMessages.message("insufficient.language.level", name, version);
|
||||
@@ -2950,16 +2965,4 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param variable variable to create change type fixes for
|
||||
* @param itemType a desired variable type
|
||||
* @return a list of created fix actions
|
||||
* @deprecated Will be removed in 2018.1. Use {@link HighlightFixUtil#getChangeVariableTypeFixes(PsiVariable, PsiType)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public static List<IntentionAction> getChangeVariableTypeFixes(@NotNull PsiVariable variable, PsiType itemType) {
|
||||
return HighlightFixUtil.getChangeVariableTypeFixes(variable, itemType);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -33,6 +33,7 @@ import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
@@ -42,8 +43,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.notNull;
|
||||
|
||||
public class HighlightVisitorImpl extends JavaElementVisitor implements HighlightVisitor {
|
||||
private final PsiResolveHelper myResolveHelper;
|
||||
|
||||
@@ -196,7 +195,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder = holder;
|
||||
myFile = file;
|
||||
myLanguageLevel = PsiUtil.getLanguageLevel(file);
|
||||
myJavaSdkVersion = notNull(JavaVersionService.getInstance().getJavaSdkVersion(file), JavaSdkVersion.fromLanguageLevel(myLanguageLevel));
|
||||
myJavaSdkVersion = ObjectUtils
|
||||
.notNull(JavaVersionService.getInstance().getJavaSdkVersion(file), JavaSdkVersion.fromLanguageLevel(myLanguageLevel));
|
||||
myJavaModule = myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_9) ? JavaModuleGraphUtil.findDescriptorByElement(file) : null;
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkConditionalExpressionBranchTypesMatch(expression, type));
|
||||
if (!myHolder.hasErrorResults()
|
||||
&& parent instanceof PsiThrowStatement
|
||||
&& ((PsiThrowStatement)parent).getException() == expression) {
|
||||
&& ((PsiThrowStatement)parent).getException() == expression && type != null) {
|
||||
myHolder.add(HighlightUtil.checkMustBeThrowable(type, expression, true));
|
||||
}
|
||||
|
||||
@@ -782,9 +782,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
PsiModifierList psiModifierList = (PsiModifierList)parent;
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkNotAllowedModifier(keyword, psiModifierList));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIllegalModifierCombination(keyword, psiModifierList));
|
||||
if (PsiModifier.ABSTRACT.equals(text) && psiModifierList.getParent() instanceof PsiMethod) {
|
||||
PsiElement pParent = psiModifierList.getParent();
|
||||
if (PsiModifier.ABSTRACT.equals(text) && pParent instanceof PsiMethod) {
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
myHolder.add(HighlightMethodUtil.checkAbstractMethodInConcreteClass((PsiMethod)psiModifierList.getParent(), keyword));
|
||||
myHolder.add(HighlightMethodUtil.checkAbstractMethodInConcreteClass((PsiMethod)pParent, keyword));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -922,12 +923,13 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
PsiMethod method = (PsiMethod)parent;
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCanHaveBody(method, myLanguageLevel));
|
||||
MethodSignatureBackedByPsiMethod methodSignature = MethodSignatureBackedByPsiMethod.create(method, PsiSubstitutor.EMPTY);
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (!method.isConstructor()) {
|
||||
try {
|
||||
List<HierarchicalMethodSignature> superMethodSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
|
||||
if (!superMethodSignatures.isEmpty()) {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodIncompatibleReturnType(methodSignature, superMethodSignatures, true));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodIncompatibleThrows(methodSignature, superMethodSignatures, true, method.getContainingClass()));
|
||||
if (aClass != null && !myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodIncompatibleThrows(methodSignature, superMethodSignatures, true, aClass));
|
||||
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodWeakerPrivileges(methodSignature, superMethodSignatures, true, myFile));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodOverridesFinal(methodSignature, superMethodSignatures));
|
||||
@@ -936,12 +938,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
catch (IndexNotReadyException ignored) { }
|
||||
}
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodMustHaveBody(method, aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorCallsBaseClassConstructor(method, myRefCountHolder, myResolveHelper));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkStaticMethodOverride(method,myFile));
|
||||
if (!myHolder.hasErrorResults() && aClass != null &&
|
||||
myOverrideEquivalentMethodsVisitedClasses.add(aClass)) {
|
||||
if (!myHolder.hasErrorResults() && aClass != null && myOverrideEquivalentMethodsVisitedClasses.add(aClass)) {
|
||||
myHolder.addAll(GenericsHighlightUtil.checkOverrideEquivalentMethods(aClass));
|
||||
}
|
||||
}
|
||||
@@ -991,7 +991,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkQualifiedNew(expression, type, aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCreateInnerClassFromStaticContext(expression, type, aClass));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkTypeParameterInstantiation(expression));
|
||||
if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkInstantiationOfAbstractClass(aClass, expression));
|
||||
if (aClass != null && !myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkInstantiationOfAbstractClass(aClass, expression));
|
||||
try {
|
||||
if (!myHolder.hasErrorResults()) HighlightMethodUtil.checkNewExpression(expression, type, myHolder, myJavaSdkVersion);
|
||||
}
|
||||
@@ -1379,8 +1379,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null) {
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
boolean notFunctional = !LambdaUtil.isFunctionalType(functionalInterfaceType);
|
||||
if (notFunctional) {
|
||||
boolean isFunctional = LambdaUtil.isFunctionalType(functionalInterfaceType);
|
||||
if (!isFunctional) {
|
||||
String description = functionalInterfaceType.getPresentableText() + " is not a functional interface";
|
||||
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create());
|
||||
}
|
||||
@@ -1471,7 +1471,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
|
||||
if (description != null) {
|
||||
PsiElement referenceNameElement = notNull(expression.getReferenceNameElement(), expression);
|
||||
PsiElement referenceNameElement = ObjectUtils.notNull(expression.getReferenceNameElement(), expression);
|
||||
HighlightInfoType type = results.length == 0 ? HighlightInfoType.WRONG_REF : HighlightInfoType.ERROR;
|
||||
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(type).descriptionAndTooltip(description).range(referenceNameElement).create();
|
||||
myHolder.add(highlightInfo);
|
||||
|
||||
+2
-1
@@ -22,13 +22,14 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiImportStaticStatement;
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ImportsHighlightUtil {
|
||||
public static final Key<Set<String>> IMPORTS_FROM_TEMPLATE = Key.create("IMPORT_FROM_FILE_TEMPLATE");
|
||||
|
||||
static HighlightInfo checkStaticOnDemandImportResolvesToClass(PsiImportStaticStatement statement) {
|
||||
static HighlightInfo checkStaticOnDemandImportResolvesToClass(@NotNull PsiImportStaticStatement statement) {
|
||||
if (statement.isOnDemand() && statement.resolveTargetClass() == null) {
|
||||
PsiJavaCodeReferenceElement ref = statement.getImportReference();
|
||||
if (ref != null) {
|
||||
|
||||
+14
-11
@@ -21,11 +21,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaHighlightUtil {
|
||||
@@ -33,14 +35,13 @@ public class JavaHighlightUtil {
|
||||
return isSerializable(aClass, "java.io.Serializable");
|
||||
}
|
||||
|
||||
public static boolean isSerializable(@NotNull PsiClass aClass,
|
||||
String serializableClassName) {
|
||||
public static boolean isSerializable(@NotNull PsiClass aClass, @NotNull String serializableClassName) {
|
||||
Project project = aClass.getManager().getProject();
|
||||
PsiClass serializableClass = JavaPsiFacade.getInstance(project).findClass(serializableClassName, aClass.getResolveScope());
|
||||
return serializableClass != null && aClass.isInheritor(serializableClass, true);
|
||||
}
|
||||
|
||||
public static boolean isSerializationRelatedMethod(PsiMethod method, PsiClass containingClass) {
|
||||
public static boolean isSerializationRelatedMethod(@NotNull PsiMethod method, @Nullable PsiClass containingClass) {
|
||||
if (containingClass == null) return false;
|
||||
if (method.isConstructor()) {
|
||||
if (isSerializable(containingClass, "java.io.Externalizable") &&
|
||||
@@ -123,7 +124,7 @@ public class JavaHighlightUtil {
|
||||
PsiFormatUtilBase.SHOW_TYPE);
|
||||
}
|
||||
|
||||
public static boolean isSuperOrThisCall(PsiStatement statement, boolean testForSuper, boolean testForThis) {
|
||||
public static boolean isSuperOrThisCall(@NotNull PsiStatement statement, boolean testForSuper, boolean testForThis) {
|
||||
if (!(statement instanceof PsiExpressionStatement)) return false;
|
||||
PsiExpression expression = ((PsiExpressionStatement)statement).getExpression();
|
||||
if (!(expression instanceof PsiMethodCallExpression)) return false;
|
||||
@@ -143,16 +144,17 @@ public class JavaHighlightUtil {
|
||||
* this (...) at the beginning of the constructor body
|
||||
* @return referring constructor
|
||||
*/
|
||||
@Nullable public static List<PsiMethod> getChainedConstructors(PsiMethod constructor) {
|
||||
@NotNull
|
||||
public static List<PsiMethod> getChainedConstructors(@NotNull PsiMethod constructor) {
|
||||
final ConstructorVisitorInfo info = new ConstructorVisitorInfo();
|
||||
visitConstructorChain(constructor, info);
|
||||
if (info.visitedConstructors != null) info.visitedConstructors.remove(constructor);
|
||||
return info.visitedConstructors;
|
||||
return ObjectUtils.notNull(info.visitedConstructors, Collections.emptyList());
|
||||
}
|
||||
|
||||
static void visitConstructorChain(PsiMethod constructor, @NotNull ConstructorVisitorInfo info) {
|
||||
static void visitConstructorChain(@NotNull PsiMethod entry, @NotNull ConstructorVisitorInfo info) {
|
||||
PsiMethod constructor = entry;
|
||||
while (true) {
|
||||
if (constructor == null) return;
|
||||
final PsiCodeBlock body = constructor.getBody();
|
||||
if (body == null) return;
|
||||
final PsiStatement[] statements = body.getStatements();
|
||||
@@ -182,7 +184,7 @@ public class JavaHighlightUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String checkPsiTypeUseInContext(@Nullable PsiType type, @NotNull PsiElement context) {
|
||||
public static String checkPsiTypeUseInContext(@NotNull PsiType type, @NotNull PsiElement context) {
|
||||
if (type instanceof PsiPrimitiveType) return null;
|
||||
if (type instanceof PsiArrayType) return checkPsiTypeUseInContext(((PsiArrayType) type).getComponentType(), context);
|
||||
if (PsiUtil.resolveClassInType(type) != null) return null;
|
||||
@@ -190,6 +192,7 @@ public class JavaHighlightUtil {
|
||||
return "Invalid Java type";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String checkClassType(@NotNull PsiClassType type, @NotNull PsiElement context) {
|
||||
String className = PsiNameHelper.getQualifiedClassName(type.getCanonicalText(false), true);
|
||||
if (classExists(context, className)) {
|
||||
@@ -198,12 +201,12 @@ public class JavaHighlightUtil {
|
||||
return "Invalid Java type";
|
||||
}
|
||||
|
||||
private static boolean classExists(@NotNull PsiElement context, String className) {
|
||||
private static boolean classExists(@NotNull PsiElement context, @NotNull String className) {
|
||||
return JavaPsiFacade.getInstance(context.getProject()).findClass(className, GlobalSearchScope.allScope(context.getProject())) != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getClassInaccessibleMessage(@NotNull PsiElement context, String className) {
|
||||
private static String getClassInaccessibleMessage(@NotNull PsiElement context, @NotNull String className) {
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(context);
|
||||
return "Class '" + className + "' is not accessible " + (module == null ? "here" : "from module '" + module.getName() + "'");
|
||||
}
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ class CanBeFinalAnnotator extends RefGraphAnnotatorEx {
|
||||
}
|
||||
}
|
||||
List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
|
||||
if (redirectedConstructors == null || redirectedConstructors.isEmpty()) {
|
||||
if (redirectedConstructors.isEmpty()) {
|
||||
List<PsiVariable> ssaVariables = ControlFlowUtil.getSSAVariables(flow);
|
||||
ArrayList<PsiVariable> good = new ArrayList<>(ssaVariables);
|
||||
good.addAll(instanceInitializerInitializedFields);
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ public class DefUseInspectionBase extends AbstractBaseJavaLocalInspectionTool {
|
||||
return false;
|
||||
}
|
||||
for (PsiMethod constructor : constructors) {
|
||||
if (JavaHighlightUtil.getChainedConstructors(constructor) != null) continue;
|
||||
if (!JavaHighlightUtil.getChainedConstructors(constructor).isEmpty()) continue;
|
||||
final PsiCodeBlock body = constructor.getBody();
|
||||
if (body == null || !HighlightControlFlowUtil.variableDefinitelyAssignedIn(field, body)) {
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -321,7 +321,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
PsiParameter[] newParameters = constructor.getParameterList().getParameters();
|
||||
if (newParameters == parameters) return false; //user must have canceled dialog
|
||||
// do not introduce assignment in chained constructor
|
||||
if (JavaHighlightUtil.getChainedConstructors(constructor) == null) {
|
||||
if (JavaHighlightUtil.getChainedConstructors(constructor).isEmpty()) {
|
||||
final SmartPointerManager manager = SmartPointerManager.getInstance(project);
|
||||
boolean created = false;
|
||||
for (PsiField field : fields.keySet()) {
|
||||
|
||||
+1
-6
@@ -87,12 +87,7 @@ public class MoveInitializerToConstructorAction extends BaseMoveInitializerToMet
|
||||
@NotNull
|
||||
private static Collection<PsiMethod> removeChainedConstructors(@NotNull Collection<PsiMethod> constructors) {
|
||||
final List<PsiMethod> result = new ArrayList<>(constructors);
|
||||
for (Iterator<PsiMethod> iterator = result.iterator(); iterator.hasNext(); ) {
|
||||
final PsiMethod constructor = iterator.next();
|
||||
if (JavaHighlightUtil.getChainedConstructors(constructor) != null) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
result.removeIf(constructor -> !JavaHighlightUtil.getChainedConstructors(constructor).isEmpty());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -292,8 +292,10 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
}
|
||||
|
||||
if (toCatchExceptions) {
|
||||
PsiStatement statement;
|
||||
if (!(ref instanceof PsiReferenceExpression &&
|
||||
JavaHighlightUtil.isSuperOrThisCall(PsiTreeUtil.getParentOfType(ref, PsiStatement.class), true, false))) {
|
||||
(statement = PsiTreeUtil.getParentOfType(ref, PsiStatement.class)) != null &&
|
||||
JavaHighlightUtil.isSuperOrThisCall(statement, true, false))) {
|
||||
if (needToCatchExceptions(changeInfo, caller)) {
|
||||
PsiClassType[] newExceptions =
|
||||
callee != null ? getCalleeChangedExceptionInfo(callee) : getPrimaryChangedExceptionInfo(changeInfo);
|
||||
|
||||
+1
-7
@@ -35,7 +35,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ClassInitializerInspection extends BaseInspection {
|
||||
|
||||
@@ -140,12 +139,7 @@ public class ClassInitializerInspection extends BaseInspection {
|
||||
|
||||
@NotNull
|
||||
private static Collection<PsiMethod> removeChainedConstructors(@NotNull Collection<PsiMethod> constructors) {
|
||||
for (final Iterator<PsiMethod> iterator = constructors.iterator(); iterator.hasNext(); ) {
|
||||
final PsiMethod constructor = iterator.next();
|
||||
if (JavaHighlightUtil.getChainedConstructors(constructor) != null) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
constructors.removeIf(constructor -> !JavaHighlightUtil.getChainedConstructors(constructor).isEmpty());
|
||||
return constructors;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1989,7 +1989,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
);
|
||||
}
|
||||
|
||||
private static void checkTypeDefinition(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
|
||||
private static void checkTypeDefinition(AnnotationHolder holder, @NotNull GrTypeDefinition typeDefinition) {
|
||||
final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance();
|
||||
if (typeDefinition.isAnonymous()) {
|
||||
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) {
|
||||
@@ -2034,7 +2034,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
}
|
||||
|
||||
private static void checkCyclicInheritance(AnnotationHolder holder,
|
||||
GrTypeDefinition typeDefinition) {
|
||||
@NotNull GrTypeDefinition typeDefinition) {
|
||||
final PsiClass psiClass = HighlightClassUtil.getCircularClass(typeDefinition, new HashSet<>());
|
||||
if (psiClass != null) {
|
||||
String qname = psiClass.getQualifiedName();
|
||||
|
||||
Reference in New Issue
Block a user