diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java index f63ea55608a2..7bb318192ba9 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/RefCountHolder.java @@ -254,11 +254,10 @@ public class RefCountHolder { return true; } - public boolean isReferencedForRead(@NotNull PsiElement element) { - LOG.assertTrue(element instanceof PsiVariable); + public boolean isReferencedForRead(@NotNull PsiVariable variable) { List array; synchronized (myLocalRefsMap) { - array = myLocalRefsMap.getKeysByValue(element); + array = myLocalRefsMap.getKeysByValue(variable); } if (array == null) return false; for (PsiReference ref : array) { @@ -278,11 +277,10 @@ public class RefCountHolder { return false; } - public boolean isReferencedForWrite(@NotNull PsiElement element) { - LOG.assertTrue(element instanceof PsiVariable); + public boolean isReferencedForWrite(@NotNull PsiVariable variable) { List array; synchronized (myLocalRefsMap) { - array = myLocalRefsMap.getKeysByValue(element); + array = myLocalRefsMap.getKeysByValue(variable); } if (array == null) return false; for (PsiReference ref : array) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java index ad17594a8c1f..10b933018455 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java @@ -163,7 +163,7 @@ public class AnnotationsHighlightUtil { return null; } - static HighlightInfo checkDuplicateAnnotations(@NotNull PsiAnnotation annotationToCheck) { + static HighlightInfo checkDuplicateAnnotations(@NotNull PsiAnnotation annotationToCheck, @NotNull LanguageLevel languageLevel) { PsiAnnotationOwner owner = annotationToCheck.getOwner(); if (owner == null) return null; @@ -186,7 +186,7 @@ public class AnnotationsHighlightUtil { } } else if (isAnnotationRepeatedTwice(owner, annotationType.getQualifiedName())) { - if (!PsiUtil.isLanguageLevel8OrHigher(annotationToCheck)) { + if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { String description = JavaErrorMessages.message("annotation.duplicate.annotation"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create(); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 1d7e8b4011fa..410be64ee738 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -506,36 +506,29 @@ public class HighlightMethodUtil { if (methodCandidate2 != null) { return null; } + if (element != null && !resolveResult.isAccessible()) { + description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult); + elementToHighlight = referenceToMethod.getReferenceNameElement(); + } + else if (element != null && !resolveResult.isStaticsScopeCorrect()) { + description = HighlightUtil.buildProblemWithStaticDescription(element); + elementToHighlight = referenceToMethod.getReferenceNameElement(); + } else { - if (element != null && !resolveResult.isAccessible()) { - description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult); - elementToHighlight = referenceToMethod.getReferenceNameElement(); - } - else if (element != null && !resolveResult.isStaticsScopeCorrect()) { - description = HighlightUtil.buildProblemWithStaticDescription(element); + String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list); + description = JavaErrorMessages.message("cannot.resolve.method", methodName); + if (candidates.length == 0) { elementToHighlight = referenceToMethod.getReferenceNameElement(); + highlightInfoType = HighlightInfoType.WRONG_REF; } else { - String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list); - description = JavaErrorMessages.message("cannot.resolve.method", methodName); - if (candidates.length == 0) { - elementToHighlight = referenceToMethod.getReferenceNameElement(); - highlightInfoType = HighlightInfoType.WRONG_REF; - } - else { - return null; - } + return null; } - toolTip = XmlStringUtil.escapeString(description); } + toolTip = XmlStringUtil.escapeString(description); HighlightInfo info = HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight).description(description).escapedToolTip(toolTip).create(); - if (methodCandidate2 == null) { - registerMethodCallIntentions(info, methodCall, list, resolveHelper); - } - if (!resolveResult.isAccessible() && resolveResult.isStaticsScopeCorrect() && methodCandidate2 != null) { - HighlightUtil.registerAccessQuickFixAction((PsiMember)element, referenceToMethod, info, resolveResult.getCurrentFileResolveScope()); - } + registerMethodCallIntentions(info, methodCall, list, resolveHelper); if (element != null && !resolveResult.isStaticsScopeCorrect()) { HighlightUtil.registerStaticProblemQuickFixAction(element, info, referenceToMethod); } @@ -1014,7 +1007,7 @@ public class HighlightMethodUtil { } @Nullable - static HighlightInfo checkMethodCanHaveBody(PsiMethod method, @NotNull LanguageLevel languageLevel,@NotNull PsiFile containingFile) { + static HighlightInfo checkMethodCanHaveBody(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) { PsiClass aClass = method.getContainingClass(); boolean hasNoBody = method.getBody() == null; boolean isInterface = aClass != null && aClass.isInterface(); @@ -1035,7 +1028,7 @@ public class HighlightMethodUtil { else if (isInterface) { if (!isExtension && !isStatic) { description = JavaErrorMessages.message("interface.methods.cannot.have.body"); - if (PsiUtil.isLanguageLevel8OrHigher(method)) { + if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.DEFAULT, true, false)); additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, true, false)); } @@ -1242,7 +1235,7 @@ public class HighlightMethodUtil { } return createIncompatibleReturnTypeMessage(currentMethod, otherSuperMethod, otherSuperReturnType, currentType, JavaErrorMessages.message("unrelated.overriding.methods.return.types"), - false ? currentMethod.getReturnTypeElement().getTextRange() : TextRange.EMPTY_RANGE); + TextRange.EMPTY_RANGE); } return null; } @@ -1262,7 +1255,7 @@ public class HighlightMethodUtil { if (aClass.equals(containingClass)) continue; //to be checked at method level if (aClass.isInterface() && !containingClass.isInterface()) continue; - HighlightInfo highlightInfo = null; + HighlightInfo highlightInfo; if (allAbstracts) { superSignatures = new ArrayList(superSignatures); superSignatures.add(signature); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index ba0e0fd47659..0dc8e3df8fec 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -299,12 +299,12 @@ public class HighlightUtil extends HighlightUtilBase { @Nullable - static HighlightInfo checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression) { + static HighlightInfo checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression, @NotNull LanguageLevel languageLevel) { final PsiTypeElement castTypeElement = expression.getCastType(); if (castTypeElement == null) return null; PsiType castType = castTypeElement.getType(); if (isIntersection(castTypeElement, castType)) { - if (PsiUtil.isLanguageLevel8OrHigher(expression)) { + if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { final PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class); if (conjuncts != null) { final List conjList = new ArrayList(Arrays.asList(conjuncts)); @@ -680,8 +680,8 @@ public class HighlightUtil extends HighlightUtilBase { } @Nullable - public static HighlightInfo checkUnderscore(@NotNull PsiIdentifier identifier, @NotNull PsiVariable variable) { - if ("_".equals(variable.getName()) && PsiUtil.isLanguageLevel8OrHigher(variable)) { + public static HighlightInfo checkUnderscore(@NotNull PsiIdentifier identifier, @NotNull PsiVariable variable, @NotNull LanguageLevel languageLevel) { + if ("_".equals(variable.getName()) && languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { if (variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiLambdaExpression) { String message = JavaErrorMessages.message("underscore.lambda.identifier"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(identifier).descriptionAndTooltip(message).create(); @@ -1416,7 +1416,8 @@ public class HighlightUtil extends HighlightUtilBase { @Nullable static HighlightInfo checkThisOrSuperExpressionInIllegalContext(@NotNull PsiExpression expr, - @Nullable PsiJavaCodeReferenceElement qualifier) { + @Nullable PsiJavaCodeReferenceElement qualifier, + @NotNull LanguageLevel languageLevel) { if (expr instanceof PsiSuperExpression) { final PsiElement parent = expr.getParent(); if (!(parent instanceof PsiReferenceExpression)) { @@ -1442,7 +1443,7 @@ public class HighlightUtil extends HighlightUtilBase { if (aClass == null) return null; if (!InheritanceUtil.hasEnclosingInstanceInScope(aClass, expr, false, false) && - !resolvesToImmediateSuperInterface(expr, qualifier, aClass)) { + !resolvesToImmediateSuperInterface(expr, qualifier, aClass, languageLevel)) { return HighlightClassUtil.reportIllegalEnclosingUsage(expr, null, aClass, expr); } @@ -1492,8 +1493,9 @@ public class HighlightUtil extends HighlightUtilBase { private static boolean resolvesToImmediateSuperInterface(@NotNull PsiExpression expr, @Nullable PsiJavaCodeReferenceElement qualifier, - @NotNull PsiClass aClass) { - if (!(expr instanceof PsiSuperExpression) || qualifier == null || !PsiUtil.isLanguageLevel8OrHigher(expr)) return false; + @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(); if (!(superType instanceof PsiClassType)) return false; final PsiClass superClass = ((PsiClassType)superType).resolve(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 7056319c5883..cbfb5f4f5d65 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -220,7 +220,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkAnnotationType(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkMissingAttributes(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkTargetAnnotationDuplicates(annotation)); - if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkDuplicateAnnotations(annotation)); + if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkDuplicateAnnotations(annotation, myLanguageLevel)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkForeignInnerClassesUsed(annotation)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkFunctionalInterface(annotation, myLanguageLevel)); if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkRepeatableAnnotation(annotation)); @@ -590,7 +590,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } - myHolder.add(HighlightUtil.checkUnderscore(identifier, variable)); + myHolder.add(HighlightUtil.checkUnderscore(identifier, variable, myLanguageLevel)); } else if (parent instanceof PsiClass) { PsiClass aClass = (PsiClass)parent; @@ -833,7 +833,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh PsiElement parent = list.getParent(); if (parent instanceof PsiMethod) { PsiMethod method = (PsiMethod)parent; - if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCanHaveBody(method, myLanguageLevel,myFile)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodCanHaveBody(method, myLanguageLevel)); MethodSignatureBackedByPsiMethod methodSignature = MethodSignatureBackedByPsiMethod.create(method, PsiSubstitutor.EMPTY); if (!method.isConstructor()) { try { @@ -1378,7 +1378,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitSuperExpression(PsiSuperExpression expr) { - myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier())); + myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier(), myLanguageLevel)); if (!myHolder.hasErrorResults()) visitExpression(expr); } @@ -1396,7 +1396,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitThisExpression(PsiThisExpression expr) { - myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier())); + myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier(), myLanguageLevel)); if (!myHolder.hasErrorResults()) { myHolder.add(HighlightUtil.checkMemberReferencedBeforeConstructorCalled(expr, null, myFile)); } @@ -1452,7 +1452,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh public void visitTypeCastExpression(PsiTypeCastExpression typeCast) { super.visitTypeCastExpression(typeCast); try { - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIntersectionInTypeCast(typeCast)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIntersectionInTypeCast(typeCast, myLanguageLevel)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkInconvertibleTypeCast(typeCast)); } catch (IndexNotReadyException ignore) { @@ -1498,7 +1498,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitConditionalExpression(PsiConditionalExpression expression) { super.visitConditionalExpression(expression); - if (PsiUtil.isLanguageLevel8OrHigher(expression) && PsiPolyExpressionUtil.isPolyExpression(expression)) { + if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) && PsiPolyExpressionUtil.isPolyExpression(expression)) { final PsiExpression thenExpression = expression.getThenExpression(); final PsiExpression elseExpression = expression.getElseExpression(); if (thenExpression != null && elseExpression != null) {