GitOrigin-RevId: b9620e6f5df659a1547053feea885e2b1873731f
This commit is contained in:
Alexey Kudravtsev
2021-12-29 15:40:56 +01:00
committed by intellij-monorepo-bot
parent 0725eb0eaa
commit 065798281a
20 changed files with 582 additions and 556 deletions

View File

@@ -2,7 +2,7 @@
package com.intellij.execution.application;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.Location;
import com.intellij.execution.actions.ConfigurationContext;
@@ -46,7 +46,7 @@ public abstract class AbstractApplicationConfigurationProducer<T extends Applica
return false;
}
PsiFile containingFile = aClass.getContainingFile();
if (HighlightClassUtil.isJavaHashBangScript(containingFile)) {
if (JavaHighlightUtil.isJavaHashBangScript(containingFile)) {
return false;
}
PsiMethod method = PsiMethodUtil.findMainInClass(aClass);

View File

@@ -1,7 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.application;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.execution.lineMarker.ExecutorAction;
import com.intellij.execution.lineMarker.RunLineMarkerContributor;
import com.intellij.icons.AllIcons;
@@ -27,7 +27,7 @@ public class ApplicationRunLineMarkerProvider extends RunLineMarkerContributor {
PsiFile containingFile = element.getContainingFile();
if (element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass)element) != null ||
element instanceof PsiMethod && "main".equals(((PsiMethod)element).getName()) && PsiMethodUtil.isMainMethod((PsiMethod)element)) {
if (HighlightClassUtil.isJavaHashBangScript(containingFile)) {
if (JavaHighlightUtil.isJavaHashBangScript(containingFile)) {
return null;
}

View File

@@ -63,8 +63,8 @@ public final class AnnotationsHighlightUtil {
}
if (method == null) {
if (pair.getName() != null) {
final String description = JavaErrorBundle.message("annotation.unknown.method", ref.getCanonicalText());
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF)
String description = JavaErrorBundle.message("annotation.unknown.method", ref.getCanonicalText());
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF)
.range(ref.getElement(), ref.getRangeInElement())
.descriptionAndTooltip(description)
.create();
@@ -74,7 +74,7 @@ public final class AnnotationsHighlightUtil {
else {
String description = JavaErrorBundle.message("annotation.missing.method", ref.getCanonicalText());
PsiElement element = ref.getElement();
final HighlightInfo highlightInfo =
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
for (IntentionAction action : QUICK_FIX_FACTORY.createAddAnnotationAttributeNameFixes(pair)) {
QuickFixAction.registerQuickFixAction(highlightInfo, action);
@@ -124,7 +124,7 @@ public final class AnnotationsHighlightUtil {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
}
}
final PsiAnnotationMethod annotationMethod = ObjectUtils.tryCast(method, PsiAnnotationMethod.class);
PsiAnnotationMethod annotationMethod = ObjectUtils.tryCast(method, PsiAnnotationMethod.class);
if (annotationMethod == null) return null;
boolean fromDefaultValue = PsiTreeUtil.isAncestor(annotationMethod.getDefaultValue(), value, false);
if (value instanceof PsiAnnotation) {
@@ -186,7 +186,7 @@ public final class AnnotationsHighlightUtil {
PsiExpression expr = (PsiExpression)value;
PsiType type = expr.getType();
final PsiClass psiClass = PsiUtil.resolveClassInType(type);
PsiClass psiClass = PsiUtil.resolveClassInType(type);
if (psiClass != null && psiClass.isEnum() && !(expr instanceof PsiReferenceExpression && ((PsiReferenceExpression)expr).resolve() instanceof PsiEnumConstant)) {
String description = JavaErrorBundle.message("annotation.non.enum.constant.attribute.value");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
@@ -307,7 +307,7 @@ public final class AnnotationsHighlightUtil {
Set<String> names = new HashSet<>();
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for (PsiNameValuePair attribute : attributes) {
final String name = attribute.getName();
String name = attribute.getName();
names.add(Objects.requireNonNullElse(name, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME));
}
@@ -345,7 +345,7 @@ public final class AnnotationsHighlightUtil {
}
static HighlightInfo checkConstantExpression(@NotNull PsiExpression expression) {
final PsiElement parent = expression.getParent();
PsiElement parent = expression.getParent();
if (PsiUtil.isAnnotationMethod(parent) || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue) {
if (!PsiUtil.isConstantExpression(expression)) {
String description = JavaErrorBundle.message("annotation.non.constant.attribute.value");
@@ -428,7 +428,7 @@ public final class AnnotationsHighlightUtil {
return annotationError(annotation, message);
}
if (typeElement.isInferredType()) {
final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(annotation)
.descriptionAndTooltip(JavaErrorBundle.message("annotation.not.allowed.var"))
.create();
@@ -459,10 +459,10 @@ public final class AnnotationsHighlightUtil {
}
@Nullable
private static HighlightInfo annotationError(@NotNull final PsiAnnotation annotation,
@NotNull final @NlsContexts.DetailedDescription String message,
@NotNull final IntentionAction fix) {
final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
private static HighlightInfo annotationError(@NotNull PsiAnnotation annotation,
@NotNull @NlsContexts.DetailedDescription String message,
@NotNull IntentionAction fix) {
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(annotation)
.descriptionAndTooltip(message)
.create();
@@ -473,16 +473,16 @@ public final class AnnotationsHighlightUtil {
@Nullable
private static HighlightInfo checkReferenceTarget(@NotNull PsiAnnotation annotation, @Nullable PsiJavaCodeReferenceElement ref) {
if (ref == null) return null;
final PsiElement refTarget = ref.resolve();
PsiElement refTarget = ref.resolve();
if (refTarget == null) return null;
if (!(refTarget instanceof PsiClass)) {
return annotationError(annotation, JavaErrorBundle.message("annotation.not.allowed.ref"));
}
final PsiElement parent = ref.getParent();
PsiElement parent = ref.getParent();
if (parent instanceof PsiJavaCodeReferenceElement) {
final PsiElement qualified = ((PsiJavaCodeReferenceElement)parent).resolve();
PsiElement qualified = ((PsiJavaCodeReferenceElement)parent).resolve();
if (qualified instanceof PsiMember && ((PsiMember)qualified).hasModifierProperty(PsiModifier.STATIC)) {
return annotationError(annotation,
JavaErrorBundle.message("annotation.not.allowed.static"),
@@ -528,13 +528,13 @@ public final class AnnotationsHighlightUtil {
private static boolean cyclicDependencies(@NotNull PsiClass aClass,
@Nullable PsiType type,
@NotNull Set<? super PsiClass> checked) {
final PsiClass resolvedClass = PsiUtil.resolveClassInType(type);
PsiClass resolvedClass = PsiUtil.resolveClassInType(type);
if (resolvedClass != null && resolvedClass.isAnnotationType()) {
if (aClass == resolvedClass) {
return true;
}
if (!checked.add(resolvedClass) || !BaseIntentionAction.canModify(resolvedClass)) return false;
final PsiMethod[] methods = resolvedClass.getMethods();
PsiMethod[] methods = resolvedClass.getMethods();
for (PsiMethod method : methods) {
if (cyclicDependencies(aClass, method.getReturnType(), checked)) return true;
}
@@ -543,13 +543,13 @@ public final class AnnotationsHighlightUtil {
}
static HighlightInfo checkClashesWithSuperMethods(@NotNull PsiAnnotationMethod psiMethod) {
final PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
if (nameIdentifier != null) {
final PsiMethod[] methods = psiMethod.findDeepestSuperMethods();
PsiMethod[] methods = psiMethod.findDeepestSuperMethods();
for (PsiMethod method : methods) {
final PsiClass containingClass = method.getContainingClass();
PsiClass containingClass = method.getContainingClass();
if (containingClass != null) {
final String qualifiedName = containingClass.getQualifiedName();
String qualifiedName = containingClass.getQualifiedName();
if (CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName) || CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION.equals(qualifiedName)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(nameIdentifier).descriptionAndTooltip(
JavaErrorBundle.message("error.interface.member.clashes", JavaHighlightUtil.formatMethod(method),
@@ -635,11 +635,11 @@ public final class AnnotationsHighlightUtil {
static HighlightInfo checkFunctionalInterface(@NotNull PsiAnnotation annotation, @NotNull LanguageLevel languageLevel) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && Comparing.strEqual(annotation.getQualifiedName(), CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE)) {
final PsiAnnotationOwner owner = annotation.getOwner();
PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof PsiModifierList) {
final PsiElement parent = ((PsiModifierList)owner).getParent();
PsiElement parent = ((PsiModifierList)owner).getParent();
if (parent instanceof PsiClass) {
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, JavaErrorBundle.message("not.a.functional.interface", ((PsiClass)parent).getName()));
String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, JavaErrorBundle.message("not.a.functional.interface", ((PsiClass)parent).getName()));
if (errorMessage != null) {
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();

View File

@@ -52,11 +52,11 @@ public final class GenericsHighlightUtil {
@NotNull PsiElement call,
@NotNull PsiSubstitutor substitutor) {
PsiTypeParameter[] typeParameters = listOwner.getTypeParameters();
final Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor,
Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor,
call, false);
if (inferredTypeArgument != null) {
final PsiType extendsType = inferredTypeArgument.second;
final PsiTypeParameter typeParameter = inferredTypeArgument.first;
PsiType extendsType = inferredTypeArgument.second;
PsiTypeParameter typeParameter = inferredTypeArgument.first;
PsiClass boundClass = extendsType instanceof PsiClassType ? ((PsiClassType)extendsType).resolve() : null;
@NonNls String messageKey = boundClass == null || typeParameter.isInterface() == boundClass.isInterface()
@@ -80,7 +80,7 @@ public final class GenericsHighlightUtil {
@NotNull PsiSubstitutor substitutor,
@NotNull JavaSdkVersion javaSdkVersion) {
if (!(resolved instanceof PsiTypeParameterListOwner)) return null;
final PsiTypeParameterListOwner typeParameterListOwner = (PsiTypeParameterListOwner)resolved;
PsiTypeParameterListOwner typeParameterListOwner = (PsiTypeParameterListOwner)resolved;
return checkReferenceTypeArgumentList(typeParameterListOwner, referenceElement.getParameterList(), substitutor, true, javaSdkVersion);
}
@@ -95,7 +95,7 @@ public final class GenericsHighlightUtil {
referenceElements = referenceParameterList.getTypeParameterElements();
if (referenceElements.length == 1 && referenceElements[0].getType() instanceof PsiDiamondType) {
if (!typeParameterListOwner.hasTypeParameters()) {
final String description = JavaErrorBundle.message("generics.diamond.not.applicable");
String description = JavaErrorBundle.message("generics.diamond.not.applicable");
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(referenceParameterList).descriptionAndTooltip(description)
.create();
@@ -103,9 +103,9 @@ public final class GenericsHighlightUtil {
return info;
}
inferenceResult = ((PsiDiamondType)referenceElements[0].getType()).resolveInferredTypes();
final String errorMessage = inferenceResult.getErrorMessage();
String errorMessage = inferenceResult.getErrorMessage();
if (errorMessage != null) {
final PsiType expectedType = detectExpectedType(referenceParameterList);
PsiType expectedType = detectExpectedType(referenceParameterList);
if (!(inferenceResult.failedToInfer() && expectedType instanceof PsiClassType && ((PsiClassType)expectedType).isRaw())) {
HighlightInfo highlightInfo = HighlightInfo
.newHighlightInfo(HighlightInfoType.ERROR).range(referenceParameterList).descriptionAndTooltip(errorMessage).create();
@@ -134,11 +134,11 @@ public final class GenericsHighlightUtil {
}
}
final PsiTypeParameter[] typeParameters = typeParameterListOwner.getTypeParameters();
final int targetParametersNum = typeParameters.length;
final int refParametersNum = referenceParameterList == null ? 0 : referenceParameterList.getTypeArguments().length;
PsiTypeParameter[] typeParameters = typeParameterListOwner.getTypeParameters();
int targetParametersNum = typeParameters.length;
int refParametersNum = referenceParameterList == null ? 0 : referenceParameterList.getTypeArguments().length;
if (targetParametersNum != refParametersNum && refParametersNum != 0) {
final String description;
String description;
if (targetParametersNum == 0) {
if (PsiTreeUtil.getParentOfType(referenceParameterList, PsiCall.class) != null &&
typeParameterListOwner instanceof PsiMethod &&
@@ -184,17 +184,17 @@ public final class GenericsHighlightUtil {
// bounds check
if (targetParametersNum > 0 && refParametersNum != 0) {
if (inferenceResult != null) {
final PsiType[] types = inferenceResult.getTypes();
PsiType[] types = inferenceResult.getTypes();
for (int i = 0; i < typeParameters.length; i++) {
final PsiType type = types[i];
final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, type, referenceElements[0], referenceParameterList);
PsiType type = types[i];
HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, type, referenceElements[0], referenceParameterList);
if (highlightInfo != null) return highlightInfo;
}
}
else {
for (int i = 0; i < typeParameters.length; i++) {
final PsiTypeElement typeElement = referenceElements[i];
final HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, typeElement.getType(), typeElement, referenceParameterList);
PsiTypeElement typeElement = referenceElements[i];
HighlightInfo highlightInfo = checkTypeParameterWithinItsBound(typeParameters[i], substitutor, typeElement.getType(), typeElement, referenceParameterList);
if (highlightInfo != null) return highlightInfo;
}
}
@@ -211,9 +211,9 @@ public final class GenericsHighlightUtil {
}
private static PsiType detectExpectedType(@NotNull PsiReferenceParameterList referenceParameterList) {
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(referenceParameterList, PsiNewExpression.class);
PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(referenceParameterList, PsiNewExpression.class);
LOG.assertTrue(newExpression != null);
final PsiElement parent = newExpression.getParent();
PsiElement parent = newExpression.getParent();
PsiType expectedType = null;
if (parent instanceof PsiVariable && newExpression.equals(((PsiVariable)parent).getInitializer())) {
expectedType = ((PsiVariable)parent).getType();
@@ -228,16 +228,16 @@ public final class GenericsHighlightUtil {
}
}
else if (parent instanceof PsiExpressionList) {
final PsiElement pParent = parent.getParent();
PsiElement pParent = parent.getParent();
if (pParent instanceof PsiCallExpression) {
PsiExpressionList argumentList = ((PsiCallExpression)pParent).getArgumentList();
if (parent.equals(argumentList)) {
final PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
PsiMethod method = ((PsiCallExpression)pParent).resolveMethod();
if (method != null) {
final PsiExpression[] expressions = argumentList.getExpressions();
final int idx = ArrayUtilRt.find(expressions, newExpression);
PsiExpression[] expressions = argumentList.getExpressions();
int idx = ArrayUtilRt.find(expressions, newExpression);
if (idx > -1) {
final PsiParameter parameter = method.getParameterList().getParameter(idx);
PsiParameter parameter = method.getParameterList().getParameter(idx);
if (parameter != null) {
expectedType = parameter.getType();
}
@@ -254,22 +254,22 @@ public final class GenericsHighlightUtil {
@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);
PsiClass referenceClass = type instanceof PsiClassType ? ((PsiClassType)type).resolve() : null;
PsiType psiType = substitutor.substitute(classParameter);
if (psiType instanceof PsiClassType && !(PsiUtil.resolveClassInType(psiType) instanceof PsiTypeParameter)) {
if (GenericsUtil.checkNotInBounds(type, psiType, referenceParameterList)) {
final String description = JavaErrorBundle.message("actual.type.argument.contradict.inferred.type");
String description = JavaErrorBundle.message("actual.type.argument.contradict.inferred.type");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement2Highlight).descriptionAndTooltip(description).create();
}
}
final PsiClassType[] bounds = classParameter.getSuperTypes();
PsiClassType[] bounds = classParameter.getSuperTypes();
for (PsiType bound : bounds) {
bound = substitutor.substitute(bound);
if (!bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && GenericsUtil.checkNotInBounds(type, bound, referenceParameterList)) {
PsiClass boundClass = bound instanceof PsiClassType ? ((PsiClassType)bound).resolve() : null;
@NonNls final String messageKey = boundClass == null || referenceClass == null || referenceClass.isInterface() == boundClass.isInterface()
@NonNls String messageKey = boundClass == null || referenceClass == null || referenceClass.isInterface() == boundClass.isInterface()
? "generics.type.parameter.is.not.within.its.bound.extend"
: "generics.type.parameter.is.not.within.its.bound.implement";
@@ -277,7 +277,7 @@ public final class GenericsHighlightUtil {
referenceClass != null ? HighlightUtil.formatClass(referenceClass) : type.getPresentableText(),
JavaHighlightUtil.formatType(bound));
final HighlightInfo info =
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement2Highlight).descriptionAndTooltip(description).create();
if (bound instanceof PsiClassType && referenceClass != null && info != null) {
QuickFixAction
@@ -322,7 +322,7 @@ public final class GenericsHighlightUtil {
@NotNull PsiClass aClass,
@NotNull JavaResolveResult resolveResult,
@NotNull PsiElement element) {
final PsiJavaCodeReferenceElement[] referenceElements = referenceList.getReferenceElements();
PsiJavaCodeReferenceElement[] referenceElements = referenceList.getReferenceElements();
PsiClass extendFrom = (PsiClass)resolveResult.getElement();
if (extendFrom == null) return null;
HighlightInfo errorResult = null;
@@ -334,7 +334,7 @@ public final class GenericsHighlightUtil {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMoveBoundClassToFrontFix(aClass, type), null);
}
else if (referenceElements.length != 0 && element != referenceElements[0] && referenceElements[0].resolve() instanceof PsiTypeParameter) {
final String description = JavaErrorBundle.message("type.parameter.cannot.be.followed.by.other.bounds");
String description = JavaErrorBundle.message("type.parameter.cannot.be.followed.by.other.bounds");
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
PsiClassType type =
JavaPsiFacade.getElementFactory(aClass.getProject()).createType(extendFrom, resolveResult.getSubstitutor());
@@ -344,9 +344,9 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkInterfaceMultipleInheritance(@NotNull PsiClass aClass) {
final PsiClassType[] types = aClass.getSuperTypes();
PsiClassType[] types = aClass.getSuperTypes();
if (types.length < 2) return null;
final TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
return checkInterfaceMultipleInheritance(aClass,
aClass,
PsiSubstitutor.EMPTY, new HashMap<>(),
@@ -359,9 +359,9 @@ public final class GenericsHighlightUtil {
@NotNull Map<PsiClass, PsiSubstitutor> inheritedClasses,
@NotNull Set<? super PsiClass> visited,
@NotNull TextRange textRange) {
final List<PsiClassType.ClassResolveResult> superTypes = PsiClassImplUtil.getScopeCorrectedSuperTypes(aClass, place.getResolveScope());
List<PsiClassType.ClassResolveResult> superTypes = PsiClassImplUtil.getScopeCorrectedSuperTypes(aClass, place.getResolveScope());
for (PsiClassType.ClassResolveResult result : superTypes) {
final PsiClass superClass = result.getElement();
PsiClass superClass = result.getElement();
if (superClass == null || visited.contains(superClass)) continue;
PsiSubstitutor superTypeSubstitutor = result.getSubstitutor();
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(aClass.getProject());
@@ -369,9 +369,9 @@ public final class GenericsHighlightUtil {
superTypeSubstitutor = PsiUtil.isRawSubstitutor(aClass, derivedSubstitutor) ? elementFactory.createRawSubstitutor(superClass)
: MethodSignatureUtil.combineSubstitutors(superTypeSubstitutor, derivedSubstitutor);
final PsiSubstitutor inheritedSubstitutor = inheritedClasses.get(superClass);
PsiSubstitutor inheritedSubstitutor = inheritedClasses.get(superClass);
if (inheritedSubstitutor != null) {
final PsiTypeParameter[] typeParameters = superClass.getTypeParameters();
PsiTypeParameter[] typeParameters = superClass.getTypeParameters();
for (PsiTypeParameter typeParameter : typeParameters) {
PsiType type1 = inheritedSubstitutor.substitute(typeParameter);
PsiType type2 = superTypeSubstitutor.substitute(typeParameter);
@@ -395,7 +395,7 @@ public final class GenericsHighlightUtil {
}
inheritedClasses.put(superClass, superTypeSubstitutor);
visited.add(superClass);
final HighlightInfo highlightInfo = checkInterfaceMultipleInheritance(superClass, place, superTypeSubstitutor, inheritedClasses, visited, textRange);
HighlightInfo highlightInfo = checkInterfaceMultipleInheritance(superClass, place, superTypeSubstitutor, inheritedClasses, visited, textRange);
visited.remove(superClass);
if (highlightInfo != null) return highlightInfo;
@@ -406,12 +406,12 @@ public final class GenericsHighlightUtil {
@NotNull
static Collection<HighlightInfo> checkOverrideEquivalentMethods(@NotNull PsiClass aClass) {
List<HighlightInfo> result = new ArrayList<>();
final Collection<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
Collection<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
PsiManager manager = aClass.getManager();
Map<MethodSignature, MethodSignatureBackedByPsiMethod> sameErasureMethods =
MethodSignatureUtil.createErasedMethodSignatureMap();
final Set<MethodSignature> foundProblems = MethodSignatureUtil.createErasedMethodSignatureSet();
Set<MethodSignature> foundProblems = MethodSignatureUtil.createErasedMethodSignatureSet();
for (HierarchicalMethodSignature signature : signaturesWithSupers) {
HighlightInfo info = checkSameErasureNotSubSignatureInner(signature, manager, aClass, sameErasureMethods);
if (info != null && foundProblems.add(signature)) {
@@ -435,8 +435,8 @@ public final class GenericsHighlightUtil {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && aClass.isInterface() && method.hasModifierProperty(PsiModifier.DEFAULT)) {
HierarchicalMethodSignature sig = method.getHierarchicalMethodSignature();
for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) {
final PsiMethod objectMethod = methodSignature.getMethod();
final PsiClass containingClass = objectMethod.getContainingClass();
PsiMethod objectMethod = methodSignature.getMethod();
PsiClass containingClass = objectMethod.getContainingClass();
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName()) && objectMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip(JavaErrorBundle.message("default.method.overrides.object.member", sig.getName()))
@@ -458,13 +458,13 @@ public final class GenericsHighlightUtil {
@NotNull Collection<? extends PsiMethod> overrideEquivalentSuperMethods,
boolean skipMethodInSelf) {
if (overrideEquivalentSuperMethods.size() <= 1) return null;
final boolean isInterface = aClass.isInterface();
boolean isInterface = aClass.isInterface();
List<PsiMethod> defaults = null;
List<PsiMethod> abstracts = null;
boolean hasConcrete = false;
for (PsiMethod method : overrideEquivalentSuperMethods) {
final boolean isDefault = method.hasModifierProperty(PsiModifier.DEFAULT);
final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
boolean isDefault = method.hasModifierProperty(PsiModifier.DEFAULT);
boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
if (isDefault) {
if (defaults == null) defaults = new ArrayList<>(2);
defaults.add(method);
@@ -477,11 +477,11 @@ public final class GenericsHighlightUtil {
}
if (!hasConcrete && defaults != null) {
final PsiMethod defaultMethod = defaults.get(0);
PsiMethod defaultMethod = defaults.get(0);
if (!skipMethodInSelf && MethodSignatureUtil.findMethodBySuperMethod(aClass, defaultMethod, false) != null) return null;
final PsiClass defaultMethodContainingClass = defaultMethod.getContainingClass();
PsiClass defaultMethodContainingClass = defaultMethod.getContainingClass();
if (defaultMethodContainingClass == null) return null;
final PsiMethod unrelatedMethod;
PsiMethod unrelatedMethod;
if (abstracts != null) {
unrelatedMethod = abstracts.get(0);
}
@@ -491,7 +491,7 @@ public final class GenericsHighlightUtil {
else {
return null;
}
final PsiClass unrelatedMethodContainingClass = unrelatedMethod.getContainingClass();
PsiClass unrelatedMethodContainingClass = unrelatedMethod.getContainingClass();
if (unrelatedMethodContainingClass == null) return null;
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT) && !(aClass instanceof PsiTypeParameter)
&& abstracts != null && unrelatedMethodContainingClass.isInterface()) {
@@ -500,7 +500,7 @@ public final class GenericsHighlightUtil {
defaultMethod.getSignature(PsiSubstitutor.EMPTY))) {
return null;
}
final String key = aClass instanceof PsiEnumConstantInitializer || aClass.isRecord() ?
String key = aClass instanceof PsiEnumConstantInitializer || aClass.isRecord() ?
"class.must.implement.method" : "class.must.be.abstract";
return JavaErrorBundle.message(key,
HighlightUtil.formatClass(aClass, false),
@@ -508,8 +508,8 @@ public final class GenericsHighlightUtil {
HighlightUtil.formatClass(unrelatedMethodContainingClass, false));
}
if (isInterface || abstracts == null || unrelatedMethodContainingClass.isInterface()) {
final List<PsiClass> defaultContainingClasses = ContainerUtil.mapNotNull(defaults, PsiMethod::getContainingClass);
final String unrelatedDefaults = hasUnrelatedDefaults(defaultContainingClasses);
List<PsiClass> defaultContainingClasses = ContainerUtil.mapNotNull(defaults, PsiMethod::getContainingClass);
String unrelatedDefaults = hasUnrelatedDefaults(defaultContainingClasses);
if (unrelatedDefaults == null &&
(abstracts == null || !hasNotOverriddenAbstract(defaultContainingClasses, unrelatedMethodContainingClass))) {
return null;
@@ -533,12 +533,12 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkUnrelatedDefaultMethods(@NotNull PsiClass aClass, @NotNull PsiIdentifier classIdentifier) {
final Map<? extends MethodSignature, Set<PsiMethod>> overrideEquivalent = PsiSuperMethodUtil.collectOverrideEquivalents(aClass);
Map<? extends MethodSignature, Set<PsiMethod>> overrideEquivalent = PsiSuperMethodUtil.collectOverrideEquivalents(aClass);
for (Set<PsiMethod> overrideEquivalentMethods : overrideEquivalent.values()) {
String errorMessage = getUnrelatedDefaultsMessage(aClass, overrideEquivalentMethods, false);
if (errorMessage != null) {
final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(classIdentifier)
.descriptionAndTooltip(errorMessage)
.create();
@@ -562,7 +562,7 @@ public final class GenericsHighlightUtil {
if (defaults.size() > 1) {
PsiClass[] defaultClasses = defaults.toArray(PsiClass.EMPTY_ARRAY);
ArrayList<PsiClass> classes = new ArrayList<>(defaults);
for (final PsiClass aClass1 : defaultClasses) {
for (PsiClass aClass1 : defaultClasses) {
classes.removeIf(aClass2 -> aClass1.isInheritor(aClass2, true));
}
@@ -577,34 +577,34 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkUnrelatedConcrete(@NotNull PsiClass psiClass,
@NotNull PsiIdentifier classIdentifier) {
final PsiClass superClass = psiClass.getSuperClass();
PsiClass superClass = psiClass.getSuperClass();
if (superClass != null && superClass.hasTypeParameters()) {
final Collection<HierarchicalMethodSignature> visibleSignatures = superClass.getVisibleSignatures();
final Map<MethodSignature, PsiMethod> overrideEquivalent = MethodSignatureUtil.createErasedMethodSignatureMap();
Collection<HierarchicalMethodSignature> visibleSignatures = superClass.getVisibleSignatures();
Map<MethodSignature, PsiMethod> overrideEquivalent = MethodSignatureUtil.createErasedMethodSignatureMap();
for (HierarchicalMethodSignature hms : visibleSignatures) {
final PsiMethod method = hms.getMethod();
PsiMethod method = hms.getMethod();
if (method.isConstructor()) continue;
if (method.hasModifierProperty(PsiModifier.ABSTRACT) ||
method.hasModifierProperty(PsiModifier.DEFAULT) ||
method.hasModifierProperty(PsiModifier.STATIC)) continue;
if (psiClass.findMethodsBySignature(method, false).length > 0) continue;
final PsiClass containingClass = method.getContainingClass();
PsiClass containingClass = method.getContainingClass();
if (containingClass == null) continue;
final PsiSubstitutor containingClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, psiClass, PsiSubstitutor.EMPTY);
final PsiSubstitutor finalSubstitutor = PsiSuperMethodUtil
PsiSubstitutor containingClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, psiClass, PsiSubstitutor.EMPTY);
PsiSubstitutor finalSubstitutor = PsiSuperMethodUtil
.obtainFinalSubstitutor(containingClass, containingClassSubstitutor, hms.getSubstitutor(), false);
final MethodSignatureBackedByPsiMethod signature = MethodSignatureBackedByPsiMethod.create(method, finalSubstitutor, false);
final PsiMethod foundMethod = overrideEquivalent.get(signature);
MethodSignatureBackedByPsiMethod signature = MethodSignatureBackedByPsiMethod.create(method, finalSubstitutor, false);
PsiMethod foundMethod = overrideEquivalent.get(signature);
PsiClass foundMethodContainingClass;
if (foundMethod != null &&
!foundMethod.hasModifierProperty(PsiModifier.ABSTRACT) &&
!foundMethod.hasModifierProperty(PsiModifier.DEFAULT) &&
(foundMethodContainingClass = foundMethod.getContainingClass()) != null) {
final String description =
String description =
JavaErrorBundle.message("two.methods.are.inherited.with.same.signature",
JavaHighlightUtil.formatMethod(foundMethod), HighlightUtil.formatClass(foundMethodContainingClass),
JavaHighlightUtil.formatMethod(method), HighlightUtil.formatClass(containingClass));
final HighlightInfo info = HighlightInfo
HighlightInfo info = HighlightInfo
.newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(
description)
.create();
@@ -645,7 +645,7 @@ public final class GenericsHighlightUtil {
if (info != null) return info;
if (superSignature.isRaw() && !signature.isRaw()) {
final PsiType[] parameterTypes = signature.getParameterTypes();
PsiType[] parameterTypes = signature.getParameterTypes();
PsiType[] erasedTypes = superSignature.getErasedParameterTypes();
for (int i = 0; i < erasedTypes.length; i++) {
if (!Comparing.equal(parameterTypes[i], erasedTypes[i])) {
@@ -663,7 +663,7 @@ public final class GenericsHighlightUtil {
@NotNull HierarchicalMethodSignature superSignature,
@NotNull PsiClass aClass,
@NotNull PsiMethod superMethod) {
final PsiMethod checkMethod = signatureToCheck.getMethod();
PsiMethod checkMethod = signatureToCheck.getMethod();
if (superMethod.equals(checkMethod)) return null;
PsiClass checkContainingClass = checkMethod.getContainingClass();
LOG.assertTrue(checkContainingClass != null);
@@ -675,7 +675,7 @@ public final class GenericsHighlightUtil {
else if (superMethod.isConstructor()) return null;
JavaVersionService javaVersionService = JavaVersionService.getInstance();
final boolean atLeast17 = javaVersionService.isAtLeast(aClass, JavaSdkVersion.JDK_1_7);
boolean atLeast17 = javaVersionService.isAtLeast(aClass, JavaSdkVersion.JDK_1_7);
if (checkMethod.hasModifierProperty(PsiModifier.STATIC) && !checkEqualsSuper && !atLeast17) {
return null;
}
@@ -685,8 +685,8 @@ public final class GenericsHighlightUtil {
return null;
}
final PsiType retErasure1 = TypeConversionUtil.erasure(checkMethod.getReturnType());
final PsiType retErasure2 = TypeConversionUtil.erasure(superMethod.getReturnType());
PsiType retErasure1 = TypeConversionUtil.erasure(checkMethod.getReturnType());
PsiType retErasure2 = TypeConversionUtil.erasure(superMethod.getReturnType());
boolean differentReturnTypeErasure = !Comparing.equal(retErasure1, retErasure2);
if (checkEqualsSuper && atLeast17 && retErasure1 != null && retErasure2 != null) {
@@ -699,7 +699,7 @@ public final class GenericsHighlightUtil {
!(checkEqualsSuper && Arrays.equals(superSignature.getParameterTypes(), signatureToCheck.getParameterTypes())) &&
!atLeast17) {
int idx = 0;
final PsiType[] erasedTypes = signatureToCheck.getErasedParameterTypes();
PsiType[] erasedTypes = signatureToCheck.getErasedParameterTypes();
boolean erasure = erasedTypes.length > 0;
for (PsiType type : superSignature.getParameterTypes()) {
erasure &= Comparing.equal(type, erasedTypes[idx]);
@@ -725,9 +725,9 @@ public final class GenericsHighlightUtil {
}
}
private static HighlightInfo getSameErasureMessage(final boolean sameClass, @NotNull PsiMethod method, @NotNull PsiMethod superMethod,
private static HighlightInfo getSameErasureMessage(boolean sameClass, @NotNull PsiMethod method, @NotNull PsiMethod superMethod,
@NotNull TextRange textRange) {
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
@NonNls String key = sameClass ? "generics.methods.have.same.erasure" :
method.hasModifierProperty(PsiModifier.STATIC) ?
"generics.methods.have.same.erasure.hide" :
"generics.methods.have.same.erasure.override";
@@ -742,8 +742,8 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkTypeParameterInstantiation(@NotNull PsiNewExpression expression) {
PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
if (classReference == null) return null;
final JavaResolveResult result = classReference.advancedResolve(false);
final PsiElement element = result.getElement();
JavaResolveResult result = classReference.advancedResolve(false);
PsiElement element = result.getElement();
if (element instanceof PsiTypeParameter) {
String description = JavaErrorBundle.message("generics.type.parameter.cannot.be.instantiated",
HighlightUtil.formatClass((PsiTypeParameter)element));
@@ -785,10 +785,10 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkReferenceTypeUsedAsTypeArgument(@NotNull PsiTypeElement typeElement, @NotNull LanguageLevel level) {
final PsiType type = typeElement.getType();
PsiType type = typeElement.getType();
if (type != PsiType.NULL && type instanceof PsiPrimitiveType ||
type instanceof PsiWildcardType && ((PsiWildcardType)type).getBound() instanceof PsiPrimitiveType) {
final PsiElement element = new PsiMatcherImpl(typeElement)
PsiElement element = new PsiMatcherImpl(typeElement)
.parent(PsiMatchers.hasClass(PsiReferenceParameterList.class))
.parent(PsiMatchers.hasClass(PsiJavaCodeReferenceElement.class, PsiNewExpression.class))
.getElement();
@@ -804,7 +804,7 @@ public final class GenericsHighlightUtil {
toConvert = ((PsiWildcardType)type).getBound();
}
if (toConvert instanceof PsiPrimitiveType) {
final PsiClassType boxedType = ((PsiPrimitiveType)toConvert).getBoxedType(typeElement);
PsiClassType boxedType = ((PsiPrimitiveType)toConvert).getBoxedType(typeElement);
if (boxedType != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createReplacePrimitiveWithBoxedTypeAction(
typeElement, toConvert.getPresentableText(), ((PsiPrimitiveType)toConvert).getBoxedTypeName()));
@@ -818,11 +818,11 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkForeachExpressionTypeIsIterable(@NotNull PsiExpression expression) {
if (expression.getType() == null) return null;
final PsiType itemType = JavaGenericsUtil.getCollectionItemType(expression);
PsiType itemType = JavaGenericsUtil.getCollectionItemType(expression);
if (itemType == null) {
String description = JavaErrorBundle.message("foreach.not.applicable",
JavaHighlightUtil.formatType(expression.getType()));
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createNotIterableForEachLoopFix(expression));
return highlightInfo;
}
@@ -830,11 +830,11 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkForEachParameterType(@NotNull PsiForeachStatement statement, @NotNull PsiParameter parameter) {
final PsiExpression expression = statement.getIteratedValue();
final PsiType itemType = expression == null ? null : JavaGenericsUtil.getCollectionItemType(expression);
PsiExpression expression = statement.getIteratedValue();
PsiType itemType = expression == null ? null : JavaGenericsUtil.getCollectionItemType(expression);
if (itemType == null) return null;
final PsiType parameterType = parameter.getType();
PsiType parameterType = parameter.getType();
if (TypeConversionUtil.isAssignable(parameterType, itemType)) {
return null;
}
@@ -869,7 +869,7 @@ public final class GenericsHighlightUtil {
if (field.getContainingClass() != enumClass) return false;
if (!JavaVersionService.getInstance().isAtLeast(field, JavaSdkVersion.JDK_1_6)) {
final PsiType type = field.getType();
PsiType type = field.getType();
if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == enumClass) return false;
}
@@ -883,7 +883,7 @@ public final class GenericsHighlightUtil {
*/
public static @Nullable PsiClass getEnumClassForExpressionInInitializer(@NotNull PsiExpression expr) {
if (PsiImplUtil.getSwitchLabel(expr) != null) return null;
final PsiMember constructorOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expr);
PsiMember constructorOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expr);
if (constructorOrInitializer == null) return null;
if (constructorOrInitializer.hasModifierProperty(PsiModifier.STATIC)) return null;
PsiClass enumClass = constructorOrInitializer instanceof PsiEnumConstantInitializer ?
@@ -927,14 +927,14 @@ public final class GenericsHighlightUtil {
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,
PsiType javaLangString = PsiType.getJavaLangString(PsiManager.getInstance(project), GlobalSearchScope.allScope(project));
MethodSignature valueOfMethod = MethodSignatureUtil.createMethodSignature("valueOf", new PsiType[]{javaLangString}, PsiTypeParameter.EMPTY_ARRAY,
PsiSubstitutor.EMPTY);
return MethodSignatureUtil.areSignaturesErasureEqual(valueOfMethod, methodSignature);
}
static HighlightInfo checkTypeParametersList(@NotNull PsiTypeParameterList list, PsiTypeParameter @NotNull [] parameters, @NotNull LanguageLevel level) {
final PsiElement parent = list.getParent();
PsiElement parent = list.getParent();
if (parent instanceof PsiClass && ((PsiClass)parent).isEnum()) {
String description = JavaErrorBundle.message("generics.enum.may.not.have.type.parameters");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
@@ -949,12 +949,12 @@ public final class GenericsHighlightUtil {
}
for (int i = 0; i < parameters.length; i++) {
final PsiTypeParameter typeParameter1 = parameters[i];
final HighlightInfo cyclicInheritance = HighlightClassUtil.checkCyclicInheritance(typeParameter1);
PsiTypeParameter typeParameter1 = parameters[i];
HighlightInfo cyclicInheritance = HighlightClassUtil.checkCyclicInheritance(typeParameter1);
if (cyclicInheritance != null) return cyclicInheritance;
String name1 = typeParameter1.getName();
for (int j = i + 1; j < parameters.length; j++) {
final PsiTypeParameter typeParameter2 = parameters[j];
PsiTypeParameter typeParameter2 = parameters[j];
String name2 = typeParameter2.getName();
if (Comparing.strEqual(name1, name2)) {
String message = JavaErrorBundle.message("generics.duplicate.type.parameter", name1);
@@ -963,7 +963,7 @@ public final class GenericsHighlightUtil {
}
if (!level.isAtLeast(LanguageLevel.JDK_1_7)) {
for (PsiJavaCodeReferenceElement referenceElement : typeParameter1.getExtendsList().getReferenceElements()) {
final PsiElement resolve = referenceElement.resolve();
PsiElement resolve = referenceElement.resolve();
if (resolve instanceof PsiTypeParameter && ArrayUtilRt.find(parameters, resolve) > i) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(referenceElement).descriptionAndTooltip(
JavaErrorBundle.message("illegal.forward.reference")).create();
@@ -978,12 +978,12 @@ public final class GenericsHighlightUtil {
static Collection<HighlightInfo> checkCatchParameterIsClass(@NotNull PsiParameter parameter) {
if (!(parameter.getDeclarationScope() instanceof PsiCatchSection)) return Collections.emptyList();
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
final Collection<HighlightInfo> result = new ArrayList<>(typeElements.size());
List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
Collection<HighlightInfo> result = new ArrayList<>(typeElements.size());
for (PsiTypeElement typeElement : typeElements) {
final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(typeElement.getType());
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(typeElement.getType());
if (aClass instanceof PsiTypeParameter) {
final String message = JavaErrorBundle.message("generics.cannot.catch.type.parameters");
String message = JavaErrorBundle.message("generics.cannot.catch.type.parameters");
result.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(message).create());
}
}
@@ -992,7 +992,7 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkInstanceOfGenericType(@NotNull LanguageLevel languageLevel, @NotNull PsiInstanceOfExpression expression) {
final PsiTypeElement checkTypeElement = expression.getCheckType();
PsiTypeElement checkTypeElement = expression.getCheckType();
if (checkTypeElement == null) return null;
PsiType checkType = checkTypeElement.getType();
if (HighlightingFeature.PATTERNS.isSufficient(languageLevel)) {
@@ -1015,7 +1015,7 @@ public final class GenericsHighlightUtil {
* ReferenceType mentioned after the instanceof operator is reifiable
*/
private static HighlightInfo isIllegalForInstanceOf(@Nullable PsiType type, @NotNull PsiTypeElement typeElement) {
final PsiClass resolved = PsiUtil.resolveClassInClassTypeOnly(type);
PsiClass resolved = PsiUtil.resolveClassInClassTypeOnly(type);
if (resolved instanceof PsiTypeParameter) {
String description = JavaErrorBundle.message("generics.cannot.instanceof.type.parameters");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
@@ -1035,7 +1035,7 @@ public final class GenericsHighlightUtil {
return canSelectFrom((PsiClassType)type, expression.getOperand());
}
if (type instanceof PsiArrayType) {
final PsiType arrayComponentType = type.getDeepComponentType();
PsiType arrayComponentType = type.getDeepComponentType();
if (arrayComponentType instanceof PsiClassType) {
return canSelectFrom((PsiClassType)arrayComponentType, expression.getOperand());
}
@@ -1063,8 +1063,8 @@ public final class GenericsHighlightUtil {
try {
MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superMethod != null && method.getContainingClass().isInterface()) {
final PsiMethod psiMethod = superMethod.getMethod();
final PsiClass containingClass = psiMethod.getContainingClass();
PsiMethod psiMethod = superMethod.getMethod();
PsiClass containingClass = psiMethod.getContainingClass();
if (containingClass != null &&
CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName()) &&
psiMethod.hasModifierProperty(PsiModifier.PROTECTED)) {
@@ -1102,7 +1102,7 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkSafeVarargsAnnotation(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
PsiModifierList list = method.getModifierList();
final PsiAnnotation safeVarargsAnnotation = list.findAnnotation(CommonClassNames.JAVA_LANG_SAFE_VARARGS);
PsiAnnotation safeVarargsAnnotation = list.findAnnotation(CommonClassNames.JAVA_LANG_SAFE_VARARGS);
if (safeVarargsAnnotation == null) {
return null;
}
@@ -1119,7 +1119,7 @@ public final class GenericsHighlightUtil {
}
PsiParameterList parameterList = method.getParameterList();
final PsiParameter varParameter = Objects.requireNonNull(parameterList.getParameter(parameterList.getParametersCount() - 1));
PsiParameter varParameter = Objects.requireNonNull(parameterList.getParameter(parameterList.getParametersCount() - 1));
for (PsiReferenceExpression element : VariableAccessUtils.getVariableReferences(varParameter, method.getBody())) {
if (!PsiUtil.isAccessedForReading(element)) {
@@ -1130,8 +1130,8 @@ public final class GenericsHighlightUtil {
LOG.assertTrue(varParameter.isVarArgs());
final PsiEllipsisType ellipsisType = (PsiEllipsisType)varParameter.getType();
final PsiType componentType = ellipsisType.getComponentType();
PsiEllipsisType ellipsisType = (PsiEllipsisType)varParameter.getType();
PsiType componentType = ellipsisType.getComponentType();
if (JavaGenericsUtil.isReifiableType(componentType)) {
PsiElement element = varParameter.getTypeElement();
return HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING).range(element).descriptionAndTooltip(
@@ -1176,13 +1176,13 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkEnumSuperConstructorCall(@NotNull PsiMethodCallExpression expr) {
PsiReferenceExpression methodExpression = expr.getMethodExpression();
final PsiElement refNameElement = methodExpression.getReferenceNameElement();
PsiElement refNameElement = methodExpression.getReferenceNameElement();
if (refNameElement != null && PsiKeyword.SUPER.equals(refNameElement.getText())) {
final PsiMember constructor = PsiUtil.findEnclosingConstructorOrInitializer(expr);
PsiMember constructor = PsiUtil.findEnclosingConstructorOrInitializer(expr);
if (constructor instanceof PsiMethod) {
final PsiClass aClass = constructor.getContainingClass();
PsiClass aClass = constructor.getContainingClass();
if (aClass != null && aClass.isEnum()) {
final String message = JavaErrorBundle.message("call.to.super.is.not.allowed.in.enum.constructor");
String message = JavaErrorBundle.message("call.to.super.is.not.allowed.in.enum.constructor");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expr).descriptionAndTooltip(message).create();
}
}
@@ -1221,11 +1221,11 @@ public final class GenericsHighlightUtil {
}
static HighlightInfo checkParametersAllowed(@NotNull PsiReferenceParameterList refParamList) {
final PsiElement parent = refParamList.getParent();
PsiElement parent = refParamList.getParent();
if (parent instanceof PsiReferenceExpression) {
final PsiElement grandParent = parent.getParent();
PsiElement grandParent = parent.getParent();
if (!(grandParent instanceof PsiMethodCallExpression) && !(parent instanceof PsiMethodReferenceExpression)) {
final String message = JavaErrorBundle.message("generics.reference.parameters.not.allowed");
String message = JavaErrorBundle.message("generics.reference.parameters.not.allowed");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(refParamList).descriptionAndTooltip(message).create();
}
}
@@ -1245,7 +1245,7 @@ public final class GenericsHighlightUtil {
else if (parent instanceof PsiCallExpression) {
resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics();
if (parent instanceof PsiMethodCallExpression) {
final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)parent).getMethodExpression();
PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)parent).getMethodExpression();
qualifier = methodExpression.getQualifier();
}
}
@@ -1260,16 +1260,16 @@ public final class GenericsHighlightUtil {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) return null;
if (((PsiMethod)element).findSuperMethods().length > 0) return null;
if (qualifier instanceof PsiReferenceExpression) {
final PsiType type = ((PsiReferenceExpression)qualifier).getType();
final boolean isJavac7 = JavaVersionService.getInstance().isAtLeast(containingClass, JavaSdkVersion.JDK_1_7);
PsiType type = ((PsiReferenceExpression)qualifier).getType();
boolean isJavac7 = JavaVersionService.getInstance().isAtLeast(containingClass, JavaSdkVersion.JDK_1_7);
if (type instanceof PsiClassType && isJavac7 && ((PsiClassType)type).isRaw()) return null;
final PsiClass typeParameter = PsiUtil.resolveClassInType(type);
PsiClass typeParameter = PsiUtil.resolveClassInType(type);
if (typeParameter instanceof PsiTypeParameter) {
if (isJavac7) return null;
for (PsiClassType classType : typeParameter.getExtendsListTypes()) {
final PsiClass resolve = classType.resolve();
PsiClass resolve = classType.resolve();
if (resolve != null) {
final PsiMethod[] superMethods = resolve.findMethodsBySignature((PsiMethod)element, true);
PsiMethod[] superMethods = resolve.findMethodsBySignature((PsiMethod)element, true);
for (PsiMethod superMethod : superMethods) {
if (!PsiUtil.isRawSubstitutor(superMethod, resolveResult.getSubstitutor())) {
return null;
@@ -1280,7 +1280,7 @@ public final class GenericsHighlightUtil {
}
}
}
final String message = element instanceof PsiClass
String message = element instanceof PsiClass
? JavaErrorBundle.message("generics.type.arguments.on.raw.type")
: JavaErrorBundle.message("generics.type.arguments.on.raw.method");
@@ -1349,11 +1349,11 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkSelectStaticClassFromParameterizedType(@Nullable PsiElement resolved, @NotNull PsiJavaCodeReferenceElement ref) {
if (resolved instanceof PsiClass && ((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC)) {
final PsiElement qualifier = ref.getQualifier();
PsiElement qualifier = ref.getQualifier();
if (qualifier instanceof PsiJavaCodeReferenceElement) {
final PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)qualifier).getParameterList();
PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)qualifier).getParameterList();
if (parameterList != null && parameterList.getTypeArguments().length > 0) {
final String message = JavaErrorBundle.message("generics.select.static.class.from.parameterized.type",
String message = JavaErrorBundle.message("generics.select.static.class.from.parameterized.type",
HighlightUtil.formatClass((PsiClass)resolved));
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parameterList).descriptionAndTooltip(message).create();
}
@@ -1376,13 +1376,13 @@ public final class GenericsHighlightUtil {
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();
PsiElement qualifier = parent.getQualifier();
if (qualifier instanceof PsiJavaCodeReferenceElement &&
((PsiJavaCodeReferenceElement)qualifier).getTypeParameters().length > 0 &&
resolved instanceof PsiTypeParameterListOwner &&
((PsiTypeParameterListOwner)resolved).hasTypeParameters() &&
!((PsiTypeParameterListOwner)resolved).hasModifierProperty(PsiModifier.STATIC)) {
final String message = JavaErrorBundle.message("text.improper.formed.type");
String message = JavaErrorBundle.message("text.improper.formed.type");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip(message).create();
}
return null;
@@ -1399,7 +1399,7 @@ public final class GenericsHighlightUtil {
String shortName = ((PsiClassType)type).getClassName();
PsiManager manager = parameterList.getManager();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
PsiShortNamesCache shortNamesCache = PsiShortNamesCache.getInstance(parameterList.getProject());
PsiClass[] classes = shortNamesCache.getClassesByName(shortName, GlobalSearchScope.allScope(manager.getProject()));
PsiElementFactory factory = facade.getElementFactory();
@@ -1426,10 +1426,10 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkInferredIntersections(@NotNull PsiSubstitutor substitutor, @NotNull PsiMethodCallExpression call) {
for (Map.Entry<PsiTypeParameter, PsiType> typeEntry : substitutor.getSubstitutionMap().entrySet()) {
final String parameterName = typeEntry.getKey().getName();
final PsiType type = typeEntry.getValue();
String parameterName = typeEntry.getKey().getName();
PsiType type = typeEntry.getValue();
if (type instanceof PsiIntersectionType) {
final String conflictingConjunctsMessage = ((PsiIntersectionType)type).getConflictingConjunctsMessage();
String conflictingConjunctsMessage = ((PsiIntersectionType)type).getConflictingConjunctsMessage();
if (conflictingConjunctsMessage != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip(
@@ -1454,11 +1454,11 @@ public final class GenericsHighlightUtil {
private static HighlightInfo.Builder checkClassSupersAccessibility(@NotNull PsiClass aClass,
@NotNull GlobalSearchScope resolveScope,
boolean checkParameters) {
final JavaPsiFacade factory = JavaPsiFacade.getInstance(aClass.getProject());
JavaPsiFacade factory = JavaPsiFacade.getInstance(aClass.getProject());
for (PsiClassType superType : aClass.getSuperTypes()) {
HashSet<PsiClass> checked = new HashSet<>();
checked.add(aClass);
final String notAccessibleErrorMessage = isTypeAccessible(superType, checked, checkParameters, resolveScope, factory);
String notAccessibleErrorMessage = isTypeAccessible(superType, checked, checkParameters, resolveScope, factory);
if (notAccessibleErrorMessage != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip(notAccessibleErrorMessage);
@@ -1470,15 +1470,15 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkMemberSignatureTypesAccessibility(@NotNull PsiReferenceExpression ref) {
String message = null;
final PsiElement parent = ref.getParent();
PsiElement parent = ref.getParent();
if (parent instanceof PsiMethodCallExpression) {
final JavaResolveResult resolveResult = ((PsiMethodCallExpression)parent).resolveMethodGenerics();
final PsiMethod method = (PsiMethod)resolveResult.getElement();
JavaResolveResult resolveResult = ((PsiMethodCallExpression)parent).resolveMethodGenerics();
PsiMethod method = (PsiMethod)resolveResult.getElement();
if (method != null) {
final Set<PsiClass> classes = new HashSet<>();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
final GlobalSearchScope resolveScope = ref.getResolveScope();
Set<PsiClass> classes = new HashSet<>();
JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
PsiSubstitutor substitutor = resolveResult.getSubstitutor();
GlobalSearchScope resolveScope = ref.getResolveScope();
message = isTypeAccessible(substitutor.substitute(method.getReturnType()), classes, false, resolveScope, facade);
if (message == null) {
@@ -1492,10 +1492,10 @@ public final class GenericsHighlightUtil {
}
}
else {
final PsiElement resolve = ref.resolve();
PsiElement resolve = ref.resolve();
if (resolve instanceof PsiField) {
final GlobalSearchScope resolveScope = ref.getResolveScope();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
GlobalSearchScope resolveScope = ref.getResolveScope();
JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
message = isTypeAccessible(((PsiField)resolve).getType(), new HashSet<>(), false, resolveScope, facade);
}
}
@@ -1518,7 +1518,7 @@ public final class GenericsHighlightUtil {
@NotNull JavaPsiFacade factory) {
type = PsiClassImplUtil.correctType(type, resolveScope);
final PsiClass aClass = PsiUtil.resolveClassInType(type);
PsiClass aClass = PsiUtil.resolveClassInType(type);
if (aClass != null && classes.add(aClass)) {
VirtualFile vFile = PsiUtilCore.getVirtualFile(aClass);
if (vFile == null) {
@@ -1529,7 +1529,7 @@ public final class GenericsHighlightUtil {
return null;
}
final String qualifiedName = aClass.getQualifiedName();
String qualifiedName = aClass.getQualifiedName();
if (qualifiedName != null && factory.findClass(qualifiedName, resolveScope) == null) {
return JavaErrorBundle.message("text.class.cannot.access", HighlightUtil.formatClass(aClass));
}
@@ -1540,7 +1540,7 @@ public final class GenericsHighlightUtil {
if (type instanceof PsiClassType) {
for (PsiType parameterType : ((PsiClassType)type).getParameters()) {
final String notAccessibleMessage = isTypeAccessible(parameterType, classes, true, resolveScope, factory);
String notAccessibleMessage = isTypeAccessible(parameterType, classes, true, resolveScope, factory);
if (notAccessibleMessage != null) {
return notAccessibleMessage;
}
@@ -1549,7 +1549,7 @@ public final class GenericsHighlightUtil {
boolean isInLibrary = !index.isInContent(vFile);
for (PsiClassType superType : aClass.getSuperTypes()) {
final String notAccessibleMessage = isTypeAccessible(superType, classes, !isInLibrary, resolveScope, factory);
String notAccessibleMessage = isTypeAccessible(superType, classes, !isInLibrary, resolveScope, factory);
if (notAccessibleMessage != null) {
return notAccessibleMessage;
}
@@ -1561,10 +1561,10 @@ public final class GenericsHighlightUtil {
static HighlightInfo checkTypeParameterOverrideEquivalentMethods(@NotNull PsiClass aClass, @NotNull LanguageLevel level) {
if (aClass instanceof PsiTypeParameter && level.isAtLeast(LanguageLevel.JDK_1_7)) {
final PsiReferenceList extendsList = aClass.getExtendsList();
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);
Collection<HighlightInfo> result = checkOverrideEquivalentMethods(aClass);
if (!result.isEmpty()) {
return result.iterator().next();
}

View File

@@ -85,7 +85,7 @@ public final class HighlightControlFlowUtil {
// see JLS 14.20 Unreachable Statements
try {
AllVariablesControlFlowPolicy policy = AllVariablesControlFlowPolicy.getInstance();
final ControlFlow controlFlow = ControlFlowFactory.getControlFlow(codeBlock, policy, ControlFlowOptions.NO_CONST_EVALUATE);
ControlFlow controlFlow = ControlFlowFactory.getControlFlow(codeBlock, policy, ControlFlowOptions.NO_CONST_EVALUATE);
PsiElement unreachableStatement = ControlFlowUtil.getUnreachableStatement(controlFlow);
if (unreachableStatement != null) {
if (unreachableStatement instanceof PsiCodeBlock && unreachableStatement.getParent() instanceof PsiBlockStatement) {
@@ -117,8 +117,8 @@ public final class HighlightControlFlowUtil {
unreachableStatement instanceof PsiLabeledStatement) {
keyword = unreachableStatement.getFirstChild();
}
final PsiElement element = keyword != null ? keyword : unreachableStatement;
final HighlightInfo info =
PsiElement element = keyword != null ? keyword : unreachableStatement;
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(
info, QUICK_FIX_FACTORY.createDeleteFix(unreachableStatement, QuickFixBundle.message("delete.unreachable.statement.fix.text")));
@@ -133,13 +133,13 @@ public final class HighlightControlFlowUtil {
public static boolean isFieldInitializedAfterObjectConstruction(@NotNull PsiField field) {
if (field.hasInitializer()) return true;
final boolean isFieldStatic = field.hasModifierProperty(PsiModifier.STATIC);
final PsiClass aClass = field.getContainingClass();
boolean isFieldStatic = field.hasModifierProperty(PsiModifier.STATIC);
PsiClass aClass = field.getContainingClass();
if (aClass != null) {
// field might be assigned in the other field initializers
if (isFieldInitializedInOtherFieldInitializer(aClass, field, isFieldStatic, __->true)) return true;
}
final PsiClassInitializer[] initializers;
PsiClassInitializer[] initializers;
if (aClass != null) {
initializers = aClass.getInitializers();
}
@@ -152,16 +152,16 @@ public final class HighlightControlFlowUtil {
}
else {
// instance field should be initialized at the end of each constructor
final PsiMethod[] constructors = aClass.getConstructors();
PsiMethod[] constructors = aClass.getConstructors();
if (constructors.length == 0) return false;
nextConstructor:
for (PsiMethod constructor : constructors) {
PsiCodeBlock ctrBody = constructor.getBody();
if (ctrBody == null) return false;
final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
for (PsiMethod redirectedConstructor : redirectedConstructors) {
final PsiCodeBlock body = redirectedConstructor.getBody();
PsiCodeBlock body = redirectedConstructor.getBody();
if (body != null && variableDefinitelyAssignedIn(field, body)) continue nextConstructor;
}
if (!ctrBody.isValid() || variableDefinitelyAssignedIn(field, ctrBody)) {
@@ -182,7 +182,7 @@ public final class HighlightControlFlowUtil {
private static boolean isFieldInitializedInOtherFieldInitializer(@NotNull PsiClass aClass,
@NotNull PsiField field,
final boolean fieldStatic,
boolean fieldStatic,
@NotNull Predicate<? super PsiField> condition) {
PsiField[] fields = aClass.getFields();
for (PsiField psiField : fields) {
@@ -197,7 +197,7 @@ public final class HighlightControlFlowUtil {
}
static boolean isRecursivelyCalledConstructor(@NotNull PsiMethod constructor) {
final JavaHighlightUtil.ConstructorVisitorInfo info = new JavaHighlightUtil.ConstructorVisitorInfo();
JavaHighlightUtil.ConstructorVisitorInfo info = new JavaHighlightUtil.ConstructorVisitorInfo();
JavaHighlightUtil.visitConstructorChain(constructor, info);
if (info.recursivelyCalledConstructor == null) return false;
// our constructor is reached from some other constructor by constructor chain
@@ -215,7 +215,7 @@ public final class HighlightControlFlowUtil {
private volatile boolean myIsWriteRefFound;
@Override
public boolean process(PsiReference reference) {
final PsiElement element = reference.getElement();
PsiElement element = reference.getElement();
if (element instanceof PsiReferenceExpression && PsiUtil.isAccessedForWriting((PsiExpression)element)) {
myIsWriteRefFound = true;
return false;
@@ -279,7 +279,7 @@ public final class HighlightControlFlowUtil {
QuickFixAction.registerQuickFixAction(highlightInfo, HighlightMethodUtil.getFixRange(field), QUICK_FIX_FACTORY.createCreateConstructorParameterFromFieldFix(field));
QuickFixAction.registerQuickFixAction(highlightInfo, HighlightMethodUtil.getFixRange(field), QUICK_FIX_FACTORY.createInitializeFinalFieldInConstructorFix(field));
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createAddVariableInitializerFix(field));
final PsiClass containingClass = field.getContainingClass();
PsiClass containingClass = field.getContainingClass();
if (containingClass != null && !containingClass.isInterface()) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createModifierListFix(field, PsiModifier.FINAL, false, false));
}
@@ -302,7 +302,7 @@ public final class HighlightControlFlowUtil {
if (variable instanceof ImplicitVariable) return null;
if (!PsiUtil.isAccessedForReading(expression)) return null;
int startOffset = expression.getTextRange().getStartOffset();
final PsiElement topBlock;
PsiElement topBlock;
if (variable.hasInitializer()) {
topBlock = PsiUtil.getVariableCodeBlock(variable, variable);
if (topBlock == null) return null;
@@ -326,18 +326,18 @@ public final class HighlightControlFlowUtil {
return null;
}
if (topBlock == null) return null;
final PsiElement parent = topBlock.getParent();
PsiElement parent = topBlock.getParent();
// access to final fields from inner classes always allowed
if (inInnerClass(expression, ((PsiField)variable).getContainingClass())) return null;
final PsiCodeBlock block;
final PsiClass aClass;
PsiCodeBlock block;
PsiClass aClass;
if (parent instanceof PsiMethod) {
PsiMethod constructor = (PsiMethod)parent;
if (!containingFile.getManager().areElementsEquivalent(constructor.getContainingClass(), ((PsiField)variable).getContainingClass())) return null;
// static variables already initialized in class initializers
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);
List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
for (PsiMethod redirectedConstructor : redirectedConstructors) {
// variable must be initialized before its usage
//???
@@ -352,7 +352,7 @@ public final class HighlightControlFlowUtil {
aClass = constructor.getContainingClass();
}
else if (parent instanceof PsiClassInitializer) {
final PsiClassInitializer classInitializer = (PsiClassInitializer)parent;
PsiClassInitializer classInitializer = (PsiClassInitializer)parent;
if (!containingFile.getManager().areElementsEquivalent(classInitializer.getContainingClass(), ((PsiField)variable).getContainingClass())) return null;
block = classInitializer.getBody();
aClass = classInitializer.getContainingClass();
@@ -362,10 +362,10 @@ public final class HighlightControlFlowUtil {
else {
// field reference outside code block
// check variable initialized before its usage
final PsiField field = (PsiField)variable;
PsiField field = (PsiField)variable;
aClass = field.getContainingClass();
final PsiField anotherField = PsiTreeUtil.getTopmostParentOfType(expression, PsiField.class);
PsiField anotherField = PsiTreeUtil.getTopmostParentOfType(expression, PsiField.class);
if (aClass == null ||
isFieldInitializedInOtherFieldInitializer(aClass, field, field.hasModifierProperty(PsiModifier.STATIC), psiField -> startOffset > psiField.getTextOffset())) {
return null;
@@ -381,7 +381,7 @@ public final class HighlightControlFlowUtil {
}
block = null;
// initializers will be checked later
final PsiMethod[] constructors = aClass.getConstructors();
PsiMethod[] constructors = aClass.getConstructors();
for (PsiMethod constructor : constructors) {
// variable must be initialized before its usage
if (offset < constructor.getTextRange().getStartOffset()) continue;
@@ -390,7 +390,7 @@ public final class HighlightControlFlowUtil {
return null;
}
// as a last chance, field may be initialized in this() call
final List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
List<PsiMethod> redirectedConstructors = JavaHighlightUtil.getChainedConstructors(constructor);
for (PsiMethod redirectedConstructor : redirectedConstructors) {
// variable must be initialized before its usage
if (offset < redirectedConstructor.getTextRange().getStartOffset()) continue;
@@ -404,7 +404,7 @@ public final class HighlightControlFlowUtil {
if (aClass != null) {
// field may be initialized in class initializer
final PsiClassInitializer[] initializers = aClass.getInitializers();
PsiClassInitializer[] initializers = aClass.getInitializers();
for (PsiClassInitializer initializer : initializers) {
PsiCodeBlock body = initializer.getBody();
if (body == block) break;
@@ -424,7 +424,7 @@ public final class HighlightControlFlowUtil {
Collection<PsiReferenceExpression> codeBlockProblems = uninitializedVarProblems.get(topBlock);
if (codeBlockProblems == null) {
try {
final ControlFlow controlFlow = getControlFlow(topBlock);
ControlFlow controlFlow = getControlFlow(topBlock);
codeBlockProblems = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
}
catch (AnalysisCanceledException | IndexNotReadyException e) {
@@ -433,7 +433,7 @@ public final class HighlightControlFlowUtil {
uninitializedVarProblems.put(topBlock, codeBlockProblems);
}
if (codeBlockProblems.contains(expression)) {
final String name = expression.getElement().getText();
String name = expression.getElement().getText();
String description = JavaErrorBundle.message("variable.not.initialized", name);
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
@@ -454,7 +454,7 @@ public final class HighlightControlFlowUtil {
private static boolean inInnerClass(@NotNull PsiElement psiElement, @Nullable PsiClass containingClass) {
for (PsiElement element = psiElement;element != null;element = element.getParent()) {
if (element instanceof PsiClass) {
final boolean innerClass = !psiElement.getManager().areElementsEquivalent(element, containingClass);
boolean innerClass = !psiElement.getManager().areElementsEquivalent(element, containingClass);
if (innerClass) {
if (element instanceof PsiAnonymousClass) {
if (PsiTreeUtil.isAncestor(((PsiAnonymousClass)element).getArgumentList(), psiElement, false)) {
@@ -462,7 +462,7 @@ public final class HighlightControlFlowUtil {
}
return !insideClassInitialization(containingClass, (PsiClass)element);
}
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(psiElement, PsiLambdaExpression.class);
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(psiElement, PsiLambdaExpression.class);
return lambdaExpression == null || !insideClassInitialization(containingClass, (PsiClass)element);
}
return false;
@@ -487,15 +487,15 @@ public final class HighlightControlFlowUtil {
public static boolean isReassigned(@NotNull PsiVariable variable,
@NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems) {
if (variable instanceof PsiLocalVariable) {
final PsiElement parent = variable.getParent();
PsiElement parent = variable.getParent();
if (parent == null) return false;
final PsiElement declarationScope = parent.getParent();
PsiElement declarationScope = parent.getParent();
if (declarationScope == null) return false;
Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = getFinalVariableProblemsInBlock(finalVarProblems, declarationScope);
return codeBlockProblems.contains(new ControlFlowUtil.VariableInfo(variable, null));
}
if (variable instanceof PsiParameter) {
final PsiParameter parameter = (PsiParameter)variable;
PsiParameter parameter = (PsiParameter)variable;
return isAssigned(parameter);
}
return false;
@@ -507,7 +507,7 @@ public final class HighlightControlFlowUtil {
@NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems) {
if (!PsiUtil.isAccessedForWriting(expression)) return null;
final PsiElement scope = variable instanceof PsiField ? variable.getParent() :
PsiElement scope = variable instanceof PsiField ? variable.getParent() :
variable.getParent() == null ? null : variable.getParent().getParent();
PsiElement codeBlock = PsiUtil.getTopLevelEnclosingCodeBlock(expression, scope);
if (codeBlock == null) return null;
@@ -526,7 +526,7 @@ public final class HighlightControlFlowUtil {
String description =
JavaErrorBundle.message(inLoop ? "variable.assigned.in.loop" : "variable.already.assigned", variable.getName());
final HighlightInfo highlightInfo =
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
if (canDefer) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createDeferFinalAssignmentFix(variable, expression));
@@ -538,10 +538,10 @@ public final class HighlightControlFlowUtil {
private static boolean isFieldInitializedInAnotherMember(@NotNull PsiField field,
@NotNull PsiReferenceExpression expression,
@NotNull PsiElement codeBlock) {
final PsiClass aClass = field.getContainingClass();
PsiClass aClass = field.getContainingClass();
if (aClass == null) return false;
boolean isFieldStatic = field.hasModifierProperty(PsiModifier.STATIC);
final PsiMember enclosingConstructorOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expression);
PsiMember enclosingConstructorOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expression);
if (!isFieldStatic) {
// constructor that delegates to another constructor cannot assign final fields
@@ -581,7 +581,7 @@ public final class HighlightControlFlowUtil {
Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = finalVarProblems.get(codeBlock);
if (codeBlockProblems == null) {
try {
final ControlFlow controlFlow = getControlFlow(codeBlock);
ControlFlow controlFlow = getControlFlow(codeBlock);
codeBlockProblems = ControlFlowUtil.getInitializedTwice(controlFlow);
codeBlockProblems = addReassignedInLoopProblems(codeBlockProblems, controlFlow);
}
@@ -632,13 +632,13 @@ public final class HighlightControlFlowUtil {
PsiReferenceExpression reference = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(operand), PsiReferenceExpression.class);
PsiVariable variable = reference == null ? null : ObjectUtils.tryCast(reference.resolve(), PsiVariable.class);
if (variable == null || !variable.hasModifierProperty(PsiModifier.FINAL)) return null;
final boolean canWrite = canWriteToFinal(variable, expression, reference, containingFile) && checkWriteToFinalInsideLambda(variable, reference) == null;
boolean canWrite = canWriteToFinal(variable, expression, reference, containingFile) && checkWriteToFinalInsideLambda(variable, reference) == null;
if (canWrite) return null;
final String name = variable.getName();
String name = variable.getName();
String description = JavaErrorBundle.message("assignment.to.final.variable", name);
final HighlightInfo highlightInfo =
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(reference).descriptionAndTooltip(description).create();
final PsiElement innerClass = getInnerClassVariableReferencedFrom(variable, expression);
PsiElement innerClass = getInnerClassVariableReferencedFrom(variable, expression);
if (innerClass == null || variable instanceof PsiField) {
HighlightFixUtil.registerMakeNotFinalAction(variable, highlightInfo);
}
@@ -661,7 +661,7 @@ public final class HighlightControlFlowUtil {
// assignment from within inner class is illegal always
PsiField field = (PsiField)variable;
if (innerClass != null && !containingFile.getManager().areElementsEquivalent(innerClass, field.getContainingClass())) return false;
final PsiMember enclosingCtrOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expression);
PsiMember enclosingCtrOrInitializer = PsiUtil.findEnclosingConstructorOrInitializer(expression);
return enclosingCtrOrInitializer != null &&
!(enclosingCtrOrInitializer instanceof PsiMethod &&
JavaPsiRecordUtil.isCompactConstructor((PsiMethod)enclosingCtrOrInitializer)) &&
@@ -689,23 +689,23 @@ public final class HighlightControlFlowUtil {
@NotNull PsiJavaCodeReferenceElement context,
@NotNull LanguageLevel languageLevel) {
if (variable.hasModifierProperty(PsiModifier.FINAL)) return null;
final PsiElement innerClass = getInnerClassVariableReferencedFrom(variable, context);
PsiElement innerClass = getInnerClassVariableReferencedFrom(variable, context);
if (innerClass instanceof PsiClass) {
if (variable instanceof PsiParameter) {
final PsiElement parent = variable.getParent();
PsiElement parent = variable.getParent();
if (parent instanceof PsiParameterList && parent.getParent() instanceof PsiLambdaExpression &&
!VariableAccessUtils.variableIsAssigned(variable, ((PsiParameter)variable).getDeclarationScope())) {
return null;
}
}
final boolean isToBeEffectivelyFinal = languageLevel.isAtLeast(LanguageLevel.JDK_1_8);
boolean isToBeEffectivelyFinal = languageLevel.isAtLeast(LanguageLevel.JDK_1_8);
if (isToBeEffectivelyFinal && isEffectivelyFinal(variable, innerClass, context)) {
return null;
}
final String description = JavaErrorBundle
String description = JavaErrorBundle
.message(isToBeEffectivelyFinal ? "variable.must.be.final.or.effectively.final" : "variable.must.be.final", context.getText());
final HighlightInfo highlightInfo =
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(context).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createVariableAccessFromInnerClassFix(variable, innerClass));
return highlightInfo;
@@ -719,9 +719,9 @@ public final class HighlightControlFlowUtil {
@Nullable
private static HighlightInfo checkWriteToFinalInsideLambda(@NotNull PsiVariable variable, @NotNull PsiJavaCodeReferenceElement context) {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
if (lambdaExpression != null && !PsiTreeUtil.isAncestor(lambdaExpression, variable, true)) {
final PsiElement parent = variable.getParent();
PsiElement parent = variable.getParent();
if (parent instanceof PsiParameterList && parent.getParent() == lambdaExpression) {
return null;
}
@@ -763,7 +763,7 @@ public final class HighlightControlFlowUtil {
effectivelyFinal = !VariableAccessUtils.variableIsAssigned(variable, ((PsiParameter)variable).getDeclarationScope());
}
else {
final ControlFlow controlFlow;
ControlFlow controlFlow;
try {
PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, context);
if (codeBlock == null) return true;
@@ -773,10 +773,10 @@ public final class HighlightControlFlowUtil {
return true;
}
final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
if (effectivelyFinal) {
final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
for (PsiReferenceExpression expression : readBeforeWriteLocals) {
if (expression.resolve() == variable) {
return PsiUtil.isAccessedForReading(expression);
@@ -798,12 +798,12 @@ public final class HighlightControlFlowUtil {
}
public static PsiElement getInnerClassVariableReferencedFrom(@NotNull PsiVariable variable, @NotNull PsiElement context) {
final PsiElement[] scope;
PsiElement[] scope;
if (variable instanceof PsiResourceVariable) {
scope = ((PsiResourceVariable)variable).getDeclarationScope();
}
else if (variable instanceof PsiLocalVariable) {
final PsiElement parent = variable.getParent();
PsiElement parent = variable.getParent();
scope = new PsiElement[]{parent != null ? parent.getParent() : null}; // code block or for statement
}
else if (variable instanceof PsiParameter) {
@@ -833,11 +833,11 @@ public final class HighlightControlFlowUtil {
}
static HighlightInfo checkInitializerCompleteNormally(@NotNull PsiClassInitializer initializer) {
final PsiCodeBlock body = initializer.getBody();
PsiCodeBlock body = initializer.getBody();
// unhandled exceptions already reported
try {
final ControlFlow controlFlow = getControlFlowNoConstantEvaluate(body);
final int completionReasons = ControlFlowUtil.getCompletionReasons(controlFlow, 0, controlFlow.getSize());
ControlFlow controlFlow = getControlFlowNoConstantEvaluate(body);
int completionReasons = ControlFlowUtil.getCompletionReasons(controlFlow, 0, controlFlow.getSize());
if (!BitUtil.isSet(completionReasons, ControlFlowUtil.NORMAL_COMPLETION_REASON)) {
String description = JavaErrorBundle.message("initializer.must.be.able.to.complete.normally");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(body).descriptionAndTooltip(description).create();

View File

@@ -188,18 +188,18 @@ public final class HighlightMethodUtil {
@NotNull @Nls String detailMessage,
@NotNull TextRange range,
@NotNull LanguageLevel languageLevel) {
final PsiClass superContainingClass = superMethod.getContainingClass();
PsiClass superContainingClass = superMethod.getContainingClass();
if (superContainingClass != null &&
CommonClassNames.JAVA_LANG_OBJECT.equals(superContainingClass.getQualifiedName()) &&
!superMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
final PsiClass containingClass = method.getContainingClass();
PsiClass containingClass = method.getContainingClass();
if (containingClass != null && containingClass.isInterface() && !superContainingClass.isInterface()) {
return null;
}
}
PsiType substitutedSuperReturnType;
final boolean isJdk15 = languageLevel.isAtLeast(LanguageLevel.JDK_1_5);
boolean isJdk15 = languageLevel.isAtLeast(LanguageLevel.JDK_1_5);
if (isJdk15 && !superMethodSignature.isRaw() && superMethodSignature.equals(methodSignature)) { //see 8.4.5
PsiSubstitutor unifyingSubstitutor = MethodSignatureUtil.getSuperMethodSignatureSubstitutor(methodSignature,
superMethodSignature);
@@ -242,7 +242,7 @@ public final class HighlightMethodUtil {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMethodReturnFix(method, substitutedSuperReturnType, false));
}
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createSuperMethodReturnFix(superMethod, returnType));
final PsiClass returnClass = PsiUtil.resolveClassInClassTypeOnly(returnType);
PsiClass returnClass = PsiUtil.resolveClassInClassTypeOnly(returnType);
if (returnClass != null && substitutedSuperReturnType instanceof PsiClassType) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createChangeParameterClassFix(returnClass, (PsiClassType)substitutedSuperReturnType));
}
@@ -316,7 +316,7 @@ public final class HighlightMethodUtil {
int index = getExtraExceptionNum(methodSignature, superMethodSignature, checkedExceptions, superSubstitutor);
if (index != -1) {
if (aClass.isInterface()) {
final PsiClass superContainingClass = superMethod.getContainingClass();
PsiClass superContainingClass = superMethod.getContainingClass();
if (superContainingClass != null && !superContainingClass.isInterface()) continue;
if (superContainingClass != null && !aClass.isInheritor(superContainingClass, true)) continue;
}
@@ -349,8 +349,8 @@ public final class HighlightMethodUtil {
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 ? TypeConversionUtil.erasure(checkedEx) : substitutorForMethod.substitute(checkedEx);
PsiClassType checkedEx = checkedExceptions.get(i);
PsiType substituted = substitutorForMethod == null ? TypeConversionUtil.erasure(checkedEx) : substitutorForMethod.substitute(checkedEx);
PsiType exception = substitutorForDerivedClass.substitute(substituted);
if (!isMethodThrows(superMethod, substitutorForMethod, exception, substitutorForDerivedClass)) {
return i;
@@ -388,7 +388,7 @@ public final class HighlightMethodUtil {
if (isDummy) return;
HighlightInfo highlightInfo;
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
PsiSubstitutor substitutor = resolveResult.getSubstitutor();
if (resolved instanceof PsiMethod && resolveResult.isValidResult()) {
highlightInfo = HighlightUtil.checkUnhandledExceptions(methodCall);
@@ -495,8 +495,8 @@ public final class HighlightMethodUtil {
String toolTip = null;
List<PsiExpression> mismatchedExpressions;
if (parent != null) {
final PsiExpression[] expressions = list.getExpressions();
final PsiParameter[] parameters = resolvedMethod.getParameterList().getParameters();
PsiExpression[] expressions = list.getExpressions();
PsiParameter[] parameters = resolvedMethod.getParameterList().getParameters();
mismatchedExpressions = mismatchedArgs(expressions, substitutor, parameters, candidateInfo.isVarargs());
if (mismatchedExpressions.size() == 1) {
toolTip = createOneArgMismatchTooltip(candidateInfo, mismatchedExpressions, expressions, parameters);
@@ -540,8 +540,8 @@ public final class HighlightMethodUtil {
@NotNull List<? extends PsiExpression> mismatchedExpressions,
PsiExpression[] expressions,
PsiParameter[] parameters) {
final PsiExpression wrongArg = mismatchedExpressions.get(0);
final PsiType argType = wrongArg.getType();
PsiExpression wrongArg = mismatchedExpressions.get(0);
PsiType argType = wrongArg.getType();
if (argType != null) {
if ((parameters.length == 0 || !parameters[parameters.length - 1].isVarArgs()) && parameters.length != expressions.length) {
return createMismatchedArgumentCountTooltip(parameters, expressions);
@@ -691,10 +691,10 @@ public final class HighlightMethodUtil {
@NotNull MethodCandidateInfo candidate,
@NotNull PsiCall methodCall) {
if (candidate.getInferenceErrorMessage() != null && methodCall.getParent() instanceof PsiReturnStatement) {
final PsiMethod containerMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class, true, PsiLambdaExpression.class);
PsiMethod containerMethod = PsiTreeUtil.getParentOfType(methodCall, PsiMethod.class, true, PsiLambdaExpression.class);
if (containerMethod != null) {
final PsiMethod method = candidate.getElement();
final PsiExpression methodCallCopy =
PsiMethod method = candidate.getElement();
PsiExpression methodCallCopy =
JavaPsiFacade.getElementFactory(method.getProject()).createExpressionFromText(methodCall.getText(), methodCall);
PsiType methodCallTypeByArgs = methodCallCopy.getType();
//ensure type params are not included
@@ -816,7 +816,7 @@ public final class HighlightMethodUtil {
static HighlightInfo checkAmbiguousMethodCallArguments(@NotNull PsiReferenceExpression referenceToMethod,
JavaResolveResult @NotNull [] resolveResults,
@NotNull PsiExpressionList list,
final PsiElement element,
PsiElement element,
@NotNull JavaResolveResult resolveResult,
@NotNull PsiMethodCallExpression methodCall,
@NotNull PsiResolveHelper resolveHelper,
@@ -921,9 +921,9 @@ public final class HighlightMethodUtil {
@NotNull PsiExpressionList list,
@NotNull PsiResolveHelper resolveHelper) {
TextRange fixRange = getFixRange(methodCall);
final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression();
PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression();
if (qualifierExpression instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression)qualifierExpression).resolve();
PsiElement resolve = ((PsiReferenceExpression)qualifierExpression).resolve();
if (resolve instanceof PsiClass &&
((PsiClass)resolve).getContainingClass() != null &&
!((PsiClass)resolve).hasModifierProperty(PsiModifier.STATIC)) {
@@ -1263,7 +1263,7 @@ public final class HighlightMethodUtil {
boolean isPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
boolean isConstructor = method.isConstructor();
final List<IntentionAction> additionalFixes = new ArrayList<>();
List<IntentionAction> additionalFixes = new ArrayList<>();
String description = null;
if (hasNoBody) {
if (isExtension) {
@@ -1408,18 +1408,18 @@ public final class HighlightMethodUtil {
PsiClass aClass = method.getContainingClass();
if (aClass == null) return null;
final HierarchicalMethodSignature methodSignature = PsiSuperMethodImplUtil.getHierarchicalMethodSignature(method);
final List<HierarchicalMethodSignature> superSignatures = methodSignature.getSuperSignatures();
HierarchicalMethodSignature methodSignature = PsiSuperMethodImplUtil.getHierarchicalMethodSignature(method);
List<HierarchicalMethodSignature> superSignatures = methodSignature.getSuperSignatures();
if (superSignatures.isEmpty()) {
return null;
}
boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC);
for (HierarchicalMethodSignature signature : superSignatures) {
final PsiMethod superMethod = signature.getMethod();
final PsiClass superClass = superMethod.getContainingClass();
PsiMethod superMethod = signature.getMethod();
PsiClass superClass = superMethod.getContainingClass();
if (superClass == null) continue;
final HighlightInfo highlightInfo = checkStaticMethodOverride(aClass, method, isStatic, superClass, superMethod, containingFile);
HighlightInfo highlightInfo = checkStaticMethodOverride(aClass, method, isStatic, superClass, superMethod, containingFile);
if (highlightInfo != null) {
return highlightInfo;
}
@@ -1445,7 +1445,7 @@ public final class HighlightMethodUtil {
boolean isSuperMethodStatic = superModifierList.hasModifierProperty(PsiModifier.STATIC);
if (isMethodStatic != isSuperMethodStatic) {
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
final String messageKey = isMethodStatic
String messageKey = isMethodStatic
? "static.method.cannot.override.instance.method"
: "instance.method.cannot.override.static.method";
@@ -1482,7 +1482,7 @@ public final class HighlightMethodUtil {
private static HighlightInfo checkInterfaceInheritedMethodsReturnTypes(@NotNull List<? extends MethodSignatureBackedByPsiMethod> superMethodSignatures,
@NotNull LanguageLevel languageLevel) {
if (superMethodSignatures.size() < 2) return null;
final MethodSignatureBackedByPsiMethod[] returnTypeSubstitutable = {superMethodSignatures.get(0)};
MethodSignatureBackedByPsiMethod[] returnTypeSubstitutable = {superMethodSignatures.get(0)};
for (int i = 1; i < superMethodSignatures.size(); i++) {
PsiMethod currentMethod = returnTypeSubstitutable[0].getMethod();
PsiType currentType = returnTypeSubstitutable[0].getSubstitutor().substitute(currentMethod.getReturnType());
@@ -1501,7 +1501,7 @@ public final class HighlightMethodUtil {
if (otherSuperReturnType == null || currentType == null || otherSuperReturnType.equals(currentType)) continue;
PsiType otherReturnType = otherSuperReturnType;
PsiType curType = currentType;
final HighlightInfo info =
HighlightInfo info =
LambdaUtil.performWithSubstitutedParameterBounds(otherSuperMethod.getTypeParameters(), otherSubstitutor, () -> {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) {
//http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8 Example 8.1.5-3
@@ -1527,7 +1527,7 @@ public final class HighlightMethodUtil {
@NotNull LanguageLevel languageLevel) {
String description = null;
boolean appendImplementMethodFix = true;
final Collection<HierarchicalMethodSignature> visibleSignatures = aClass.getVisibleSignatures();
Collection<HierarchicalMethodSignature> visibleSignatures = aClass.getVisibleSignatures();
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(aClass.getProject()).getResolveHelper();
Ultimate:
@@ -1586,7 +1586,7 @@ public final class HighlightMethodUtil {
if (description != null) {
// show error info at the class level
TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
if (appendImplementMethodFix) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createImplementMethodsFix(aClass));
}
@@ -1688,7 +1688,7 @@ public final class HighlightMethodUtil {
if (list == null) return;
PsiClass aClass = typeResolveResult.getElement();
if (aClass == null) return;
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(holder.getProject()).getResolveHelper();
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(holder.getProject()).getResolveHelper();
PsiClass accessObjectClass = null;
if (constructorCall instanceof PsiNewExpression) {
PsiExpression qualifier = ((PsiNewExpression)constructorCall).getQualifier();
@@ -1725,7 +1725,7 @@ public final class HighlightMethodUtil {
if (classReference != null && aClass.hasModifierProperty(PsiModifier.PROTECTED) && callingProtectedConstructorFromDerivedClass(constructorCall, aClass)) {
holder.add(buildAccessProblem(classReference, aClass, typeResolveResult));
} else if (aClass.isInterface() && constructorCall instanceof PsiNewExpression) {
final PsiReferenceParameterList typeArgumentList = ((PsiNewExpression)constructorCall).getTypeArgumentList();
PsiReferenceParameterList typeArgumentList = ((PsiNewExpression)constructorCall).getTypeArgumentList();
if (typeArgumentList.getTypeArguments().length > 0) {
holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeArgumentList)
.descriptionAndTooltip(JavaErrorBundle.message("anonymous.class.implements.interface.cannot.have.type.arguments")).create());
@@ -1735,7 +1735,7 @@ public final class HighlightMethodUtil {
else {
PsiElement place = list;
if (constructorCall instanceof PsiNewExpression) {
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)constructorCall).getAnonymousClass();
PsiAnonymousClass anonymousClass = ((PsiNewExpression)constructorCall).getAnonymousClass();
if (anonymousClass != null) place = anonymousClass;
}
@@ -1747,8 +1747,8 @@ public final class HighlightMethodUtil {
boolean applicable = true;
try {
final PsiDiamondType diamondType = constructorCall instanceof PsiNewExpression ? PsiDiamondType.getDiamondType((PsiNewExpression)constructorCall) : null;
final JavaResolveResult staticFactory = diamondType != null ? diamondType.getStaticFactory() : null;
PsiDiamondType diamondType = constructorCall instanceof PsiNewExpression ? PsiDiamondType.getDiamondType((PsiNewExpression)constructorCall) : null;
JavaResolveResult staticFactory = diamondType != null ? diamondType.getStaticFactory() : null;
if (staticFactory instanceof MethodCandidateInfo) {
if (((MethodCandidateInfo)staticFactory).isApplicable()) {
result = (MethodCandidateInfo)staticFactory;
@@ -1820,14 +1820,14 @@ public final class HighlightMethodUtil {
* 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(@NotNull MethodCandidateInfo info, @NotNull PsiCall place) {
final PsiMethod method = info.getElement();
PsiMethod method = info.getElement();
if (info.isVarargs() || method.isVarArgs() && !PsiUtil.isLanguageLevel8OrHigher(place)) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiType componentType = ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
final PsiType substitutedTypeErasure = TypeConversionUtil.erasure(info.getSubstitutor().substitute(componentType));
final PsiClass targetClass = PsiUtil.resolveClassInClassTypeOnly(substitutedTypeErasure);
PsiParameter[] parameters = method.getParameterList().getParameters();
PsiType componentType = ((PsiEllipsisType)parameters[parameters.length - 1].getType()).getComponentType();
PsiType substitutedTypeErasure = TypeConversionUtil.erasure(info.getSubstitutor().substitute(componentType));
PsiClass targetClass = PsiUtil.resolveClassInClassTypeOnly(substitutedTypeErasure);
if (targetClass != null && !PsiUtil.isAccessible(targetClass, place, null)) {
final PsiExpressionList argumentList = place.getArgumentList();
PsiExpressionList argumentList = place.getArgumentList();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.descriptionAndTooltip(JavaErrorBundle.message("formal.varargs.element.type.inaccessible.here",
PsiFormatUtil.formatClass(targetClass, PsiFormatUtilBase.SHOW_FQ_NAME)))
@@ -1844,7 +1844,7 @@ public final class HighlightMethodUtil {
@NotNull PsiClass aClass,
PsiMethod @NotNull [] constructors,
JavaResolveResult @NotNull [] results,
@NotNull final HighlightInfo info,
@NotNull HighlightInfo info,
TextRange fixRange) {
if (classReference != null) {
ConstructorParametersFixer.registerFixActions(classReference, constructorCall, info, fixRange);
@@ -1906,18 +1906,18 @@ public final class HighlightMethodUtil {
private static void registerChangeParameterClassFix(@NotNull PsiCall methodCall,
@NotNull PsiExpressionList list,
@Nullable HighlightInfo highlightInfo, TextRange fixRange) {
final JavaResolveResult result = methodCall.resolveMethodGenerics();
JavaResolveResult result = methodCall.resolveMethodGenerics();
PsiMethod method = (PsiMethod)result.getElement();
final PsiSubstitutor substitutor = result.getSubstitutor();
PsiSubstitutor substitutor = result.getSubstitutor();
PsiExpression[] expressions = list.getExpressions();
if (method == null) return;
final PsiParameter[] parameters = method.getParameterList().getParameters();
PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length != expressions.length) return;
for (int i = 0; i < expressions.length; i++) {
final PsiExpression expression = expressions[i];
final PsiParameter parameter = parameters[i];
final PsiType expressionType = expression.getType();
final PsiType parameterType = substitutor.substitute(parameter.getType());
PsiExpression expression = expressions[i];
PsiParameter parameter = parameters[i];
PsiType expressionType = expression.getType();
PsiType parameterType = substitutor.substitute(parameter.getType());
if (expressionType == null || expressionType instanceof PsiPrimitiveType || TypeConversionUtil.isNullType(expressionType) || expressionType instanceof PsiArrayType) continue;
if (parameterType instanceof PsiPrimitiveType || TypeConversionUtil.isNullType(parameterType) || parameterType instanceof PsiArrayType) continue;
if (parameterType.isAssignableFrom(expressionType)) continue;

View File

@@ -39,7 +39,7 @@ public final class HighlightNamesUtil {
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMember methodOrClass,
@NotNull PsiElement elementToHighlight,
final boolean isDeclaration,
boolean isDeclaration,
@NotNull TextAttributesScheme colorsScheme) {
boolean isInherited = false;
boolean isStaticallyImported = false;
@@ -47,7 +47,7 @@ public final class HighlightNamesUtil {
if (!isDeclaration) {
isStaticallyImported = isStaticallyImported(elementToHighlight);
if (isCalledOnThis(elementToHighlight)) {
final PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
while (enclosingClass != null) {
isInherited = enclosingClass.isInheritor(containingClass, true);
@@ -126,7 +126,7 @@ public final class HighlightNamesUtil {
static HighlightInfo highlightClassName(@Nullable PsiClass aClass, @NotNull PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme) {
TextRange range = elementToHighlight.getTextRange();
if (elementToHighlight instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)elementToHighlight;
PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)elementToHighlight;
PsiElement identifier = referenceElement.getReferenceNameElement();
if (identifier != null) {
range = identifier.getTextRange();
@@ -134,9 +134,9 @@ public final class HighlightNamesUtil {
}
// This will highlight @ sign in annotation as well.
final PsiElement parent = elementToHighlight.getParent();
PsiElement parent = elementToHighlight.getParent();
if (parent instanceof PsiAnnotation) {
final PsiAnnotation psiAnnotation = (PsiAnnotation)parent;
PsiAnnotation psiAnnotation = (PsiAnnotation)parent;
range = new TextRange(psiAnnotation.getTextRange().getStartOffset(), range.getEndOffset());
}
@@ -233,7 +233,7 @@ public final class HighlightNamesUtil {
if (aClass.isInterface()) return JavaHighlightInfoTypes.INTERFACE_NAME;
if (aClass.isEnum()) return JavaHighlightInfoTypes.ENUM_NAME;
if (aClass instanceof PsiTypeParameter) return JavaHighlightInfoTypes.TYPE_PARAMETER_NAME;
final PsiModifierList modList = aClass.getModifierList();
PsiModifierList modList = aClass.getModifierList();
if (modList != null && modList.hasModifierProperty(PsiModifier.ABSTRACT)) return JavaHighlightInfoTypes.ABSTRACT_CLASS_NAME;
}
// use class by default
@@ -276,13 +276,13 @@ public final class HighlightNamesUtil {
DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl)DependencyValidationManager.getInstance(file.getProject());
List<Pair<NamedScope,NamedScopesHolder>> scopes = validationManager.getScopeBasedHighlightingCachedScopes();
for (Pair<NamedScope, NamedScopesHolder> scope : scopes) {
final NamedScope namedScope = scope.getFirst();
final TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getScopeId());
final TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
NamedScope namedScope = scope.getFirst();
TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getScopeId());
TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
if (attributes == null || attributes.isEmpty()) {
continue;
}
final PackageSet packageSet = namedScope.getValue();
PackageSet packageSet = namedScope.getValue();
if (packageSet != null && packageSet.contains(file, scope.getSecond())) {
result = TextAttributes.merge(attributes, result);
}
@@ -294,7 +294,7 @@ public final class HighlightNamesUtil {
public static TextRange getMethodDeclarationTextRange(@NotNull PsiMethod method) {
if (method instanceof SyntheticElement) return TextRange.EMPTY_RANGE;
int start = stripAnnotationsFromModifierList(method.getModifierList());
final TextRange throwsRange = method.getThrowsList().getTextRange();
TextRange throwsRange = method.getThrowsList().getTextRange();
LOG.assertTrue(throwsRange != null, method);
int end = throwsRange.getEndOffset();
return new TextRange(start, end);
@@ -312,7 +312,7 @@ public final class HighlightNamesUtil {
if (aClass instanceof PsiEnumConstantInitializer) {
return ((PsiEnumConstantInitializer)aClass).getEnumConstant().getNameIdentifier().getTextRange();
}
final PsiElement psiElement = aClass instanceof PsiAnonymousClass
PsiElement psiElement = aClass instanceof PsiAnonymousClass
? ((PsiAnonymousClass)aClass).getBaseClassReference()
: aClass.getModifierList() == null ? aClass.getNameIdentifier() : aClass.getModifierList();
if(psiElement == null) return new TextRange(aClass.getTextRange().getStartOffset(), aClass.getTextRange().getStartOffset());

View File

@@ -174,9 +174,9 @@ public final class HighlightUtil {
Set<String> incompatibles = incompatibleModifiersHash.get(modifier);
if (incompatibles == null) return null;
final PsiElement parent = modifierList.getParent();
final boolean level8OrHigher = PsiUtil.isLanguageLevel8OrHigher(modifierList);
final boolean level9OrHigher = PsiUtil.isLanguageLevel9OrHigher(modifierList);
PsiElement parent = modifierList.getParent();
boolean level8OrHigher = PsiUtil.isLanguageLevel8OrHigher(modifierList);
boolean level9OrHigher = PsiUtil.isLanguageLevel9OrHigher(modifierList);
for (@PsiModifier.ModifierConstant String incompatible : incompatibles) {
if (level8OrHigher) {
if (modifier.equals(PsiModifier.STATIC) && incompatible.equals(PsiModifier.ABSTRACT)) {
@@ -189,7 +189,7 @@ public final class HighlightUtil {
}
if (modifier.equals(PsiModifier.STATIC) && incompatible.equals(PsiModifier.FINAL)) {
final PsiClass containingClass = ((PsiMethod)parent).getContainingClass();
PsiClass containingClass = ((PsiMethod)parent).getContainingClass();
if (containingClass == null || !containingClass.isInterface()) {
continue;
}
@@ -245,18 +245,18 @@ public final class HighlightUtil {
HighlightInfo info = checkFeature(expression, HighlightingFeature.INTERSECTION_CASTS, languageLevel, file);
if (info != null) return info;
final PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class);
PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class);
if (conjuncts != null) {
final Set<PsiType> erasures = new HashSet<>(conjuncts.length);
Set<PsiType> erasures = new HashSet<>(conjuncts.length);
erasures.add(TypeConversionUtil.erasure(conjuncts[0].getType()));
final List<PsiTypeElement> conjList = new ArrayList<>(Arrays.asList(conjuncts));
List<PsiTypeElement> conjList = new ArrayList<>(Arrays.asList(conjuncts));
for (int i = 1; i < conjuncts.length; i++) {
final PsiTypeElement conjunct = conjuncts[i];
final PsiType conjType = conjunct.getType();
PsiTypeElement conjunct = conjuncts[i];
PsiType conjType = conjunct.getType();
if (conjType instanceof PsiClassType) {
final PsiClass aClass = ((PsiClassType)conjType).resolve();
PsiClass aClass = ((PsiClassType)conjType).resolve();
if (aClass != null && !aClass.isInterface()) {
final HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(conjunct)
.descriptionAndTooltip(JavaErrorBundle.message("interface.expected")).create();
QuickFixAction
@@ -271,7 +271,7 @@ public final class HighlightUtil {
.descriptionAndTooltip(JavaErrorBundle.message("unexpected.type.class.expected")).create();
}
if (!erasures.add(TypeConversionUtil.erasure(conjType))) {
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(conjunct)
.descriptionAndTooltip(JavaErrorBundle.message("repeated.interface")).create();
QuickFixAction.registerQuickFixAction(highlightInfo, new DeleteRepeatedInterfaceFix(conjunct, conjList), null);
@@ -279,9 +279,9 @@ public final class HighlightUtil {
}
}
final List<PsiType> typeList = ContainerUtil.map(conjList, PsiTypeElement::getType);
final Ref<@Nls String> differentArgumentsMessage = new Ref<>();
final PsiClass sameGenericParameterization =
List<PsiType> typeList = ContainerUtil.map(conjList, PsiTypeElement::getType);
Ref<@Nls String> differentArgumentsMessage = new Ref<>();
PsiClass sameGenericParameterization =
InferenceSession.findParameterizationOfTheSameGenericClass(typeList, pair -> {
if (!TypesDistinctProver.provablyDistinct(pair.first, pair.second)) {
return true;
@@ -291,7 +291,7 @@ public final class HighlightUtil {
return false;
});
if (sameGenericParameterization != null) {
final String message = JavaErrorBundle
String message = JavaErrorBundle
.message("class.cannot.be.inherited.with.different.arguments", formatClass(sameGenericParameterization),
differentArgumentsMessage.get());
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
@@ -310,7 +310,7 @@ public final class HighlightUtil {
}
static HighlightInfo checkInconvertibleTypeCast(@NotNull PsiTypeCastExpression expression) {
final PsiTypeElement castTypeElement = expression.getCastType();
PsiTypeElement castTypeElement = expression.getCastType();
if (castTypeElement == null) return null;
PsiType castType = castTypeElement.getType();
@@ -357,10 +357,10 @@ public final class HighlightUtil {
IElementType eqOpSign = operationSign.getTokenType();
IElementType opSign = TypeConversionUtil.convertEQtoOperation(eqOpSign);
if (opSign == null) return null;
final PsiType lType = assignment.getLExpression().getType();
final PsiExpression rExpression = assignment.getRExpression();
PsiType lType = assignment.getLExpression().getType();
PsiExpression rExpression = assignment.getRExpression();
if (rExpression == null) return null;
final PsiType rType = rExpression.getType();
PsiType rType = rExpression.getType();
HighlightInfo errorResult = null;
if (!TypeConversionUtil.isBinaryOperatorApplicable(opSign, lType, rType, true)) {
String operatorText = operationSign.getText().substring(0, operationSign.getText().length() - 1);
@@ -382,15 +382,15 @@ public final class HighlightUtil {
PsiType rType = rExpr.getType();
if (rType == null) return null;
final IElementType sign = assignment.getOperationTokenType();
IElementType sign = assignment.getOperationTokenType();
HighlightInfo highlightInfo;
if (JavaTokenType.EQ.equals(sign)) {
highlightInfo = checkAssignability(lType, rType, rExpr, assignment);
}
else {
// 15.26.2. Compound Assignment Operators
final IElementType opSign = TypeConversionUtil.convertEQtoOperation(sign);
final PsiType type = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, opSign, true);
IElementType opSign = TypeConversionUtil.convertEQtoOperation(sign);
PsiType type = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, opSign, true);
if (type == null || lType == null || TypeConversionUtil.areTypesConvertible(type, lType)) {
return null;
}
@@ -586,7 +586,7 @@ public final class HighlightUtil {
else {
PsiType returnType = method != null ? method.getReturnType() : null/*JSP page returns void*/;
boolean isMethodVoid = returnType == null || PsiType.VOID.equals(returnType);
final PsiExpression returnValue = statement.getReturnValue();
PsiExpression returnValue = statement.getReturnValue();
if (returnValue != null) {
PsiType valueType = RefactoringChangeUtil.getTypeByExpression(returnValue);
if (isMethodVoid) {
@@ -603,7 +603,7 @@ public final class HighlightUtil {
errorResult = checkAssignability(returnType, valueType, returnValue, textRange, returnValue.getStartOffsetInParent());
if (errorResult != null && valueType != null) {
if (returnType instanceof PsiArrayType) {
final PsiType erasedValueType = TypeConversionUtil.erasure(valueType);
PsiType erasedValueType = TypeConversionUtil.erasure(valueType);
if (erasedValueType != null &&
TypeConversionUtil.isAssignable(((PsiArrayType)returnType).getComponentType(), erasedValueType)) {
QuickFixAction.registerQuickFixAction(errorResult, getFixFactory().createSurroundWithArrayFix(null, returnValue));
@@ -639,7 +639,7 @@ public final class HighlightUtil {
@NotNull
private static @NlsContexts.DetailedDescription String getUnhandledExceptionsDescriptor(@NotNull Collection<? extends PsiClassType> unhandled,
@Nullable @Nls String source) {
final String exceptions = formatTypes(unhandled);
String exceptions = formatTypes(unhandled);
return source == null
? JavaErrorBundle.message("unhandled.exceptions", exceptions, unhandled.size())
: JavaErrorBundle.message("unhandled.close.exceptions", exceptions, unhandled.size(), source);
@@ -663,7 +663,7 @@ public final class HighlightUtil {
PsiTreeUtil.getParentOfType(variable, PsiFile.class, PsiMethod.class, PsiClassInitializer.class, PsiResourceList.class);
VariablesNotProcessor proc = new VariablesNotProcessor(variable, false) {
@Override
protected boolean check(final PsiVariable var, final ResolveState state) {
protected boolean check(PsiVariable var, ResolveState state) {
return PsiUtil.isJvmLocalVariable(var) && super.check(var, state);
}
};
@@ -707,7 +707,7 @@ public final class HighlightUtil {
VirtualFile vFile = PsiUtilCore.getVirtualFile(identifier);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(identifier);
if (vFile != null) {
final String path = FileUtil.toSystemIndependentName(vFile.getPath());
String path = FileUtil.toSystemIndependentName(vFile.getPath());
String linkText = "<a href=\"#navigation/" + path + ":" + oldVariable.getTextOffset() + "\">" + variable.getName() + "</a>";
builder = builder.description(description)
.escapedToolTip("<html>" + JavaErrorBundle.message("variable.already.defined", linkText) + "</html>");
@@ -730,7 +730,7 @@ public final class HighlightUtil {
PatternResolveState hint = PatternResolveState.WHEN_TRUE;
VariablesNotProcessor proc = new VariablesNotProcessor(variable, false) {
@Override
protected boolean check(final PsiVariable var, final ResolveState state) {
protected boolean check(PsiVariable var, ResolveState state) {
return var instanceof PsiPatternVariable && super.check(var, state);
}
};
@@ -1147,13 +1147,13 @@ public final class HighlightUtil {
if (file != null) {
if (isFP) {
if (text.startsWith(PsiLiteralUtil.HEX_PREFIX)) {
final HighlightInfo info = checkFeature(expression, HighlightingFeature.HEX_FP_LITERALS, level, file);
HighlightInfo info = checkFeature(expression, HighlightingFeature.HEX_FP_LITERALS, level, file);
if (info != null) return info;
}
}
if (isInt) {
if (text.startsWith(PsiLiteralUtil.BIN_PREFIX)) {
final HighlightInfo info = checkFeature(expression, HighlightingFeature.BIN_LITERALS, level, file);
HighlightInfo info = checkFeature(expression, HighlightingFeature.BIN_LITERALS, level, file);
if (info != null) return info;
}
}
@@ -1167,7 +1167,7 @@ public final class HighlightUtil {
}
}
final PsiElement parent = expression.getParent();
PsiElement parent = expression.getParent();
if (type == JavaTokenType.INTEGER_LITERAL) {
String cleanText = StringUtil.replace(text, "_", "");
//literal 2147483648 may appear only as the operand of the unary negation operator -.
@@ -1302,13 +1302,13 @@ public final class HighlightUtil {
}
else {
if (file != null && containsUnescaped(text, "\\\n")) {
final HighlightInfo info = checkFeature(expression, HighlightingFeature.TEXT_BLOCK_ESCAPES, level, file);
HighlightInfo info = checkFeature(expression, HighlightingFeature.TEXT_BLOCK_ESCAPES, level, file);
if (info != null) return info;
}
}
}
if (file != null && containsUnescaped(text, "\\s")) {
final HighlightInfo info = checkFeature(expression, HighlightingFeature.TEXT_BLOCK_ESCAPES, level, file);
HighlightInfo info = checkFeature(expression, HighlightingFeature.TEXT_BLOCK_ESCAPES, level, file);
if (info != null) return info;
}
}
@@ -1404,10 +1404,10 @@ public final class HighlightUtil {
}
private static HighlightInfo createMustBeBooleanInfo(@NotNull PsiExpression expr, @Nullable PsiType type) {
final HighlightInfo info = createIncompatibleTypeHighlightInfo(PsiType.BOOLEAN, type, expr.getTextRange(), 0);
HighlightInfo info = createIncompatibleTypeHighlightInfo(PsiType.BOOLEAN, type, expr.getTextRange(), 0);
if (expr instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expr;
final PsiMethod method = methodCall.resolveMethod();
PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expr;
PsiMethod method = methodCall.resolveMethod();
if (method != null) {
QuickFixAction.registerQuickFixAction(info, getFixFactory().createMethodReturnFix(method, PsiType.BOOLEAN, true));
}
@@ -1420,15 +1420,15 @@ public final class HighlightUtil {
@NotNull
static Set<PsiClassType> collectUnhandledExceptions(@NotNull final PsiTryStatement statement) {
final Set<PsiClassType> thrownTypes = new HashSet<>();
static Set<PsiClassType> collectUnhandledExceptions(@NotNull PsiTryStatement statement) {
Set<PsiClassType> thrownTypes = new HashSet<>();
final PsiCodeBlock tryBlock = statement.getTryBlock();
PsiCodeBlock tryBlock = statement.getTryBlock();
if (tryBlock != null) {
thrownTypes.addAll(ExceptionUtil.collectUnhandledExceptions(tryBlock, tryBlock));
}
final PsiResourceList resources = statement.getResourceList();
PsiResourceList resources = statement.getResourceList();
if (resources != null) {
thrownTypes.addAll(ExceptionUtil.collectUnhandledExceptions(resources, resources));
}
@@ -1437,12 +1437,12 @@ public final class HighlightUtil {
}
@NotNull
static List<HighlightInfo> checkExceptionThrownInTry(@NotNull final PsiParameter parameter,
@NotNull final Set<? extends PsiClassType> thrownTypes) {
final PsiElement declarationScope = parameter.getDeclarationScope();
static List<HighlightInfo> checkExceptionThrownInTry(@NotNull PsiParameter parameter,
@NotNull Set<? extends PsiClassType> thrownTypes) {
PsiElement declarationScope = parameter.getDeclarationScope();
if (!(declarationScope instanceof PsiCatchSection)) return Collections.emptyList();
final PsiType caughtType = parameter.getType();
PsiType caughtType = parameter.getType();
if (caughtType instanceof PsiClassType) {
HighlightInfo info = checkSimpleCatchParameter(parameter, thrownTypes, (PsiClassType)caughtType);
return info == null ? Collections.emptyList() : Collections.singletonList(info);
@@ -1454,30 +1454,30 @@ public final class HighlightUtil {
return Collections.emptyList();
}
private static HighlightInfo checkSimpleCatchParameter(@NotNull final PsiParameter parameter,
@NotNull final Collection<? extends PsiClassType> thrownTypes,
@NotNull final PsiClassType caughtType) {
private static HighlightInfo checkSimpleCatchParameter(@NotNull PsiParameter parameter,
@NotNull Collection<? extends PsiClassType> thrownTypes,
@NotNull PsiClassType caughtType) {
if (ExceptionUtil.isUncheckedExceptionOrSuperclass(caughtType)) return null;
for (PsiClassType exceptionType : thrownTypes) {
if (exceptionType.isAssignableFrom(caughtType) || caughtType.isAssignableFrom(exceptionType)) return null;
}
final String description = JavaErrorBundle.message("exception.never.thrown.try", JavaHighlightUtil.formatType(caughtType));
final HighlightInfo errorResult =
String description = JavaErrorBundle.message("exception.never.thrown.try", JavaHighlightUtil.formatType(caughtType));
HighlightInfo errorResult =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parameter).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(errorResult, getFixFactory().createDeleteCatchFix(parameter));
return errorResult;
}
@NotNull
private static List<HighlightInfo> checkMultiCatchParameter(@NotNull final PsiParameter parameter,
@NotNull final Collection<? extends PsiClassType> thrownTypes) {
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
final List<HighlightInfo> highlights = new ArrayList<>(typeElements.size());
private static List<HighlightInfo> checkMultiCatchParameter(@NotNull PsiParameter parameter,
@NotNull Collection<? extends PsiClassType> thrownTypes) {
List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
List<HighlightInfo> highlights = new ArrayList<>(typeElements.size());
for (final PsiTypeElement typeElement : typeElements) {
final PsiType catchType = typeElement.getType();
for (PsiTypeElement typeElement : typeElements) {
PsiType catchType = typeElement.getType();
if (catchType instanceof PsiClassType && ExceptionUtil.isUncheckedExceptionOrSuperclass((PsiClassType)catchType)) continue;
boolean used = false;
@@ -1488,8 +1488,8 @@ public final class HighlightUtil {
}
}
if (!used) {
final String description = JavaErrorBundle.message("exception.never.thrown.try", JavaHighlightUtil.formatType(catchType));
final HighlightInfo highlight =
String description = JavaErrorBundle.message("exception.never.thrown.try", JavaHighlightUtil.formatType(catchType));
HighlightInfo highlight =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(highlight, getFixFactory().createDeleteMultiCatchFix(typeElement));
highlights.add(highlight);
@@ -1504,39 +1504,39 @@ public final class HighlightUtil {
static Collection<HighlightInfo> checkWithImprovedCatchAnalysis(@NotNull PsiParameter parameter,
@NotNull Collection<? extends PsiClassType> thrownInTryStatement,
@NotNull PsiFile containingFile) {
final PsiElement scope = parameter.getDeclarationScope();
PsiElement scope = parameter.getDeclarationScope();
if (!(scope instanceof PsiCatchSection)) return Collections.emptyList();
final PsiCatchSection catchSection = (PsiCatchSection)scope;
final PsiCatchSection[] allCatchSections = catchSection.getTryStatement().getCatchSections();
final int idx = ArrayUtilRt.find(allCatchSections, catchSection);
PsiCatchSection catchSection = (PsiCatchSection)scope;
PsiCatchSection[] allCatchSections = catchSection.getTryStatement().getCatchSections();
int idx = ArrayUtilRt.find(allCatchSections, catchSection);
if (idx <= 0) return Collections.emptyList();
final Collection<PsiClassType> thrownTypes = new HashSet<>(thrownInTryStatement);
final PsiManager manager = containingFile.getManager();
final GlobalSearchScope parameterResolveScope = parameter.getResolveScope();
Collection<PsiClassType> thrownTypes = new HashSet<>(thrownInTryStatement);
PsiManager manager = containingFile.getManager();
GlobalSearchScope parameterResolveScope = parameter.getResolveScope();
thrownTypes.add(PsiType.getJavaLangError(manager, parameterResolveScope));
thrownTypes.add(PsiType.getJavaLangRuntimeException(manager, parameterResolveScope));
final Collection<HighlightInfo> result = new ArrayList<>();
Collection<HighlightInfo> result = new ArrayList<>();
final List<PsiTypeElement> parameterTypeElements = PsiUtil.getParameterTypeElements(parameter);
final boolean isMultiCatch = parameterTypeElements.size() > 1;
List<PsiTypeElement> parameterTypeElements = PsiUtil.getParameterTypeElements(parameter);
boolean isMultiCatch = parameterTypeElements.size() > 1;
for (PsiTypeElement catchTypeElement : parameterTypeElements) {
final PsiType catchType = catchTypeElement.getType();
PsiType catchType = catchTypeElement.getType();
if (ExceptionUtil.isGeneralExceptionType(catchType)) continue;
// collect exceptions caught by this type
final Collection<PsiClassType> caught =
Collection<PsiClassType> caught =
ContainerUtil.findAll(thrownTypes, type -> catchType.isAssignableFrom(type) || type.isAssignableFrom(catchType));
if (caught.isEmpty()) continue;
final Collection<PsiClassType> caughtCopy = new HashSet<>(caught);
Collection<PsiClassType> caughtCopy = new HashSet<>(caught);
// exclude all caught by previous catch sections
for (int i = 0; i < idx; i++) {
final PsiParameter prevCatchParameter = allCatchSections[i].getParameter();
PsiParameter prevCatchParameter = allCatchSections[i].getParameter();
if (prevCatchParameter == null) continue;
for (PsiTypeElement prevCatchTypeElement : PsiUtil.getParameterTypeElements(prevCatchParameter)) {
final PsiType prevCatchType = prevCatchTypeElement.getType();
PsiType prevCatchType = prevCatchTypeElement.getType();
caught.removeIf(prevCatchType::isAssignableFrom);
if (caught.isEmpty()) break;
}
@@ -1544,8 +1544,8 @@ public final class HighlightUtil {
// check & warn
if (caught.isEmpty()) {
final String message = JavaErrorBundle.message("exception.already.caught.warn", formatTypes(caughtCopy), caughtCopy.size());
final HighlightInfo highlightInfo =
String message = JavaErrorBundle.message("exception.already.caught.warn", formatTypes(caughtCopy), caughtCopy.size());
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING).range(catchSection).descriptionAndTooltip(message).create();
if (isMultiCatch) {
QuickFixAction.registerQuickFixAction(highlightInfo, getFixFactory().createDeleteMultiCatchFix(catchTypeElement));
@@ -1603,7 +1603,7 @@ public final class HighlightUtil {
PsiType switchExpressionType = switchExpression.getType();
if (switchExpressionType != null) {
for (PsiExpression expression : PsiUtil.getSwitchResultExpressions(switchExpression)) {
final PsiType expressionType = expression.getType();
PsiType expressionType = expression.getType();
if (expressionType != null && !TypeConversionUtil.areTypesAssignmentCompatible(switchExpressionType, expression)) {
String text = JavaErrorBundle
.message("bad.type.in.switch.expression", expressionType.getCanonicalText(), switchExpressionType.getCanonicalText());
@@ -1712,19 +1712,19 @@ public final class HighlightUtil {
@Contract(value = "null -> null", pure = true)
private static @Nullable PsiTypeTestPattern getTypeTestPattern(@Nullable PsiPattern expressionPattern) {
final PsiPattern innerMostPattern = JavaPsiPatternUtil.skipParenthesizedPatternDown(expressionPattern);
PsiPattern innerMostPattern = JavaPsiPatternUtil.skipParenthesizedPatternDown(expressionPattern);
if (innerMostPattern == null) return null;
final PsiTypeTestPattern pattern = tryCast(innerMostPattern, PsiTypeTestPattern.class);
PsiTypeTestPattern pattern = tryCast(innerMostPattern, PsiTypeTestPattern.class);
if (pattern != null) return pattern;
final PsiGuardedPattern guardedPattern = tryCast(innerMostPattern, PsiGuardedPattern.class);
PsiGuardedPattern guardedPattern = tryCast(innerMostPattern, PsiGuardedPattern.class);
if (guardedPattern == null) return null;
final Object condition = ExpressionUtils.computeConstantExpression(guardedPattern.getGuardingExpression());
Object condition = ExpressionUtils.computeConstantExpression(guardedPattern.getGuardingExpression());
if (!Boolean.TRUE.equals(condition)) return null;
final PsiPattern patternInGuard = JavaPsiPatternUtil.skipParenthesizedPatternDown(guardedPattern.getPrimaryPattern());
PsiPattern patternInGuard = JavaPsiPatternUtil.skipParenthesizedPatternDown(guardedPattern.getPrimaryPattern());
if (patternInGuard == null || patternInGuard instanceof PsiTypeTestPattern) return (PsiTypeTestPattern)patternInGuard;
return getTypeTestPattern(patternInGuard);
@@ -1780,10 +1780,10 @@ public final class HighlightUtil {
@Nullable PsiJavaCodeReferenceElement qualifier,
@NotNull LanguageLevel languageLevel) {
if (expr instanceof PsiSuperExpression) {
final PsiElement parent = expr.getParent();
PsiElement parent = expr.getParent();
if (!(parent instanceof PsiReferenceExpression)) {
// like in 'Object o = super;'
final int o = expr.getTextRange().getEndOffset();
int o = expr.getTextRange().getEndOffset();
String description = JavaErrorBundle.message("dot.expected.after.super.or.this");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(o, o + 1).descriptionAndTooltip(description).create();
}
@@ -1808,7 +1808,7 @@ public final class HighlightUtil {
return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr);
}
if (expr instanceof PsiSuperExpression) {
final PsiElement resolved = ((PsiReferenceExpression)expr.getParent()).resolve();
PsiElement resolved = ((PsiReferenceExpression)expr.getParent()).resolve();
//15.11.2
//The form T.super.Identifier refers to the field named Identifier of the lexically enclosing instance corresponding to T,
//but with that instance viewed as an instance of the superclass of T.
@@ -1826,8 +1826,8 @@ public final class HighlightUtil {
//or if there exists some other direct superclass or direct superinterface of T, J, such that J is a subtype of I.
PsiClass classT = getContainingClass(expr);
if (classT != null) {
final PsiElement parent = expr.getParent();
final PsiElement resolved = parent instanceof PsiReferenceExpression ? ((PsiReferenceExpression)parent).resolve() : null;
PsiElement parent = expr.getParent();
PsiElement resolved = parent instanceof PsiReferenceExpression ? ((PsiReferenceExpression)parent).resolve() : null;
PsiClass containingClass =
ObjectUtils.notNull(resolved instanceof PsiMethod ? ((PsiMethod)resolved).getContainingClass() : null, aClass);
@@ -1875,7 +1875,7 @@ public final class HighlightUtil {
@NotNull PsiReferenceExpression expr,
@Nullable PsiExpression qualifier) {
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && qualifier instanceof PsiSuperExpression) {
final PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class);
PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class);
if (method != null && method.hasModifierProperty(PsiModifier.DEFAULT) && ((PsiSuperExpression)qualifier).getQualifier() == null) {
String description = JavaErrorBundle.message("unqualified.super.disallowed");
HighlightInfo info =
@@ -1892,9 +1892,9 @@ public final class HighlightUtil {
@NotNull PsiClass aClass,
@NotNull LanguageLevel languageLevel) {
if (!(expr instanceof PsiSuperExpression) || qualifier == null || !languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) return false;
final PsiType superType = expr.getType();
PsiType superType = expr.getType();
if (!(superType instanceof PsiClassType)) return false;
final PsiClass superClass = ((PsiClassType)superType).resolve();
PsiClass superClass = ((PsiClassType)superType).resolve();
return aClass.equals(superClass) && PsiUtil.getEnclosingStaticElement(expr, PsiTreeUtil.getParentOfType(expr, PsiClass.class)) == null;
}
@@ -1982,37 +1982,37 @@ public final class HighlightUtil {
private static PsiElement getContainer(@NotNull PsiModifierListOwner refElement) {
for (ContainerProvider provider : ContainerProvider.EP_NAME.getExtensions()) {
final PsiElement container = provider.getContainer(refElement);
PsiElement container = provider.getContainer(refElement);
if (container != null) return container;
}
return refElement.getParent();
}
private static String getContainerName(@NotNull PsiModifierListOwner refElement, @NotNull PsiSubstitutor substitutor) {
final PsiElement container = getContainer(refElement);
PsiElement container = getContainer(refElement);
return container == null ? "?" : HighlightMessageUtil.getSymbolName(container, substitutor);
}
static HighlightInfo checkValidArrayAccessExpression(@NotNull PsiArrayAccessExpression arrayAccessExpression) {
final PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression();
final PsiType arrayExpressionType = arrayExpression.getType();
PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression();
PsiType arrayExpressionType = arrayExpression.getType();
if (arrayExpressionType != null && !(arrayExpressionType instanceof PsiArrayType)) {
final String description = JavaErrorBundle.message("array.type.expected", JavaHighlightUtil.formatType(arrayExpressionType));
final HighlightInfo info =
String description = JavaErrorBundle.message("array.type.expected", JavaHighlightUtil.formatType(arrayExpressionType));
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(arrayExpression).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, getFixFactory().createReplaceWithListAccessFix(arrayAccessExpression));
return info;
}
final PsiExpression indexExpression = arrayAccessExpression.getIndexExpression();
PsiExpression indexExpression = arrayAccessExpression.getIndexExpression();
return indexExpression != null ? checkAssignability(PsiType.INT, indexExpression.getType(), indexExpression, indexExpression) : null;
}
static HighlightInfo checkCatchParameterIsThrowable(@NotNull final PsiParameter parameter) {
static HighlightInfo checkCatchParameterIsThrowable(@NotNull PsiParameter parameter) {
if (parameter.getDeclarationScope() instanceof PsiCatchSection) {
final PsiType type = parameter.getType();
PsiType type = parameter.getType();
return checkMustBeThrowable(type, parameter, true);
}
return null;
@@ -2063,21 +2063,21 @@ public final class HighlightUtil {
if (!(initializer instanceof PsiArrayInitializerExpression)) return Collections.emptyList();
if (!(type instanceof PsiArrayType)) return Collections.emptyList();
final PsiType componentType = ((PsiArrayType)type).getComponentType();
final PsiArrayInitializerExpression arrayInitializer = (PsiArrayInitializerExpression)initializer;
PsiType componentType = ((PsiArrayType)type).getComponentType();
PsiArrayInitializerExpression arrayInitializer = (PsiArrayInitializerExpression)initializer;
boolean arrayTypeFixChecked = false;
VariableArrayTypeFix fix = null;
final PsiExpression[] initializers = arrayInitializer.getInitializers();
final Collection<HighlightInfo> result = new ArrayList<>(initializers.length);
PsiExpression[] initializers = arrayInitializer.getInitializers();
Collection<HighlightInfo> result = new ArrayList<>(initializers.length);
for (PsiExpression expression : initializers) {
final HighlightInfo info = checkArrayInitializerCompatibleTypes(expression, componentType);
HighlightInfo info = checkArrayInitializerCompatibleTypes(expression, componentType);
if (info != null) {
result.add(info);
if (!arrayTypeFixChecked) {
final PsiType checkResult = JavaHighlightUtil.sameType(initializers);
PsiType checkResult = JavaHighlightUtil.sameType(initializers);
fix = checkResult != null ? VariableArrayTypeFix.createFix(arrayInitializer, checkResult) : null;
arrayTypeFixChecked = true;
}
@@ -2538,12 +2538,12 @@ public final class HighlightUtil {
return null;
}
final HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange());
HighlightInfo highlightInfo = createMemberReferencedError(resolvedName, expression.getTextRange());
if (expression instanceof PsiReferenceExpression && PsiUtil.isInnerClass(parentClass)) {
final String referenceName = ((PsiReferenceExpression)expression).getReferenceName();
final PsiClass containingClass = parentClass.getContainingClass();
String referenceName = ((PsiReferenceExpression)expression).getReferenceName();
PsiClass containingClass = parentClass.getContainingClass();
LOG.assertTrue(containingClass != null);
final PsiField fieldInContainingClass = containingClass.findFieldByName(referenceName, true);
PsiField fieldInContainingClass = containingClass.findFieldByName(referenceName, true);
if (fieldInContainingClass != null && ((PsiReferenceExpression)expression).getQualifierExpression() == null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new QualifyWithThisFix(containingClass, expression));
}
@@ -2553,7 +2553,7 @@ public final class HighlightUtil {
}
if (element instanceof PsiReferenceExpression) {
final PsiElement resolve;
PsiElement resolve;
if (element instanceof PsiReferenceExpressionImpl) {
PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)element;
JavaResolveResult[] results = JavaResolveUtil
@@ -2661,25 +2661,25 @@ public final class HighlightUtil {
@NotNull
static Collection<HighlightInfo> checkCatchTypeIsDisjoint(@NotNull final PsiParameter parameter) {
static Collection<HighlightInfo> checkCatchTypeIsDisjoint(@NotNull PsiParameter parameter) {
if (!(parameter.getType() instanceof PsiDisjunctionType)) return Collections.emptyList();
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
final Collection<HighlightInfo> result = new ArrayList<>(typeElements.size());
List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
Collection<HighlightInfo> result = new ArrayList<>(typeElements.size());
for (int i = 0, size = typeElements.size(); i < size; i++) {
final PsiClass class1 = PsiUtil.resolveClassInClassTypeOnly(typeElements.get(i).getType());
PsiClass class1 = PsiUtil.resolveClassInClassTypeOnly(typeElements.get(i).getType());
if (class1 == null) continue;
for (int j = i + 1; j < size; j++) {
final PsiClass class2 = PsiUtil.resolveClassInClassTypeOnly(typeElements.get(j).getType());
PsiClass class2 = PsiUtil.resolveClassInClassTypeOnly(typeElements.get(j).getType());
if (class2 == null) continue;
final boolean sub = InheritanceUtil.isInheritorOrSelf(class1, class2, true);
final boolean sup = InheritanceUtil.isInheritorOrSelf(class2, class1, true);
boolean sub = InheritanceUtil.isInheritorOrSelf(class1, class2, true);
boolean sup = InheritanceUtil.isInheritorOrSelf(class2, class1, true);
if (sub || sup) {
final String name1 = PsiFormatUtil.formatClass(class1, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
final String name2 = PsiFormatUtil.formatClass(class2, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
final String message = JavaErrorBundle.message("exception.must.be.disjoint", sub ? name1 : name2, sub ? name2 : name1);
final PsiTypeElement element = typeElements.get(sub ? i : j);
final HighlightInfo highlight =
String name1 = PsiFormatUtil.formatClass(class1, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
String name2 = PsiFormatUtil.formatClass(class2, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
String message = JavaErrorBundle.message("exception.must.be.disjoint", sub ? name1 : name2, sub ? name2 : name1);
PsiTypeElement element = typeElements.get(sub ? i : j);
HighlightInfo highlight =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(highlight, getFixFactory().createDeleteMultiCatchFix(element));
result.add(highlight);
@@ -2693,34 +2693,34 @@ public final class HighlightUtil {
@NotNull
static Collection<HighlightInfo> checkExceptionAlreadyCaught(@NotNull final PsiParameter parameter) {
final PsiElement scope = parameter.getDeclarationScope();
static Collection<HighlightInfo> checkExceptionAlreadyCaught(@NotNull PsiParameter parameter) {
PsiElement scope = parameter.getDeclarationScope();
if (!(scope instanceof PsiCatchSection)) return Collections.emptyList();
final PsiCatchSection catchSection = (PsiCatchSection)scope;
final PsiCatchSection[] allCatchSections = catchSection.getTryStatement().getCatchSections();
final int startFrom = ArrayUtilRt.find(allCatchSections, catchSection) - 1;
PsiCatchSection catchSection = (PsiCatchSection)scope;
PsiCatchSection[] allCatchSections = catchSection.getTryStatement().getCatchSections();
int startFrom = ArrayUtilRt.find(allCatchSections, catchSection) - 1;
if (startFrom < 0) return Collections.emptyList();
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
final boolean isInMultiCatch = typeElements.size() > 1;
final Collection<HighlightInfo> result = new ArrayList<>();
List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
boolean isInMultiCatch = typeElements.size() > 1;
Collection<HighlightInfo> result = new ArrayList<>();
for (PsiTypeElement typeElement : typeElements) {
final PsiClass catchClass = PsiUtil.resolveClassInClassTypeOnly(typeElement.getType());
PsiClass catchClass = PsiUtil.resolveClassInClassTypeOnly(typeElement.getType());
if (catchClass == null) continue;
for (int i = startFrom; i >= 0; i--) {
final PsiCatchSection upperCatchSection = allCatchSections[i];
final PsiType upperCatchType = upperCatchSection.getCatchType();
PsiCatchSection upperCatchSection = allCatchSections[i];
PsiType upperCatchType = upperCatchSection.getCatchType();
final boolean highlight = upperCatchType instanceof PsiDisjunctionType
boolean highlight = upperCatchType instanceof PsiDisjunctionType
? checkMultipleTypes(catchClass, ((PsiDisjunctionType)upperCatchType).getDisjunctions())
: checkSingleType(catchClass, upperCatchType);
if (highlight) {
final String className = PsiFormatUtil.formatClass(catchClass, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
final String description = JavaErrorBundle.message("exception.already.caught", className);
final HighlightInfo highlightInfo =
String className = PsiFormatUtil.formatClass(catchClass, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
String description = JavaErrorBundle.message("exception.already.caught", className);
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
result.add(highlightInfo);
@@ -2738,7 +2738,7 @@ public final class HighlightUtil {
return result;
}
private static boolean checkMultipleTypes(@NotNull PsiClass catchClass, @NotNull final List<? extends PsiType> upperCatchTypes) {
private static boolean checkMultipleTypes(@NotNull PsiClass catchClass, @NotNull List<? extends PsiType> upperCatchTypes) {
for (int i = upperCatchTypes.size() - 1; i >= 0; i--) {
if (checkSingleType(catchClass, upperCatchTypes.get(i))) return true;
}
@@ -2746,7 +2746,7 @@ public final class HighlightUtil {
}
private static boolean checkSingleType(@NotNull PsiClass catchClass, @Nullable PsiType upperCatchType) {
final PsiClass upperCatchClass = PsiUtil.resolveClassInType(upperCatchType);
PsiClass upperCatchClass = PsiUtil.resolveClassInType(upperCatchType);
return upperCatchClass != null && InheritanceUtil.isInheritorOrSelf(catchClass, upperCatchClass, true);
}
@@ -2798,7 +2798,7 @@ public final class HighlightUtil {
return null;
}
static HighlightInfo checkConditionalExpressionBranchTypesMatch(@NotNull final PsiExpression expression, @Nullable PsiType type) {
static HighlightInfo checkConditionalExpressionBranchTypesMatch(@NotNull PsiExpression expression, @Nullable PsiType type) {
PsiElement parent = expression.getParent();
if (!(parent instanceof PsiConditionalExpression)) {
return null;
@@ -2806,7 +2806,7 @@ public final class HighlightUtil {
PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)parent;
// check else branches only
if (conditionalExpression.getElseExpression() != expression) return null;
final PsiExpression thenExpression = conditionalExpression.getThenExpression();
PsiExpression thenExpression = conditionalExpression.getThenExpression();
assert thenExpression != null;
PsiType thenType = thenExpression.getType();
if (thenType == null || type == null) return null;
@@ -2991,7 +2991,7 @@ public final class HighlightUtil {
}
}
final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(type);
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(type);
if (aClass != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, getFixFactory().createExtendsListFix(aClass, throwable, true));
}
@@ -3135,25 +3135,25 @@ public final class HighlightUtil {
static boolean isCallToStaticMember(@Nullable PsiElement element) {
if (!(element instanceof PsiNewExpression)) return false;
final PsiNewExpression newExpression = (PsiNewExpression)element;
final PsiJavaCodeReferenceElement reference = newExpression.getClassOrAnonymousClassReference();
PsiNewExpression newExpression = (PsiNewExpression)element;
PsiJavaCodeReferenceElement reference = newExpression.getClassOrAnonymousClassReference();
if (reference == null) return false;
final PsiElement qualifier = reference.getQualifier();
final PsiElement memberName = reference.getReferenceNameElement();
PsiElement qualifier = reference.getQualifier();
PsiElement memberName = reference.getReferenceNameElement();
if (!(qualifier instanceof PsiJavaCodeReferenceElement) || memberName == null) return false;
final PsiJavaCodeReferenceElement psiReference = (PsiJavaCodeReferenceElement)qualifier;
PsiJavaCodeReferenceElement psiReference = (PsiJavaCodeReferenceElement)qualifier;
if (psiReference.getTypeParameterCount() > 0) return false;
final PsiClass clazz = tryCast(psiReference.resolve(), PsiClass.class);
PsiClass clazz = tryCast(psiReference.resolve(), PsiClass.class);
if (clazz == null) return false;
if (newExpression.getArgumentList() == null) {
final PsiField field = clazz.findFieldByName(memberName.getText(), true);
PsiField field = clazz.findFieldByName(memberName.getText(), true);
if (field != null && field.hasModifierProperty(PsiModifier.STATIC)) return true;
}
else {
final PsiMethod[] methods = clazz.findMethodsByName(memberName.getText(), true);
PsiMethod[] methods = clazz.findMethodsByName(memberName.getText(), true);
if (methods.length == 0) return false;
for (PsiMethod method : methods) {
if (method.hasModifierProperty(PsiModifier.STATIC)) return true;
@@ -3256,16 +3256,16 @@ public final class HighlightUtil {
public static boolean isSerializationImplicitlyUsedField(@NotNull PsiField field) {
final String name = field.getName();
String name = field.getName();
if (!CommonClassNames.SERIAL_VERSION_UID_FIELD_NAME.equals(name) && !SERIAL_PERSISTENT_FIELDS_FIELD_NAME.equals(name)) return false;
if (!field.hasModifierProperty(PsiModifier.STATIC)) return false;
PsiClass aClass = field.getContainingClass();
return aClass == null || JavaHighlightUtil.isSerializable(aClass);
}
static HighlightInfo checkClassReferenceAfterQualifier(@NotNull final PsiReferenceExpression expression, @Nullable PsiElement resolved) {
static HighlightInfo checkClassReferenceAfterQualifier(@NotNull PsiReferenceExpression expression, @Nullable PsiElement resolved) {
if (!(resolved instanceof PsiClass)) return null;
final PsiExpression qualifier = expression.getQualifierExpression();
PsiExpression qualifier = expression.getQualifierExpression();
if (qualifier == null) return null;
if (qualifier instanceof PsiReferenceExpression) {
PsiElement qualifierResolved = ((PsiReferenceExpression)qualifier).resolve();
@@ -3295,11 +3295,11 @@ public final class HighlightUtil {
}
static HighlightInfo checkAnnotationMethodParameters(@NotNull PsiParameterList list) {
final PsiElement parent = list.getParent();
PsiElement parent = list.getParent();
if (PsiUtil.isAnnotationMethod(parent) &&
(!list.isEmpty() || PsiTreeUtil.getChildOfType(list, PsiReceiverParameter.class) != null)) {
final String message = JavaErrorBundle.message("annotation.interface.members.may.not.have.parameters");
final HighlightInfo highlightInfo =
String message = JavaErrorBundle.message("annotation.interface.members.may.not.have.parameters");
HighlightInfo highlightInfo =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(highlightInfo, getFixFactory().createRemoveParameterListFix((PsiMethod)parent));
return highlightInfo;

View File

@@ -97,20 +97,20 @@ public enum HighlightingFeature {
@Nullable
@Contract(value = "null -> null", pure = true)
public static HighlightingFeature fromPreviewFeatureAnnotation(@Nullable final PsiAnnotation annotation) {
public static HighlightingFeature fromPreviewFeatureAnnotation(@Nullable PsiAnnotation annotation) {
if (annotation == null) return null;
if (!annotation.hasQualifiedName(JDK_INTERNAL_PREVIEW_FEATURE) &&
!annotation.hasQualifiedName(JDK_INTERNAL_JAVAC_PREVIEW_FEATURE)) {
return null;
}
final PsiNameValuePair feature = AnnotationUtil.findDeclaredAttribute(annotation, "feature");
PsiNameValuePair feature = AnnotationUtil.findDeclaredAttribute(annotation, "feature");
if (feature == null) return null;
final PsiReferenceExpression referenceExpression = tryCast(feature.getDetachedValue(), PsiReferenceExpression.class);
PsiReferenceExpression referenceExpression = tryCast(feature.getDetachedValue(), PsiReferenceExpression.class);
if (referenceExpression == null) return null;
final PsiEnumConstant enumConstant = tryCast(referenceExpression.resolve(), PsiEnumConstant.class);
PsiEnumConstant enumConstant = tryCast(referenceExpression.resolve(), PsiEnumConstant.class);
if (enumConstant == null) return null;
return convertFromPreviewFeatureName(enumConstant.getName());
@@ -118,7 +118,7 @@ public enum HighlightingFeature {
@Nullable
@Contract(pure = true)
private static HighlightingFeature convertFromPreviewFeatureName(@NotNull @NonNls final String feature) {
private static HighlightingFeature convertFromPreviewFeatureName(@NotNull @NonNls String feature) {
switch (feature) {
case "PATTERN_MATCHING_IN_INSTANCEOF":
return PATTERNS;
@@ -135,32 +135,32 @@ public enum HighlightingFeature {
@Nullable
@Contract(value = "null -> null", pure = true)
public static PsiAnnotation getPreviewFeatureAnnotation(@Nullable final PsiModifierListOwner owner) {
public static PsiAnnotation getPreviewFeatureAnnotation(@Nullable PsiModifierListOwner owner) {
if (owner == null) return null;
final PsiAnnotation annotation = getAnnotation(owner);
PsiAnnotation annotation = getAnnotation(owner);
if (annotation != null) return annotation;
if (owner instanceof PsiMember && !owner.hasModifier(JvmModifier.STATIC)) {
final PsiMember member = (PsiMember)owner;
final PsiAnnotation result = getPreviewFeatureAnnotation(member.getContainingClass());
PsiMember member = (PsiMember)owner;
PsiAnnotation result = getPreviewFeatureAnnotation(member.getContainingClass());
if (result != null) return result;
}
final PsiPackage psiPackage = JavaResolveUtil.getContainingPackage(owner);
PsiPackage psiPackage = JavaResolveUtil.getContainingPackage(owner);
if (psiPackage == null) return null;
final PsiAnnotation packageAnnotation = getAnnotation(psiPackage);
PsiAnnotation packageAnnotation = getAnnotation(psiPackage);
if (packageAnnotation != null) return packageAnnotation;
final PsiJavaModule module = JavaModuleGraphUtil.findDescriptorByElement(owner);
PsiJavaModule module = JavaModuleGraphUtil.findDescriptorByElement(owner);
if (module == null) return null;
return getAnnotation(module);
}
private static PsiAnnotation getAnnotation(@NotNull PsiModifierListOwner owner) {
final PsiAnnotation annotation = owner.getAnnotation(JDK_INTERNAL_JAVAC_PREVIEW_FEATURE);
PsiAnnotation annotation = owner.getAnnotation(JDK_INTERNAL_JAVAC_PREVIEW_FEATURE);
if (annotation != null) return annotation;
return owner.getAnnotation(JDK_INTERNAL_PREVIEW_FEATURE);

View File

@@ -6,7 +6,10 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiFileEx;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
@@ -19,6 +22,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -37,12 +41,9 @@ public final class JavaHighlightUtil {
public static boolean isSerializationRelatedMethod(@NotNull PsiMethod method, @Nullable PsiClass containingClass) {
if (containingClass == null) return false;
if (method.isConstructor()) {
if (isSerializable(containingClass, "java.io.Externalizable") &&
method.getParameterList().isEmpty() &&
method.hasModifierProperty(PsiModifier.PUBLIC)) {
return true;
}
return false;
return isSerializable(containingClass, "java.io.Externalizable") &&
method.getParameterList().isEmpty() &&
method.hasModifierProperty(PsiModifier.PUBLIC);
}
if (method.hasModifierProperty(PsiModifier.STATIC)) return false;
@NonNls String name = method.getName();
@@ -98,7 +99,7 @@ public final class JavaHighlightUtil {
public static PsiType sameType(PsiExpression @NotNull [] expressions) {
PsiType type = null;
for (PsiExpression expression : expressions) {
final PsiType currentType;
PsiType currentType;
if (expression instanceof PsiArrayInitializerExpression) {
currentType = getArrayInitializerType((PsiArrayInitializerExpression)expression);
}
@@ -125,15 +126,11 @@ public final class JavaHighlightUtil {
if (!(statement instanceof PsiExpressionStatement)) return false;
PsiExpression expression = ((PsiExpressionStatement)statement).getExpression();
if (!(expression instanceof PsiMethodCallExpression)) return false;
final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)expression).getMethodExpression();
PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)expression).getMethodExpression();
if (testForSuper) {
if ("super".equals(methodExpression.getText())) return true;
}
if (testForThis) {
if ("this".equals(methodExpression.getText())) return true;
}
return false;
return testForThis && "this".equals(methodExpression.getText());
}
/**
@@ -143,7 +140,7 @@ public final class JavaHighlightUtil {
*/
@NotNull
public static List<PsiMethod> getChainedConstructors(@NotNull PsiMethod constructor) {
final ConstructorVisitorInfo info = new ConstructorVisitorInfo();
ConstructorVisitorInfo info = new ConstructorVisitorInfo();
visitConstructorChain(constructor, info);
if (info.visitedConstructors != null) info.visitedConstructors.remove(constructor);
return ObjectUtils.notNull(info.visitedConstructors, Collections.emptyList());
@@ -204,6 +201,35 @@ public final class JavaHighlightUtil {
return JavaAnalysisBundle.message("message.class.inaccessible.from.module", className, module.getName());
}
/**
* @return true if file correspond to the shebang script
*/
public static boolean isJavaHashBangScript(@NotNull PsiFile containingFile) {
if (!(containingFile instanceof PsiJavaFile)) return false;
if (containingFile instanceof PsiFileEx && !((PsiFileEx)containingFile).isContentsLoaded()) {
VirtualFile vFile = containingFile.getVirtualFile();
if (vFile.isInLocalFileSystem()) {
try {
// don't build PSI when not yet loaded -> time for scanning scope from 18 seconds to 8 seconds on IntelliJ project
return VfsUtilCore.loadText(vFile, 5).startsWith("#!");
}
catch (IOException e) {
return false;
}
}
}
PsiElement firstChild = containingFile.getFirstChild();
if (firstChild instanceof PsiImportList && firstChild.getTextLength() == 0) {
PsiElement sibling = firstChild.getNextSibling();
if (sibling instanceof PsiClass) {
firstChild = sibling.getFirstChild();
}
}
return firstChild instanceof PsiComment &&
((PsiComment)firstChild).getTokenType() == JavaTokenType.END_OF_LINE_COMMENT &&
firstChild.getText().startsWith("#!");
}
static class ConstructorVisitorInfo {
List<PsiMethod> visitedConstructors;
PsiMethod recursivelyCalledConstructor;

View File

@@ -27,7 +27,7 @@ public final class LambdaHighlightingUtil {
static @NlsContexts.DetailedDescription String checkInterfaceFunctional(@NotNull PsiClass psiClass, @NotNull @Nls String interfaceNonFunctionalMessage) {
if (psiClass instanceof PsiTypeParameter) return null; //should be logged as cyclic inference
final List<HierarchicalMethodSignature> signatures = LambdaUtil.findFunctionCandidates(psiClass);
List<HierarchicalMethodSignature> signatures = LambdaUtil.findFunctionCandidates(psiClass);
if (signatures == null) return interfaceNonFunctionalMessage;
if (signatures.isEmpty()) return JavaErrorBundle.message("no.target.method.found");
if (signatures.size() == 1) {
@@ -39,7 +39,7 @@ public final class LambdaHighlightingUtil {
static HighlightInfo checkParametersCompatible(@NotNull PsiLambdaExpression expression,
PsiParameter @NotNull [] methodParameters,
@NotNull PsiSubstitutor substitutor) {
final PsiParameter[] lambdaParameters = expression.getParameterList().getParameters();
PsiParameter[] lambdaParameters = expression.getParameterList().getParameters();
if (lambdaParameters.length != methodParameters.length) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expression.getParameterList())
@@ -53,8 +53,8 @@ public final class LambdaHighlightingUtil {
PsiType substitutedParamType = substitutor.substitute(methodParameters[i].getType());
if (hasFormalParameterTypes &&!PsiTypesUtil.compareTypes(lambdaParameterType, substitutedParamType, true) ||
!TypeConversionUtil.isAssignable(substitutedParamType, lambdaParameterType)) {
final String expectedType = substitutedParamType != null ? substitutedParamType.getPresentableText() : null;
final String actualType = lambdaParameterType.getPresentableText();
String expectedType = substitutedParamType != null ? substitutedParamType.getPresentableText() : null;
String actualType = lambdaParameterType.getPresentableText();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expression.getParameterList())
.descriptionAndTooltip(
@@ -75,10 +75,10 @@ public final class LambdaHighlightingUtil {
public static @NlsContexts.DetailedDescription String checkInterfaceFunctional(@NotNull PsiType functionalInterfaceType) {
if (functionalInterfaceType instanceof PsiIntersectionType) {
final Set<MethodSignature> signatures = new HashSet<>();
Set<MethodSignature> signatures = new HashSet<>();
for (PsiType type : ((PsiIntersectionType)functionalInterfaceType).getConjuncts()) {
if (checkInterfaceFunctional(type) == null) {
final MethodSignature signature = LambdaUtil.getFunction(PsiUtil.resolveClassInType(type));
MethodSignature signature = LambdaUtil.getFunction(PsiUtil.resolveClassInType(type));
LOG.assertTrue(signature != null, type.getCanonicalText());
signatures.add(signature);
}
@@ -89,8 +89,8 @@ public final class LambdaHighlightingUtil {
}
return null;
}
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiClass aClass = resolveResult.getElement();
PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
PsiClass aClass = resolveResult.getElement();
if (aClass != null) {
if (aClass instanceof PsiTypeParameter) return null; //should be logged as cyclic inference
MethodSignature functionalMethod = LambdaUtil.getFunction(aClass);

View File

@@ -65,7 +65,7 @@ class PostHighlightingVisitor {
private final HighlightInfoType myDeadCodeInfoType;
private final UnusedDeclarationInspectionBase myDeadCodeInspection;
private void optimizeImportsOnTheFlyLater(@NotNull final ProgressIndicator progress) {
private void optimizeImportsOnTheFlyLater(@NotNull ProgressIndicator progress) {
if ((myHasRedundantImports || myHasMisSortedImports) && !progress.isCanceled()) {
// schedule optimise action at the time of session disposal, which is after all applyInformation() calls
Disposable invokeFixLater = () -> {
@@ -126,8 +126,8 @@ class PostHighlightingVisitor {
if (isToolEnabled(myDeadCodeKey)) {
GlobalUsageHelper globalUsageHelper = myRefCountHolder.getGlobalUsageHelper(myFile, myDeadCodeInspection, true);
final FileViewProvider viewProvider = myFile.getViewProvider();
final Set<Language> relevantLanguages = viewProvider.getLanguages();
FileViewProvider viewProvider = myFile.getViewProvider();
Set<Language> relevantLanguages = viewProvider.getLanguages();
for (Language language : relevantLanguages) {
ProgressManager.checkCanceled();
PsiElement psiRoot = viewProvider.getPsi(language);
@@ -153,10 +153,10 @@ class PostHighlightingVisitor {
if (isUnusedImportEnabled(unusedImportKey)) {
PsiImportList importList = ((PsiJavaFile)myFile).getImportList();
if (importList != null) {
final PsiImportStatementBase[] imports = importList.getAllImportStatements();
PsiImportStatementBase[] imports = importList.getAllImportStatements();
for (PsiImportStatementBase statement : imports) {
ProgressManager.checkCanceled();
final HighlightInfo info = processImport(statement, unusedImportKey);
HighlightInfo info = processImport(statement, unusedImportKey);
if (info != null) {
errorFound |= info.getSeverity() == HighlightSeverity.ERROR;
result.add(info);
@@ -206,7 +206,7 @@ class PostHighlightingVisitor {
}
if (parent instanceof PsiParameter) {
PsiElement declarationScope = ((PsiParameter)parent).getDeclarationScope();
final boolean needToProcessParameter;
boolean needToProcessParameter;
if (declarationScope instanceof PsiMethod || declarationScope instanceof PsiLambdaExpression) {
if (declarationScope instanceof PsiLambdaExpression) {
declarationScope = PsiTreeUtil.getParentOfType(declarationScope, PsiModifierListOwner.class);
@@ -230,7 +230,7 @@ class PostHighlightingVisitor {
}
}
if (parent instanceof PsiClass) {
final String acceptedVisibility = ((PsiClass)parent).getContainingClass() == null ? myUnusedSymbolInspection.getClassVisibility()
String acceptedVisibility = ((PsiClass)parent).getContainingClass() == null ? myUnusedSymbolInspection.getClassVisibility()
: myUnusedSymbolInspection.getInnerClassVisibility();
if (compareVisibilities((PsiModifierListOwner)parent, acceptedVisibility)) {
return processClass(myProject, (PsiClass)parent, identifier, progress, helper);
@@ -239,7 +239,7 @@ class PostHighlightingVisitor {
return null;
}
private static boolean compareVisibilities(PsiModifierListOwner listOwner, final String visibility) {
private static boolean compareVisibilities(PsiModifierListOwner listOwner, String visibility) {
if (visibility != null) {
while (listOwner != null) {
if (VisibilityUtil.compare(VisibilityUtil.getVisibilityModifier(listOwner.getModifierList()), visibility) >= 0) {
@@ -278,7 +278,7 @@ class PostHighlightingVisitor {
}
if (message != null) {
final HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
QuickFixAction.registerQuickFixAction(highlightInfo, fix, myDeadCodeKey);
return highlightInfo;
}
@@ -287,8 +287,8 @@ class PostHighlightingVisitor {
}
@Nullable
private HighlightInfo processField(@NotNull final Project project,
@NotNull final PsiField field,
private HighlightInfo processField(@NotNull Project project,
@NotNull PsiField field,
@NotNull PsiIdentifier identifier,
@NotNull ProgressIndicator progress,
@NotNull GlobalUsageHelper helper) {
@@ -296,7 +296,7 @@ class PostHighlightingVisitor {
return null;
}
if (field.hasModifierProperty(PsiModifier.PRIVATE)) {
final QuickFixFactory quickFixFactory = QuickFixFactory.getInstance();
QuickFixFactory quickFixFactory = QuickFixFactory.getInstance();
if (!myRefCountHolder.isReferenced(field) && !UnusedSymbolUtil.isImplicitUsage(myProject, field)) {
String message = JavaErrorBundle.message("private.field.is.not.used", identifier.getText());
@@ -308,7 +308,7 @@ class PostHighlightingVisitor {
return highlightInfo;
}
final boolean readReferenced = myRefCountHolder.isReferencedForRead(field);
boolean readReferenced = myRefCountHolder.isReferencedForRead(field);
if (!readReferenced && !UnusedSymbolUtil.isImplicitRead(project, field)) {
String message = getNotUsedForReadingMessage(field, identifier);
return suggestionsToMakeFieldUsed(field, identifier, message);
@@ -317,10 +317,10 @@ class PostHighlightingVisitor {
if (field.hasInitializer()) {
return null;
}
final boolean writeReferenced = myRefCountHolder.isReferencedForWrite(field);
boolean writeReferenced = myRefCountHolder.isReferencedForWrite(field);
if (!writeReferenced && !UnusedSymbolUtil.isImplicitWrite(project, field)) {
String message = JavaErrorBundle.message("private.field.is.not.assigned", identifier.getText());
final HighlightInfo info = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
HighlightInfo info = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
QuickFixAction.registerQuickFixAction(info, quickFixFactory.createCreateGetterOrSetterFix(false, true, field), myDeadCodeKey);
if (!field.hasModifierProperty(PsiModifier.FINAL)) {
@@ -350,10 +350,10 @@ class PostHighlightingVisitor {
}
@NotNull
private static @NlsContexts.DetailedDescription String getNotUsedForReadingMessage(@NotNull final PsiField field, @NotNull final PsiIdentifier identifier) {
final String visibility = VisibilityUtil.getVisibilityStringToDisplay(field);
private static @NlsContexts.DetailedDescription String getNotUsedForReadingMessage(@NotNull PsiField field, @NotNull PsiIdentifier identifier) {
String visibility = VisibilityUtil.getVisibilityStringToDisplay(field);
final String message = JavaErrorBundle.message("field.is.not.used.for.reading", visibility, identifier.getText());
String message = JavaErrorBundle.message("field.is.not.used.for.reading", visibility, identifier.getText());
return StringUtil.capitalize(message);
}
@@ -465,8 +465,8 @@ class PostHighlightingVisitor {
}
@Nullable
private HighlightInfo processMethod(@NotNull final Project project,
@NotNull final PsiMethod method,
private HighlightInfo processMethod(@NotNull Project project,
@NotNull PsiMethod method,
@NotNull PsiIdentifier identifier,
@NotNull ProgressIndicator progress,
@NotNull GlobalUsageHelper helper) {
@@ -481,7 +481,7 @@ class PostHighlightingVisitor {
int options = PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES;
String symbolName = HighlightMessageUtil.getSymbolName(method, PsiSubstitutor.EMPTY, options);
String message = JavaErrorBundle.message(key, symbolName);
final HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createSafeDeleteFix(method), myDeadCodeKey);
SpecialAnnotationsUtilBase.createAddToSpecialAnnotationFixes(method, annoName -> {
IntentionAction fix = QuickFixFactory.getInstance().createAddToDependencyInjectionAnnotationsFix(project, annoName);
@@ -524,15 +524,15 @@ class PostHighlightingVisitor {
}
private static HighlightInfo formatUnusedSymbolHighlightInfo(@NotNull final Project project,
private static HighlightInfo formatUnusedSymbolHighlightInfo(@NotNull Project project,
@NotNull @PropertyKey(resourceBundle = JavaErrorBundle.BUNDLE) String pattern,
@NotNull final PsiNameIdentifierOwner aClass,
@NotNull PsiNameIdentifierOwner aClass,
HighlightDisplayKey highlightDisplayKey,
@NotNull HighlightInfoType highlightInfoType,
@NotNull PsiElement identifier) {
String symbolName = aClass.getName();
String message = JavaErrorBundle.message(pattern, symbolName);
final HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, highlightInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, highlightInfoType, UnusedDeclarationInspectionBase.SHORT_NAME);
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createSafeDeleteFix(aClass), highlightDisplayKey);
SpecialAnnotationsUtilBase.createAddToSpecialAnnotationFixes((PsiModifierListOwner)aClass, annoName -> {
QuickFixAction

View File

@@ -21,22 +21,22 @@ public abstract class PreviewFeatureVisitorBase extends JavaElementVisitor {
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
final PsiElement resolved = reference.resolve();
PsiElement resolved = reference.resolve();
if (!(resolved instanceof PsiModifierListOwner)) return;
final PsiModifierListOwner owner = (PsiModifierListOwner)resolved;
PsiModifierListOwner owner = (PsiModifierListOwner)resolved;
checkPreviewFeature(reference, reference, owner);
}
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
final PsiElement resolved = expression.resolve();
PsiElement resolved = expression.resolve();
if (!(resolved instanceof PsiModifierListOwner)) return;
final PsiModifierListOwner owner = (PsiModifierListOwner)resolved;
PsiModifierListOwner owner = (PsiModifierListOwner)resolved;
checkPreviewFeature(expression, expression, owner);
}
@@ -44,30 +44,30 @@ public abstract class PreviewFeatureVisitorBase extends JavaElementVisitor {
@Override
public void visitModuleStatement(PsiStatement statement) {
if (statement instanceof PsiRequiresStatement) {
final PsiRequiresStatement requiresStatement = (PsiRequiresStatement)statement;
final PsiJavaModule module = requiresStatement.resolve();
PsiRequiresStatement requiresStatement = (PsiRequiresStatement)statement;
PsiJavaModule module = requiresStatement.resolve();
if (module == null) return;
final PsiAnnotation annotation = getPreviewFeatureAnnotation(module);
final HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
PsiAnnotation annotation = getPreviewFeatureAnnotation(module);
HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
if (feature == null) return;
final String description = JavaBundle.message("inspection.preview.feature.0.is.preview.api.message", module.getName());
String description = JavaBundle.message("inspection.preview.feature.0.is.preview.api.message", module.getName());
registerProblem(requiresStatement.getReferenceElement(), description, feature, annotation);
}
else if (statement instanceof PsiProvidesStatement) {
final PsiProvidesStatement providesStatement = (PsiProvidesStatement)statement;
final PsiReferenceList list = providesStatement.getImplementationList();
PsiProvidesStatement providesStatement = (PsiProvidesStatement)statement;
PsiReferenceList list = providesStatement.getImplementationList();
if (list == null) return;
for (PsiJavaCodeReferenceElement element : list.getReferenceElements()) {
final PsiElement resolved = element.resolve();
PsiElement resolved = element.resolve();
if (resolved instanceof PsiClass) {
final PsiClass psiClass = (PsiClass)resolved;
final PsiAnnotation annotation = getPreviewFeatureAnnotation(psiClass);
final HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
PsiClass psiClass = (PsiClass)resolved;
PsiAnnotation annotation = getPreviewFeatureAnnotation(psiClass);
HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
if (feature == null) continue;
final String description =
String description =
JavaBundle.message("inspection.preview.feature.0.is.preview.api.message", psiClass.getQualifiedName());
registerProblem(element, description, feature, annotation);
}
@@ -96,18 +96,18 @@ public abstract class PreviewFeatureVisitorBase extends JavaElementVisitor {
* @param owner an element that should be checked if it's a preview feature
*/
private void checkPreviewFeature(PsiElement context, PsiJavaCodeReferenceElement reference, PsiModifierListOwner owner) {
final PsiAnnotation annotation = getPreviewFeatureAnnotation(owner);
final HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
PsiAnnotation annotation = getPreviewFeatureAnnotation(owner);
HighlightingFeature feature = HighlightingFeature.fromPreviewFeatureAnnotation(annotation);
if (feature == null) return;
if (isParticipating(reference, owner)) return;
@NotNull final String name;
@NotNull String name;
if (owner instanceof PsiMember) {
final PsiMember member = (PsiMember)owner;
final PsiClass className = member.getContainingClass();
final String methodName = member.getName();
PsiMember member = (PsiMember)owner;
PsiClass className = member.getContainingClass();
String methodName = member.getName();
if (member instanceof PsiClass) {
final PsiClass psiClass = (PsiClass)member;
PsiClass psiClass = (PsiClass)member;
name = Objects.requireNonNull(psiClass.getQualifiedName());
}
else if (member instanceof PsiMethod && ((PsiMethod)member).isConstructor()) {
@@ -121,7 +121,7 @@ public abstract class PreviewFeatureVisitorBase extends JavaElementVisitor {
name = reference.getQualifiedName();
}
final String description = JavaBundle.message("inspection.preview.feature.0.is.preview.api.message", name);
String description = JavaBundle.message("inspection.preview.feature.0.is.preview.api.message", name);
registerProblem(context, description, feature, annotation);
}
@@ -147,8 +147,8 @@ public abstract class PreviewFeatureVisitorBase extends JavaElementVisitor {
if (element == null) return Optional.empty();
if (element instanceof PsiPackage) return Optional.empty();
final Supplier<PsiClass> containingClass = () -> element instanceof PsiMember ? ((PsiMember)element).getContainingClass() : null;
final Supplier<PsiJavaModule> javaModule = () -> element instanceof PsiJavaModule ? null : JavaModuleGraphUtil.findDescriptorByElement(element);
Supplier<PsiClass> containingClass = () -> element instanceof PsiMember ? ((PsiMember)element).getContainingClass() : null;
Supplier<PsiJavaModule> javaModule = () -> element instanceof PsiJavaModule ? null : JavaModuleGraphUtil.findDescriptorByElement(element);
return Optional.ofNullable(element.getAnnotation(JDK_INTERNAL_JAVAC_PREVIEW_FEATURE))
.or(() -> Optional.ofNullable(element.getAnnotation(JDK_INTERNAL_PREVIEW_FEATURE)))

View File

@@ -29,7 +29,7 @@ public final class PsiMethodReferenceHighlightingUtil {
}
static @NlsContexts.DetailedDescription String checkMethodReferenceContext(@NotNull PsiMethodReferenceExpression methodRef) {
final PsiElement resolve = methodRef.resolve();
PsiElement resolve = methodRef.resolve();
if (resolve == null) return null;
return checkMethodReferenceContext(methodRef, resolve, methodRef.getFunctionalInterfaceType());
@@ -38,22 +38,22 @@ public final class PsiMethodReferenceHighlightingUtil {
public static @NlsContexts.DetailedDescription String checkMethodReferenceContext(@NotNull PsiMethodReferenceExpression methodRef,
@NotNull PsiElement resolve,
PsiType functionalInterfaceType) {
final PsiClass containingClass = resolve instanceof PsiMethod ? ((PsiMethod)resolve).getContainingClass() : (PsiClass)resolve;
final boolean isStaticSelector = PsiMethodReferenceUtil.isStaticallyReferenced(methodRef);
final PsiElement qualifier = methodRef.getQualifier();
PsiClass containingClass = resolve instanceof PsiMethod ? ((PsiMethod)resolve).getContainingClass() : (PsiClass)resolve;
boolean isStaticSelector = PsiMethodReferenceUtil.isStaticallyReferenced(methodRef);
PsiElement qualifier = methodRef.getQualifier();
boolean isMethodStatic = false;
boolean receiverReferenced = false;
boolean isConstructor = true;
if (resolve instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)resolve;
PsiMethod method = (PsiMethod)resolve;
isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
isConstructor = method.isConstructor();
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
receiverReferenced = PsiMethodReferenceUtil.isResolvedBySecondSearch(methodRef,
interfaceMethod != null ? interfaceMethod.getSignature(LambdaUtil.getSubstitutor(interfaceMethod, resolveResult)) : null,
method.isVarArgs(),
@@ -78,9 +78,9 @@ public final class PsiMethodReferenceHighlightingUtil {
}
if (isMethodStatic && isStaticSelector && qualifier instanceof PsiTypeElement) {
final PsiJavaCodeReferenceElement referenceElement = PsiTreeUtil.getChildOfType(qualifier, PsiJavaCodeReferenceElement.class);
PsiJavaCodeReferenceElement referenceElement = PsiTreeUtil.getChildOfType(qualifier, PsiJavaCodeReferenceElement.class);
if (referenceElement != null) {
final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
PsiReferenceParameterList parameterList = referenceElement.getParameterList();
if (parameterList != null && parameterList.getTypeArguments().length > 0) {
return JavaErrorBundle.message("parameterized.qualifier.on.static.method.reference.context");
}

View File

@@ -72,7 +72,7 @@ final class RefCountHolder {
@NotNull
GlobalUsageHelper getGlobalUsageHelper(@NotNull PsiFile file,
@Nullable final UnusedDeclarationInspectionBase deadCodeInspection,
@Nullable UnusedDeclarationInspectionBase deadCodeInspection,
boolean isUnusedToolEnabled) {
FileViewProvider viewProvider = file.getViewProvider();
Project project = file.getProject();

View File

@@ -33,18 +33,18 @@ final class RemoveNewKeywordFix extends LocalQuickFixAndIntentionActionOnPsiElem
@Nullable Editor editor,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
final PsiNewExpression newDeclaration = tryCast(startElement, PsiNewExpression.class);
PsiNewExpression newDeclaration = tryCast(startElement, PsiNewExpression.class);
if (newDeclaration == null) return;
final PsiJavaCodeReferenceElement reference = newDeclaration.getClassOrAnonymousClassReference();
PsiJavaCodeReferenceElement reference = newDeclaration.getClassOrAnonymousClassReference();
if (reference == null) return;
final PsiExpressionList arguments = newDeclaration.getArgumentList();
PsiExpressionList arguments = newDeclaration.getArgumentList();
final CommentTracker ct = new CommentTracker();
CommentTracker ct = new CommentTracker();
ct.markRangeUnchanged(reference, Objects.requireNonNullElse(arguments, reference));
final String methodCallExpression = newDeclaration.getText().substring(reference.getStartOffsetInParent());
String methodCallExpression = newDeclaration.getText().substring(reference.getStartOffsetInParent());
ct.replaceAndRestoreComments(newDeclaration, methodCallExpression);
}
}

View File

@@ -1,7 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.file.impl;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
@@ -26,15 +26,15 @@ public final class JavaOutOfSourcesResolveScopeProvider extends ResolveScopeProv
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, @NotNull Project project) {
// For java only! For other languages resolve may be implemented with different rules, requiring larger scope.
final FileType type = file.getFileType();
FileType type = file.getFileType();
if (type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() == JavaLanguage.INSTANCE) {
ProjectFileIndex index = project.isDefault() ? null : ProjectRootManager.getInstance(project).getFileIndex();
if (index == null) {
return GlobalSearchScope.fileScope(project, file);
}
if (index.isInContent(file) && !index.isInSource(file)) {
final PsiFile psi = PsiManager.getInstance(project).findFile(file);
if (!HighlightClassUtil.isJavaHashBangScript(psi)) {
PsiFile psi = PsiManager.getInstance(project).findFile(file);
if (psi == null || !JavaHighlightUtil.isJavaHashBangScript(psi)) {
return GlobalSearchScope.fileScope(project, file);
}
}

View File

@@ -3,7 +3,7 @@ package com.intellij.codeInspection.wrongPackageStatement;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.JavaErrorBundle;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInspection.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Comparing;
@@ -33,7 +33,7 @@ public class WrongPackageStatementInspection extends AbstractBaseJavaLocalInspec
if (FileTypeUtils.isInServerPageFile(file)) return null;
PsiJavaFile javaFile = (PsiJavaFile)file;
if (HighlightClassUtil.isJavaHashBangScript(javaFile)) return null;
if (JavaHighlightUtil.isJavaHashBangScript(javaFile)) return null;
PsiDirectory directory = javaFile.getContainingDirectory();
if (directory == null) return null;

View File

@@ -1,7 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.daemon;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.ide.scratch.ScratchUtil;
import com.intellij.openapi.roots.JavaProjectRootsUtil;
@@ -18,7 +18,7 @@ public class JavaProblemHighlightFilter extends ProblemHighlightFilter {
return psiFile.getFileType() != JavaFileType.INSTANCE ||
!JavaProjectRootsUtil.isOutsideJavaSourceRoot(psiFile) ||
ScratchUtil.isScratch(psiFile.getVirtualFile()) ||
HighlightClassUtil.isJavaHashBangScript(psiFile);
JavaHighlightUtil.isJavaHashBangScript(psiFile);
}
@Override

View File

@@ -2,7 +2,7 @@
package com.intellij.java.codeInsight.daemon
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
import com.intellij.psi.CommonClassNames
import com.intellij.psi.PsiClass
@@ -38,7 +38,7 @@ class LightJava11HighlightingTest : LightJavaCodeInsightFixtureTestCase() {
|i*<error descr="Expression expected"><error descr="Unexpected token">*</error></error>;
|}}""".trimMargin())
myFixture.checkHighlighting()
Assert.assertTrue(HighlightClassUtil.isJavaHashBangScript(file))
Assert.assertTrue(JavaHighlightUtil.isJavaHashBangScript(file))
}
private fun doTest() {