Skip to content

Commit

Permalink
[21] Removing Parenthesized Patterns and adjusting tests that allow them
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthana committed Aug 28, 2023
1 parent 582b1b5 commit 919e80b
Show file tree
Hide file tree
Showing 30 changed files with 481 additions and 524 deletions.
5 changes: 0 additions & 5 deletions org.eclipse.jdt.core.compiler.batch/grammar/java.g
Original file line number Diff line number Diff line change
Expand Up @@ -1253,15 +1253,10 @@ InstanceofPattern ::= 'instanceof' Pattern


Pattern -> TypePattern
Pattern -> ParenthesizedPattern
Pattern -> RecordPattern
/.$putCase consumePattern(); $break ./
/:$readableName Pattern:/

ParenthesizedPattern ::= PushLPAREN Pattern PushRPAREN
/.$putCase consumeParenthesizedPattern(); $break ./
/:$readableName ParenthesizedPattern:/

TypePattern ::= Modifiersopt Type 'Identifier'
/.$putCase consumeTypePattern(); $break ./
/:$readableName TypePattern:/
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ public interface ParserBasicInformation {

ERROR_SYMBOL = 138,
MAX_NAME_LENGTH = 53,
NUM_STATES = 1233,
NUM_STATES = 1231,

NT_OFFSET = 138,
SCOPE_UBOUND = 322,
SCOPE_SIZE = 323,
LA_STATE_OFFSET = 18574,
SCOPE_UBOUND = 321,
SCOPE_SIZE = 322,
LA_STATE_OFFSET = 18334,
MAX_LA = 1,
NUM_RULES = 942,
NUM_RULES = 940,
NUM_TERMINALS = 138,
NUM_NON_TERMINALS = 433,
NUM_SYMBOLS = 571,
START_STATE = 1292,
NUM_NON_TERMINALS = 432,
NUM_SYMBOLS = 570,
START_STATE = 1003,
EOFT_SYMBOL = 64,
EOLT_SYMBOL = 64,
ACCEPT_ACTION = 18573,
ERROR_ACTION = 18574;
ACCEPT_ACTION = 18333,
ERROR_ACTION = 18334;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public interface TerminalTokens {
TokenNameshort = 114,
TokenNamestatic = 37,
TokenNamestrictfp = 49,
TokenNamesuper = 35,
TokenNamesuper = 34,
TokenNameswitch = 63,
TokenNamesynchronized = 39,
TokenNamethis = 36,
TokenNamethis = 35,
TokenNamethrow = 78,
TokenNamethrows = 117,
TokenNametransient = 50,
Expand Down Expand Up @@ -157,7 +157,7 @@ public interface TerminalTokens {
TokenNameCOMMA = 32,
TokenNameDOT = 1,
TokenNameEQUAL = 77,
TokenNameAT = 34,
TokenNameAT = 36,
TokenNameELLIPSIS = 120,
TokenNameARROW = 104,
TokenNameCOLON_COLON = 7,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ PackageDeclaration=PackageDeclaration
PackageDeclarationName=PackageDeclarationName
ParenthesizedCastNameAndBounds=ParenthesizedCastNameAndBounds
ParenthesizedLambdaParameterList=ParenthesizedLambdaParameterList
ParenthesizedPattern=ParenthesizedPattern
Pattern=Pattern
PatternList=PatternList
PatternListopt=PatternListopt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public void test001() {
"X.java",
"public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr) )) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr) ) {\n"
+ " System.out.println(\"Upper-left corner:\");\n"
+ " }\n"
+ " }\n"
Expand Down Expand Up @@ -197,8 +197,8 @@ public void test003() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr)) {\n"
+ " System.out.println(\"Upper-left corner: \" + r1);\n"
+ " }\n"
+ " }\n"
Expand All @@ -225,8 +225,8 @@ public void test004() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int x, int y), Color c),\n"
+ " ColoredPoint lr)) {\n"
+ " }\n"
+ " }\n"
+ " public static void main(String[] obj) {\n"
Expand All @@ -253,8 +253,8 @@ public void test005() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int i, int j), Color c),\n"
+ " ColoredPoint lr))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int i, int j), Color c),\n"
+ " ColoredPoint lr)) {\n"
+ " System.out.println(\"Upper-left corner: \");\n"
+ " }\n"
+ " }\n"
Expand All @@ -266,8 +266,8 @@ public void test005() {
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" if (r instanceof (Rectangle(ColoredPoint(Point(int i, int j), Color c),\n" +
" ^^^^^\n" +
" if (r instanceof Rectangle(ColoredPoint(Point(int i, int j), Color c),\n" +
" ^^^^^\n" +
"Only record types are permitted in a record pattern\n" +
"----------\n");
}
Expand All @@ -278,8 +278,8 @@ public void test006() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int i), Color c),\n"
+ " ColoredPoint lr))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int i), Color c),\n"
+ " ColoredPoint lr)) {\n"
+ " System.out.println(\"Upper-left corner: \");\n"
+ " }\n"
+ " }\n"
Expand All @@ -291,8 +291,8 @@ public void test006() {
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" if (r instanceof (Rectangle(ColoredPoint(Point(int i), Color c),\n" +
" ^^^^^^^^^^^^\n" +
" if (r instanceof Rectangle(ColoredPoint(Point(int i), Color c),\n" +
" ^^^^^^^^^^^^\n" +
"Record pattern should match the signature of the record declaration\n" +
"----------\n");
}
Expand All @@ -302,8 +302,8 @@ public void test007() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n"
+ " ColoredPoint lr))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n"
+ " ColoredPoint lr)) {\n"
+ " System.out.println(\"Upper-left corner: \" );\n"
+ " }\n"
+ " }\n"
Expand All @@ -315,13 +315,13 @@ public void test007() {
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" if (r instanceof (Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n" +
" ^^^^^^^^^\n" +
" if (r instanceof Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n" +
" ^^^^^^^^^\n" +
"Pattern of type int is not compatible with type java.lang.String\n" +
"----------\n" +
"2. ERROR in X.java (at line 4)\n" +
" if (r instanceof (Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n" +
" ^^^^^^^^^\n" +
" if (r instanceof Rectangle(ColoredPoint(Point(String o1, String o2), Color c),\n" +
" ^^^^^^^^^\n" +
"Pattern of type int is not compatible with type java.lang.String\n" +
"----------\n");
}
Expand All @@ -332,7 +332,7 @@ public void test008() {
"@SuppressWarnings(\"preview\")\n"
+ "public class X {\n"
+ " static void print(Rectangle r) {\n"
+ " if (r instanceof (Rectangle(ColoredPoint(Point(int i, int j), Color c), ColoredPoint lr, Object obj))) {\n"
+ " if (r instanceof Rectangle(ColoredPoint(Point(int i, int j), Color c), ColoredPoint lr, Object obj)) {\n"
+ " System.out.println(\"Upper-left corner: \" );\n"
+ " }\n"
+ " }\n"
Expand All @@ -344,8 +344,8 @@ public void test008() {
},
"----------\n" +
"1. ERROR in X.java (at line 4)\n" +
" if (r instanceof (Rectangle(ColoredPoint(Point(int i, int j), Color c), ColoredPoint lr, Object obj))) {\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
" if (r instanceof Rectangle(ColoredPoint(Point(int i, int j), Color c), ColoredPoint lr, Object obj)) {\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Record pattern should match the signature of the record declaration\n" +
"----------\n");
}
Expand Down Expand Up @@ -1202,8 +1202,8 @@ public void test33() {
+ " @SuppressWarnings(\"preview\")\n"
+ " public void foo(Object o) {\n"
+ " int res = switch (o) {\n"
+ " case ((R r)) -> 1;\n"
+ " case ((R(int a))) -> 0;\n"
+ " case R r -> 1;\n"
+ " case R(int a) -> 0;\n"
+ " default -> -1;\n"
+ " };\n"
+ " }\n"
Expand All @@ -1212,8 +1212,8 @@ public void test33() {
},
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
" case ((R(int a))) -> 0;\n" +
" ^^^^^^^^\n" +
" case R(int a) -> 0;\n" +
" ^^^^^^^^\n" +
"This case label is dominated by one of the preceding case labels\n" +
"----------\n");
}
Expand All @@ -1225,8 +1225,8 @@ public void test34() {
+ " @SuppressWarnings(\"preview\")\n"
+ " public void foo(Object o) {\n"
+ " int res = switch (o) {\n"
+ " case ((R(int a))) -> 1;\n"
+ " case ((R(int a))) -> 0;\n"
+ " case R(int a) -> 1;\n"
+ " case R(int a) -> 0;\n"
+ " default -> -1;\n"
+ " };\n"
+ " }\n"
Expand All @@ -1235,8 +1235,8 @@ public void test34() {
},
"----------\n" +
"1. ERROR in X.java (at line 6)\n" +
" case ((R(int a))) -> 0;\n" +
" ^^^^^^^^\n" +
" case R(int a) -> 0;\n" +
" ^^^^^^^^\n" +
"This case label is dominated by one of the preceding case labels\n" +
"----------\n");
}
Expand Down Expand Up @@ -1550,7 +1550,7 @@ public void test45() {
+ "public class X {\n"
+ " static void print(Object r) {\n"
+ " switch (r) {\n"
+ " case Rectangle(var a, var b) when (r instanceof (Rectangle(ColoredPoint upperLeft2, ColoredPoint lowerRight))):\n"
+ " case Rectangle(var a, var b) when (r instanceof Rectangle(ColoredPoint upperLeft2, ColoredPoint lowerRight)):\n"
+ " System.out.println(r);// error should not be reported here\n"
+ " break;\n"
+ " }\n"
Expand Down
Loading

0 comments on commit 919e80b

Please sign in to comment.