mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-highlighting] Preview warning migrated
Also improve reporting, different messages for errors and warnings; reflective preview use reported by inspection Part of IDEA-365344 Create a new Java error highlighter with minimal dependencies (PSI only) GitOrigin-RevId: d7c85058aed3202d0599fc879a61c0fa56388fea
This commit is contained in:
committed by
intellij-monorepo-bot
parent
12e8d62118
commit
178b721cf7
+23
-10
@@ -26,7 +26,6 @@ public final class JavaPreviewFeatureUtil {
|
||||
public static final @NonNls String JDK_INTERNAL_JAVAC_PREVIEW_FEATURE = "jdk.internal.javac.PreviewFeature";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param feature preview feature
|
||||
* @param ref reference to highlight ({@link PsiJavaCodeReferenceElement} or {@link PsiJavaModuleReferenceElement})
|
||||
* @param target target object (module, class, method, field)
|
||||
@@ -37,7 +36,10 @@ public final class JavaPreviewFeatureUtil {
|
||||
@NotNull PsiElement ref,
|
||||
@NotNull PsiModifierListOwner target,
|
||||
@NotNull PsiAnnotation annotation
|
||||
) {
|
||||
) {
|
||||
/**
|
||||
* @return user-readable name of the reference or target object to be used in the error message
|
||||
*/
|
||||
public @NlsSafe String targetName() {
|
||||
if (target instanceof PsiJavaModule module) {
|
||||
return module.getName();
|
||||
@@ -67,10 +69,21 @@ public final class JavaPreviewFeatureUtil {
|
||||
}
|
||||
return requireNonNullElse(name, ref.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if
|
||||
*/
|
||||
public boolean isReflective() {
|
||||
return Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(annotation(), "reflective"));
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable PreviewFeatureUsage getPreviewFeatureUsage(@NotNull PsiElement e) {
|
||||
if (e instanceof PsiJavaCodeReferenceElement refElement) {
|
||||
|
||||
/**
|
||||
* @param element element to check (reference or a statement from a module-info file)
|
||||
* @return PreviewFeatureUsage object if the element refers to a preview API feature; null otherwise
|
||||
*/
|
||||
public static @Nullable PreviewFeatureUsage getPreviewFeatureUsage(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiJavaCodeReferenceElement refElement) {
|
||||
PsiElement resolved = refElement.resolve();
|
||||
if (resolved instanceof PsiModifierListOwner owner) {
|
||||
PsiAnnotation annotation = getPreviewFeatureAnnotationInternal(owner);
|
||||
@@ -80,7 +93,7 @@ public final class JavaPreviewFeatureUtil {
|
||||
return new PreviewFeatureUsage(feature, refElement, owner, annotation);
|
||||
}
|
||||
}
|
||||
else if (e instanceof PsiRequiresStatement requiresStatement) {
|
||||
else if (element instanceof PsiRequiresStatement requiresStatement) {
|
||||
PsiJavaModule module = requiresStatement.resolve();
|
||||
if (module == null) return null;
|
||||
|
||||
@@ -92,17 +105,17 @@ public final class JavaPreviewFeatureUtil {
|
||||
return new PreviewFeatureUsage(feature, moduleRef, module, annotation);
|
||||
}
|
||||
}
|
||||
else if (e instanceof PsiProvidesStatement providesStatement) {
|
||||
else if (element instanceof PsiProvidesStatement providesStatement) {
|
||||
PsiReferenceList list = providesStatement.getImplementationList();
|
||||
if (list == null) return null;
|
||||
|
||||
for (PsiJavaCodeReferenceElement element : list.getReferenceElements()) {
|
||||
PsiElement resolved = element.resolve();
|
||||
for (PsiJavaCodeReferenceElement ref : list.getReferenceElements()) {
|
||||
PsiElement resolved = ref.resolve();
|
||||
if (resolved instanceof PsiClass psiClass) {
|
||||
PsiAnnotation annotation = getPreviewFeatureAnnotationInternal(psiClass);
|
||||
JavaFeature feature = fromPreviewFeatureAnnotation(annotation);
|
||||
if (feature == null) continue;
|
||||
return new PreviewFeatureUsage(feature, element, psiClass, annotation);
|
||||
return new PreviewFeatureUsage(feature, ref, psiClass, annotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
insufficient.language.level={0} are not supported at language level ''{1}''
|
||||
illegal.unicode.escape=Illegal Unicode escape sequence
|
||||
illegal.character=Illegal character: {0}
|
||||
preview.api.usage={0} is a preview API and may be removed in a future release
|
||||
preview.api.usage={0} is a preview API and is disabled by default
|
||||
|
||||
annotation.not.allowed.here=Annotations are not allowed here
|
||||
annotation.not.applicable=''@{0}'' not applicable to {1}
|
||||
|
||||
+30
-7
@@ -2,6 +2,7 @@
|
||||
package com.intellij.java.codeserver.highlighting;
|
||||
|
||||
import com.intellij.codeInsight.UnhandledExceptions;
|
||||
import com.intellij.java.codeserver.core.JavaPreviewFeatureUtil;
|
||||
import com.intellij.java.codeserver.highlighting.errors.JavaCompilationError;
|
||||
import com.intellij.java.codeserver.highlighting.errors.JavaErrorKinds;
|
||||
import com.intellij.lang.ASTNode;
|
||||
@@ -33,6 +34,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.intellij.java.codeserver.highlighting.errors.JavaErrorKinds.PREVIEW_API_USAGE;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
@@ -203,6 +205,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
if (!hasErrorResults()) myTypeChecker.checkArrayType(type);
|
||||
if (!hasErrorResults()) myGenericsChecker.checkReferenceTypeUsedAsTypeArgument(type);
|
||||
if (!hasErrorResults()) myGenericsChecker.checkWildcardUsage(type);
|
||||
if (!hasErrorResults()) checkPreviewFeature(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,6 +305,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
if (!hasErrorResults()) myExpressionChecker.checkNewExpression(expression, type);
|
||||
if (!hasErrorResults()) myGenericsChecker.checkTypeParameterInstantiation(expression);
|
||||
if (!hasErrorResults()) myGenericsChecker.checkGenericArrayCreation(expression, type);
|
||||
if (!hasErrorResults()) checkPreviewFeature(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,6 +417,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
}
|
||||
if (!hasErrorResults()) myFunctionChecker.checkMethodReferenceResolve(expression, results, functionalInterfaceType);
|
||||
if (!hasErrorResults()) myFunctionChecker.checkMethodReferenceReturnType(expression, result, functionalInterfaceType);
|
||||
if (!hasErrorResults() && method instanceof PsiModifierListOwner) checkPreviewFeature(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -517,6 +522,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
if (!hasErrorResults()) myClassChecker.checkSuperQualifierType(expression);
|
||||
if (!hasErrorResults()) myExpressionChecker.checkMethodCall(expression);
|
||||
if (!hasErrorResults()) visitExpression(expression);
|
||||
if (!hasErrorResults()) checkPreviewFeature(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -616,7 +622,13 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
super.visitModule(module);
|
||||
if (!hasErrorResults()) checkFeature(module, JavaFeature.MODULES);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitModuleStatement(@NotNull PsiStatement statement) {
|
||||
super.visitModuleStatement(statement);
|
||||
if (!hasErrorResults()) checkPreviewFeature(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitImportModuleStatement(@NotNull PsiImportModuleStatement statement) {
|
||||
super.visitImportModuleStatement(statement);
|
||||
@@ -631,9 +643,8 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
@Override
|
||||
public void visitImportStatement(@NotNull PsiImportStatement statement) {
|
||||
super.visitImportStatement(statement);
|
||||
if (!hasErrorResults()) {
|
||||
myImportChecker.checkSingleImportClassConflict(statement);
|
||||
}
|
||||
if (!hasErrorResults()) myImportChecker.checkSingleImportClassConflict(statement);
|
||||
if (!hasErrorResults()) checkPreviewFeature(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -674,6 +685,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasErrorResults()) checkPreviewFeature(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -766,6 +778,7 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
}
|
||||
if (!hasErrorResults()) myGenericsChecker.checkAccessStaticFieldFromEnumConstructor(expression, result);
|
||||
myExpressionChecker.checkUnqualifiedSuperInDefaultMethod(expression, qualifierExpression);
|
||||
if (!hasErrorResults() && resolved instanceof PsiModifierListOwner) checkPreviewFeature(expression);
|
||||
}
|
||||
|
||||
|
||||
@@ -886,9 +899,8 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
myExpressionChecker.checkLocalClassReferencedFromAnotherSwitchBranch(ref, aClass);
|
||||
}
|
||||
if (!hasErrorResults()) myGenericsChecker.checkRawOnParameterizedType(ref, resolved);
|
||||
if (!hasErrorResults()) {
|
||||
myExpressionChecker.checkAmbiguousConstructorCall(ref, resolved);
|
||||
}
|
||||
if (!hasErrorResults()) myExpressionChecker.checkAmbiguousConstructorCall(ref, resolved);
|
||||
if (!hasErrorResults() && resolved instanceof PsiModifierListOwner) checkPreviewFeature(ref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1244,4 +1256,15 @@ final class JavaErrorVisitor extends JavaElementVisitor {
|
||||
report(JavaErrorKinds.UNSUPPORTED_FEATURE.create(element, feature));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPreviewFeature(@NotNull PsiElement element) {
|
||||
if (myLanguageLevel.isPreview()) return;
|
||||
JavaPreviewFeatureUtil.PreviewFeatureUsage usage = JavaPreviewFeatureUtil.getPreviewFeatureUsage(element);
|
||||
if (usage == null || usage.isReflective()) return;
|
||||
|
||||
if (!usage.feature().isSufficient(myLanguageLevel)) {
|
||||
report(PREVIEW_API_USAGE.create(element, usage));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-11
@@ -627,18 +627,9 @@ public final class HighlightUtil {
|
||||
@NotNull JavaFeature feature,
|
||||
@NotNull LanguageLevel level,
|
||||
@NotNull PsiFile file) {
|
||||
return checkFeature(element, feature, level, file, null, HighlightInfoType.ERROR);
|
||||
}
|
||||
|
||||
static @Nullable HighlightInfo.Builder checkFeature(@NotNull PsiElement element,
|
||||
@NotNull JavaFeature feature,
|
||||
@NotNull LanguageLevel level,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable @NlsContexts.DetailedDescription String message,
|
||||
@NotNull HighlightInfoType highlightInfoType) {
|
||||
if (!feature.isSufficient(level)) {
|
||||
message = message == null ? getUnsupportedFeatureMessage(feature, level, file) : message;
|
||||
HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(highlightInfoType).range(element).descriptionAndTooltip(message);
|
||||
String message = getUnsupportedFeatureMessage(feature, level, file);
|
||||
HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(message);
|
||||
registerIncreaseLanguageLevelFixes(file, feature, info);
|
||||
return info;
|
||||
}
|
||||
|
||||
+11
-92
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
@@ -9,7 +8,6 @@ import com.intellij.codeInsight.daemon.impl.HighlightVisitor;
|
||||
import com.intellij.codeInsight.intention.CommonIntentionAction;
|
||||
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
|
||||
import com.intellij.java.codeserver.core.JavaPreviewFeatureUtil;
|
||||
import com.intellij.java.codeserver.core.JavaPsiModuleUtil;
|
||||
import com.intellij.java.codeserver.highlighting.JavaErrorCollector;
|
||||
import com.intellij.java.codeserver.highlighting.errors.JavaCompilationError;
|
||||
@@ -236,12 +234,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults()) GenericsHighlightUtil.checkTypeParameterOverrideEquivalentMethods(aClass, myLanguageLevel, myErrorSink, myOverrideEquivalentMethodsVisitedClasses, myOverrideEquivalentMethodsErrors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitImportStaticStatement(@NotNull PsiImportStaticStatement statement) {
|
||||
visitElement(statement);
|
||||
if (!hasErrorResults()) checkPreviewFeature(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIdentifier(@NotNull PsiIdentifier identifier) {
|
||||
PsiElement parent = identifier.getParent();
|
||||
@@ -254,14 +246,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
super.visitIdentifier(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitImportStatement(@NotNull PsiImportStatement statement) {
|
||||
super.visitImportStatement(statement);
|
||||
if (!hasErrorResults()) {
|
||||
checkPreviewFeature(statement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitImportStaticReferenceElement(@NotNull PsiImportStaticReferenceElement ref) {
|
||||
super.visitImportStaticReferenceElement(ref);
|
||||
@@ -277,14 +261,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults()) add(ModuleHighlightUtil.checkModuleReference(statement));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
|
||||
visitExpression(expression);
|
||||
if (!hasErrorResults()) {
|
||||
checkPreviewFeature(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModifierList(@NotNull PsiModifierList list) {
|
||||
super.visitModifierList(list);
|
||||
@@ -304,15 +280,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
if (!hasErrorResults()) visitExpression(expression);
|
||||
|
||||
if (!hasErrorResults()) {
|
||||
checkPreviewFeature(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPackageStatement(@NotNull PsiPackageStatement statement) {
|
||||
super.visitPackageStatement(statement);
|
||||
@@ -321,18 +288,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
super.visitReferenceElement(ref);
|
||||
JavaResolveResult result = ref instanceof PsiExpression ? resolveOptimised(ref, myFile) : doVisitReferenceElement(ref);
|
||||
if (result != null) {
|
||||
PsiElement resolved = result.getElement();
|
||||
if (!hasErrorResults() && resolved instanceof PsiModifierListOwner) {
|
||||
checkPreviewFeature(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JavaResolveResult doVisitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
JavaResolveResult result = resolveOptimised(ref, myFile);
|
||||
if (result == null) return null;
|
||||
@@ -418,9 +373,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults() && myJavaModule == null && qualifierExpression != null) {
|
||||
add(GenericsHighlightUtil.checkMemberSignatureTypesAccessibility(expression));
|
||||
}
|
||||
if (!hasErrorResults() && resolved instanceof PsiModifierListOwner) {
|
||||
checkPreviewFeature(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,21 +381,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
|
||||
if (toReportFunctionalExpressionProblemOnParent(parent)) return;
|
||||
PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null && !PsiTypesUtil.allTypeParametersResolved(expression, functionalInterfaceType)) return;
|
||||
|
||||
JavaResolveResult[] results = expression.multiResolve(true);
|
||||
JavaResolveResult result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
|
||||
PsiElement method = result.getElement();
|
||||
|
||||
if (functionalInterfaceType != null) {
|
||||
if (!hasErrorResults()) {
|
||||
if (!hasErrorResults() && PsiTypesUtil.allTypeParametersResolved(expression, functionalInterfaceType)) {
|
||||
add(LambdaHighlightingUtil.checkFunctionalInterfaceTypeAccessible(myFile.getProject(), expression, functionalInterfaceType));
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasErrorResults() && method instanceof PsiModifierListOwner) {
|
||||
checkPreviewFeature(expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,14 +429,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults()) model.checkSwitchLabelValues(myErrorSink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeElement(@NotNull PsiTypeElement type) {
|
||||
super.visitTypeElement(type);
|
||||
if (!hasErrorResults()) {
|
||||
checkPreviewFeature(type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModule(@NotNull PsiJavaModule module) {
|
||||
super.visitModule(module);
|
||||
@@ -506,14 +440,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults()) add(ModuleHighlightUtil.checkFileLocation(module, myFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitModuleStatement(@NotNull PsiStatement statement) {
|
||||
super.visitModuleStatement(statement);
|
||||
if (!hasErrorResults()) {
|
||||
checkPreviewFeature(statement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitRequiresStatement(@NotNull PsiRequiresStatement statement) {
|
||||
super.visitRequiresStatement(statement);
|
||||
@@ -535,6 +461,16 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) {
|
||||
super.visitReferenceElement(ref);
|
||||
if (!(ref instanceof PsiExpression)) {
|
||||
doVisitReferenceElement(ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void visitUsesStatement(@NotNull PsiUsesStatement statement) {
|
||||
super.visitUsesStatement(statement);
|
||||
@@ -550,21 +486,4 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (!hasErrorResults()) ModuleHighlightUtil.checkServiceImplementations(statement, myFile, myErrorSink);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPreviewFeature(@NotNull PsiElement element) {
|
||||
if (myLanguageLevel.isPreview()) return;
|
||||
JavaPreviewFeatureUtil.PreviewFeatureUsage usage = JavaPreviewFeatureUtil.getPreviewFeatureUsage(element);
|
||||
if (usage != null) {
|
||||
boolean isReflective = Boolean.TRUE.equals(AnnotationUtil.getBooleanAttributeValue(usage.annotation(), "reflective"));
|
||||
|
||||
HighlightInfoType type = isReflective ? HighlightInfoType.WARNING : HighlightInfoType.ERROR;
|
||||
|
||||
HighlightInfo.Builder highlightInfo =
|
||||
HighlightUtil.checkFeature(element, usage.feature(), myLanguageLevel, element.getContainingFile(),
|
||||
PREVIEW_API_USAGE.description(element, usage).toString(), type);
|
||||
if (highlightInfo != null) {
|
||||
myErrorSink.accept(highlightInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -96,6 +96,7 @@ final class JavaErrorFixProvider {
|
||||
|
||||
JavaErrorFixProvider() {
|
||||
multi(UNSUPPORTED_FEATURE, error -> HighlightUtil.getIncreaseLanguageLevelFixes(error.psi(), error.context()));
|
||||
multi(PREVIEW_API_USAGE, error -> HighlightUtil.getIncreaseLanguageLevelFixes(error.psi(), error.context().feature()));
|
||||
JavaFixProvider<PsiElement, Object> genericRemover = error -> myFactory.createDeleteFix(error.psi());
|
||||
for (JavaErrorKind<?, ?> kind : List.of(ANNOTATION_MEMBER_THROWS_NOT_ALLOWED, ANNOTATION_ATTRIBUTE_DUPLICATE,
|
||||
ANNOTATION_NOT_ALLOWED_EXTENDS, RECEIVER_STATIC_CONTEXT, RECEIVER_WRONG_POSITION,
|
||||
|
||||
+12
-6
@@ -3,8 +3,9 @@ package com.intellij.codeInspection.preview;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.java.codeserver.core.JavaPreviewFeatureUtil;
|
||||
import com.intellij.java.codeserver.highlighting.errors.JavaErrorKinds;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiImportStatementBase;
|
||||
@@ -21,15 +22,17 @@ public final class PreviewFeatureInspection extends LocalInspectionTool {
|
||||
|
||||
@Override
|
||||
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
if (!PsiUtil.getLanguageLevel(holder.getFile()).isPreview()) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
|
||||
LanguageLevel level = PsiUtil.getLanguageLevel(holder.getFile());
|
||||
boolean preview = level.isPreview();
|
||||
return new PsiElementVisitor() {
|
||||
@Override
|
||||
public void visitElement(@NotNull PsiElement element) {
|
||||
JavaPreviewFeatureUtil.PreviewFeatureUsage usage = JavaPreviewFeatureUtil.getPreviewFeatureUsage(element);
|
||||
if (usage != null) {
|
||||
if (!preview && !usage.isReflective()) {
|
||||
// reported as a compilation error
|
||||
return;
|
||||
}
|
||||
// Do not report warnings in imports, because they cannot be suppressed and javac doesn't report them
|
||||
if (element.getParent() instanceof PsiImportStatementBase) return;
|
||||
if (element instanceof PsiReferenceExpression ref) {
|
||||
@@ -38,7 +41,10 @@ public final class PreviewFeatureInspection extends LocalInspectionTool {
|
||||
element = nameElement;
|
||||
}
|
||||
}
|
||||
holder.registerProblem(element, JavaErrorKinds.PREVIEW_API_USAGE.description(element, usage).toString());
|
||||
holder.registerProblem(element,
|
||||
usage.isReflective()
|
||||
? JavaBundle.message("preview.api.usage.reflective", usage.targetName())
|
||||
: JavaBundle.message("preview.api.usage", usage.targetName()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+14
-14
@@ -1,23 +1,23 @@
|
||||
|
||||
import <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeature</error>;
|
||||
import <warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeatureReflective</warning>;
|
||||
import <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">com.mycom.FirstPreviewFeature</error>;
|
||||
import com.mycom.FirstPreviewFeatureReflective;
|
||||
|
||||
class Main {
|
||||
public Main(String value) { }
|
||||
{
|
||||
var a = new <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>.Outer.Inner();
|
||||
var b = new <warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective.Outer is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.Outer</warning>.Inner</warning>();
|
||||
<error descr="com.mycom.FirstPreviewFeature.Outer.Inner#z is a preview API and may be removed in a future release">a.z</error>();
|
||||
<warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner#z is a preview API and may be removed in a future release">b.z</warning>();
|
||||
Runnable r1 = <error descr="com.mycom.FirstPreviewFeature.Outer.Inner#z is a preview API and may be removed in a future release">a::z</error>;
|
||||
Runnable r2 = <warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner#z is a preview API and may be removed in a future release">b::z</warning>;
|
||||
new Main(<error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>.KEY);
|
||||
new Main(<warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.KEY</warning>);
|
||||
var a = new <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>.Outer.Inner();
|
||||
var b = new <warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner is a reflective preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective.Outer is a reflective preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.Outer</warning>.Inner</warning>();
|
||||
<error descr="com.mycom.FirstPreviewFeature.Outer.Inner#z is a preview API and is disabled by default">a.z</error>();
|
||||
b.<warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner#z is a reflective preview API and may be removed in a future release">z</warning>();
|
||||
Runnable r1 = <error descr="com.mycom.FirstPreviewFeature.Outer.Inner#z is a preview API and is disabled by default">a::z</error>;
|
||||
Runnable r2 = b::<warning descr="com.mycom.FirstPreviewFeatureReflective.Outer.Inner#z is a reflective preview API and may be removed in a future release">z</warning>;
|
||||
new Main(<error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>.KEY);
|
||||
new Main(<warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.<warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a reflective preview API and may be removed in a future release">KEY</warning>);
|
||||
|
||||
new Main(<error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>.KEY + "");
|
||||
new Main(<warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.KEY</warning> + "");
|
||||
new Main(<error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>.KEY + "");
|
||||
new Main(<warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.<warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a reflective preview API and may be removed in a future release">KEY</warning> + "");
|
||||
|
||||
new Main("" + <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>.KEY);
|
||||
new Main("" + <warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.KEY</warning>);
|
||||
new Main("" + <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>.KEY);
|
||||
new Main("" + <warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.<warning descr="com.mycom.FirstPreviewFeatureReflective#KEY is a reflective preview API and may be removed in a future release">KEY</warning>);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
|
||||
import <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeature</error>;
|
||||
import <warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeatureReflective</warning>;
|
||||
import <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">com.mycom.FirstPreviewFeature</error>;
|
||||
import com.mycom.FirstPreviewFeatureReflective;
|
||||
|
||||
class Main {
|
||||
{
|
||||
<error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>.g();
|
||||
Runnable r1 = <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">FirstPreviewFeature</error>::g;
|
||||
<warning descr="com.mycom.FirstPreviewFeatureReflective#g is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.g</warning>();
|
||||
Runnable r2 = <warning descr="com.mycom.FirstPreviewFeatureReflective#g is a preview API and may be removed in a future release"><warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>::g</warning>;
|
||||
<error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>.g();
|
||||
Runnable r1 = <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">FirstPreviewFeature</error>::g;
|
||||
<warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>.<warning descr="com.mycom.FirstPreviewFeatureReflective#g is a reflective preview API and may be removed in a future release">g</warning>();
|
||||
Runnable r2 = <warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">FirstPreviewFeatureReflective</warning>::<warning descr="com.mycom.FirstPreviewFeatureReflective#g is a reflective preview API and may be removed in a future release">g</warning>;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
|
||||
class A implements <error descr="com.mycom.FirstPreviewFeature is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeature</error> {
|
||||
class A implements <error descr="com.mycom.FirstPreviewFeature is a preview API and is disabled by default">com.mycom.FirstPreviewFeature</error> {
|
||||
public void f() {}
|
||||
|
||||
static class B implements <warning descr="com.mycom.FirstPreviewFeatureReflective is a preview API and may be removed in a future release">com.mycom.FirstPreviewFeatureReflective</warning> {
|
||||
static class B implements <warning descr="com.mycom.FirstPreviewFeatureReflective is a reflective preview API and may be removed in a future release">com.mycom.FirstPreviewFeatureReflective</warning> {
|
||||
public void f() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1971,4 +1971,6 @@ auto.test.on=Auto-test on
|
||||
disable.auto.test=Disable auto-test
|
||||
|
||||
error.no.annotation.class.found=No annotation class found
|
||||
java.psi.element.comment.completion.command.text=Comment element
|
||||
java.psi.element.comment.completion.command.text=Comment element
|
||||
preview.api.usage={0} is a preview API and may be removed in a future release
|
||||
preview.api.usage.reflective={0} is a reflective preview API and may be removed in a future release
|
||||
|
||||
Reference in New Issue
Block a user