mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-18 20:41:22 +07:00
[java-highlighting] Display error if record patterns in for-each loops aren't available (IDEA-309351)
GitOrigin-RevId: 0919de47769682aff2c016920175a74d89c9f7b6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9e8bae7d62
commit
608c99ed4d
@@ -690,6 +690,12 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
@Override
|
||||
public void visitForeachStatement(@NotNull PsiForeachStatement statement) {
|
||||
add(checkFeature(statement, HighlightingFeature.FOR_EACH));
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
PsiForeachDeclarationElement iterationDeclaration = statement.getIterationDeclaration();
|
||||
if (iterationDeclaration instanceof PsiPattern) {
|
||||
add(checkFeature(iterationDeclaration, HighlightingFeature.RECORD_PATTERNS_IN_FOR_EACH));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1802,12 +1808,17 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
public void visitVariable(@NotNull PsiVariable variable) {
|
||||
super.visitVariable(variable);
|
||||
if (variable instanceof PsiPatternVariable) {
|
||||
PsiElement context = PsiTreeUtil.getParentOfType(variable, PsiInstanceOfExpression.class, PsiCaseLabelElementList.class);
|
||||
HighlightingFeature feature = context instanceof PsiInstanceOfExpression ?
|
||||
HighlightingFeature.PATTERNS :
|
||||
HighlightingFeature.PATTERNS_IN_SWITCH;
|
||||
PsiIdentifier varIdentifier = ((PsiPatternVariable)variable).getNameIdentifier();
|
||||
add(checkFeature(varIdentifier, feature));
|
||||
PsiElement context = PsiTreeUtil.getParentOfType(variable,
|
||||
PsiInstanceOfExpression.class,
|
||||
PsiCaseLabelElementList.class,
|
||||
PsiForeachStatement.class);
|
||||
if (!(context instanceof PsiForeachStatement)) {
|
||||
HighlightingFeature feature = context instanceof PsiInstanceOfExpression ?
|
||||
HighlightingFeature.PATTERNS :
|
||||
HighlightingFeature.PATTERNS_IN_SWITCH;
|
||||
PsiIdentifier varIdentifier = ((PsiPatternVariable)variable).getNameIdentifier();
|
||||
add(checkFeature(varIdentifier, feature));
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!myHolder.hasErrorResults()) add(HighlightUtil.checkVarTypeApplicability(variable));
|
||||
|
||||
@@ -48,7 +48,8 @@ public enum HighlightingFeature {
|
||||
INNER_STATICS(LanguageLevel.JDK_16, "feature.inner.statics"),
|
||||
PATTERNS_IN_SWITCH(LanguageLevel.JDK_17_PREVIEW, "feature.patterns.in.switch"),
|
||||
GUARDED_AND_PARENTHESIZED_PATTERNS(LanguageLevel.JDK_17_PREVIEW, "feature.guarded.and.parenthesised.patterns"),
|
||||
PATTERN_GUARDS_AND_RECORD_PATTERNS(LanguageLevel.JDK_19_PREVIEW, "feature.pattern.guard.and.record.patterns");
|
||||
PATTERN_GUARDS_AND_RECORD_PATTERNS(LanguageLevel.JDK_19_PREVIEW, "feature.pattern.guard.and.record.patterns"),
|
||||
RECORD_PATTERNS_IN_FOR_EACH(LanguageLevel.JDK_20_PREVIEW, "feature.record.patterns.in.for.each");
|
||||
|
||||
public static final @NonNls String JDK_INTERNAL_PREVIEW_FEATURE = "jdk.internal.PreviewFeature";
|
||||
public static final @NonNls String JDK_INTERNAL_JAVAC_PREVIEW_FEATURE = "jdk.internal.javac.PreviewFeature";
|
||||
|
||||
Reference in New Issue
Block a user