Java: move old check to quirks inspection

GitOrigin-RevId: f1201462a504c09c1d4ca10e813c343d03be55ac
This commit is contained in:
Bas Leijdekkers
2023-11-06 11:16:53 +00:00
committed by intellij-monorepo-bot
parent 4a465a87f8
commit 8cbdbab21a
6 changed files with 31 additions and 33 deletions
@@ -251,10 +251,11 @@ inspection.common.if.parts.family=Extract common parts of 'if' statement
inspection.common.if.parts.settings.highlight.when.tail.call=Highlight when the last common statement is a call
inspection.common.if.parts.settings.highlight.else.if=Highlight else-if chains that can be simplified
inspection.compiler.javac.quirks.anno.array.comma.fix=Remove trailing comma
inspection.compiler.javac.quirks.anno.array.comma.problem=Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6).
inspection.compiler.javac.quirks.anno.array.comma.problem=Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)
inspection.compiler.javac.quirks.name=Javac quirks
inspection.compiler.javac.quirks.qualifier.type.args.fix=Remove generic parameter
inspection.compiler.javac.quirks.qualifier.type.args.problem=Generics in qualifier reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6).
inspection.compiler.javac.quirks.qualifier.type.args.problem=Generics in qualifier reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)
inspection.compiler.javac.quirks.illegal.forward.reference=Forward reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)
inspection.quirk.method.reference.return.type.message=Target method return type mentions inaccessible class {0}. This will cause IllegalAccessError at runtime.
# | is replaced with 'left' or 'right'
inspection.constant.on.wrong.side.of.a.comparison.side.option=Constant should be on the|side of a comparison
@@ -968,15 +968,6 @@ public final class GenericsHighlightUtil {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeParameter2).descriptionAndTooltip(message);
}
}
if (!level.isAtLeast(LanguageLevel.JDK_1_7)) {
for (PsiJavaCodeReferenceElement referenceElement : typeParameter1.getExtendsList().getReferenceElements()) {
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"));
}
}
}
}
return null;
}
@@ -1246,8 +1237,7 @@ public final class GenericsHighlightUtil {
return null;
}
static HighlightInfo.Builder checkParametersOnRaw(@NotNull PsiReferenceParameterList refParamList,
LanguageLevel languageLevel) {
static HighlightInfo.Builder checkParametersOnRaw(@NotNull PsiReferenceParameterList refParamList, LanguageLevel languageLevel) {
JavaResolveResult resolveResult = null;
PsiElement parent = refParamList.getParent();
PsiElement qualifier = null;
@@ -8,7 +8,10 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.daemon.impl.quickfix.AddTypeArgumentsFix;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.miscGenerics.RedundantTypeArgsInspection;
import com.intellij.java.analysis.JavaAnalysisBundle;
import com.intellij.modcommand.ModPsiUpdater;
@@ -26,6 +29,7 @@ import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.*;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.ObjectUtils;
import com.siyeh.ig.PsiReplacementUtil;
import org.jetbrains.annotations.Nls;
@@ -90,6 +94,22 @@ public class JavacQuirksInspectionVisitor extends JavaElementVisitor {
}
}
@Override
public void visitTypeParameterList(@NotNull PsiTypeParameterList list) {
if (PsiUtil.isLanguageLevel7OrHigher(list)) return;
PsiTypeParameter[] parameters = list.getTypeParameters();
for (int i = 0; i < parameters.length; i++) {
PsiTypeParameter typeParameter = parameters[i];
for (PsiJavaCodeReferenceElement referenceElement : typeParameter.getExtendsList().getReferenceElements()) {
PsiElement resolve = referenceElement.resolve();
if (resolve instanceof PsiTypeParameter && ArrayUtilRt.find(parameters, resolve) > i) {
myHolder.registerProblem(referenceElement,
JavaAnalysisBundle.message("inspection.compiler.javac.quirks.illegal.forward.reference"));
}
}
}
}
@Override
public void visitTypeCastExpression(final @NotNull PsiTypeCastExpression expression) {
if (PsiUtil.isLanguageLevel7OrHigher(expression)) return;
@@ -20,7 +20,7 @@ class C {
int[] value();
}
@TestAnnotation({0, 1<warning descr="Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6).">,</warning>})
@TestAnnotation({0, 1<warning descr="Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)">,</warning>})
void m() { }
class A<T> {
@@ -31,7 +31,7 @@ class C {
void m(Object o) {
if (o instanceof A<?>.B<?>) {
final A<?>.B<?> b = (A<warning descr="Generics in qualifier reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)."><?></warning>.B<?>)o;
final A<?>.B<?> b = (A<warning descr="Generics in qualifier reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)"><?></warning>.B<?>)o;
b.m(null, null);
}
}
@@ -1,2 +1,3 @@
class A<T extends <error descr="Illegal forward reference">S</error>, S> {
class A<T extends <warning descr="Forward reference may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6)">S</warning>, S> {
T t;
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -257,7 +243,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA107782() { doTest5(false);}
public void testInheritedWithDifferentArgsInTypeParams() { doTest5(false);}
public void testInheritedWithDifferentArgsInTypeParams1() { doTest5(false);}
public void testIllegalForwardReferenceInTypeParameterDefinition() { doTest5(false);}
public void testIllegalForwardReferenceInTypeParameterDefinition() { doTest5(true);}
public void testIDEA57877() { doTest5(false);}
public void testIDEA110568() { doTest5(false);}
public void testTypeParamsCyclicInference() { doTest5(false);}