[java-highlighting] Record Patterns (Second Preview): remove support for named record patterns

IDEA-310052

GitOrigin-RevId: 0128d70c6343a65e44bf14bef7d89aeb94599c71
This commit is contained in:
Andrey Cherkasov
2023-01-15 05:39:26 +00:00
committed by intellij-monorepo-bot
parent 1262c62b7f
commit 13b5f3d866
3 changed files with 23 additions and 0 deletions
@@ -1963,6 +1963,15 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
}
}
@Override
public void visitPatternVariable(@NotNull PsiPatternVariable variable) {
super.visitPatternVariable(variable);
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_20_PREVIEW) && variable.getPattern() instanceof PsiDeconstructionPattern) {
String message = JavaErrorBundle.message("identifier.is.not.allowed.here");
add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(variable).descriptionAndTooltip(message));
}
}
@Nullable
private static HighlightInfo.Builder checkGuardingExpressionHasBooleanType(@Nullable PsiExpression guardingExpression) {
if (guardingExpression != null && !TypeConversionUtil.isBooleanType(guardingExpression.getType())) {
@@ -275,6 +275,7 @@ switch.expr.rule.should.produce.result=Switch expression rule should produce res
guarded.patterns.unavailable=Guarded patterns from JEP 406 are not available since Java 19 preview
incorrect.number.of.nested.patterns=Incorrect number of nested patterns: expected {0} but found {1}
pattern.is.not.exhaustive=Pattern ''{0}'' is not exhaustive on ''{1}''
identifier.is.not.allowed.here=Identifier is not allowed here
illegal.forward.reference=Illegal forward reference
illegal.self.reference=Illegal self reference
@@ -70,4 +70,17 @@ class Main {
System.out.println(s);
}
}
void testNamedRecordPattern(Object obj, List<Rect> rectangles) {
if (obj instanceof Point(int x, int y) <error descr="Identifier is not allowed here">point</error>) {
}
switch (obj) {
case Point(int x, int y) <error descr="Identifier is not allowed here">point</error> -> System.out.println("point");
case Rect(Point point1, Point(int x2, int y2) <error descr="Identifier is not allowed here">point2</error>) <error descr="Identifier is not allowed here">rect</error> -> System.out.println("rectangle");
}
for (Rect(Point(int x1, int y1) <error descr="Identifier is not allowed here">point1</error>, Point(int x2, int y2) <error descr="Identifier is not allowed here">point2</error>) : rectangles) {
System.out.println("blah blah blah");
}
}
}