Skip to content

Commit 79a6f8f

Browse files
Revert "fix: fix parsing of unannPrimitiveType in primary"
f9b4249 change signatures
1 parent 7ab1fa5 commit 79a6f8f

9 files changed

Lines changed: 88 additions & 270 deletions

File tree

packages/java-parser/api.d.ts

Lines changed: 65 additions & 230 deletions
Large diffs are not rendered by default.

packages/java-parser/src/productions/classes.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,19 @@ function defineRules($, t) {
222222
$.OR([
223223
// Spec Deviation: The array type "dims" suffix was extracted to this rule
224224
// to avoid backtracking for performance reasons.
225-
{ ALT: () => $.SUBRULE($.unannPrimitiveTypeWithOptionalDimsSuffix) },
225+
{
226+
ALT: () => {
227+
$.SUBRULE($.unannPrimitiveType);
228+
$.OPTION({
229+
GATE: () => this.BACKTRACK_LOOKAHEAD($.isDims),
230+
DEF: () => $.SUBRULE2($.dims)
231+
});
232+
}
233+
},
226234
{ ALT: () => $.SUBRULE($.unannReferenceType) }
227235
]);
228236
});
229237

230-
$.RULE("unannPrimitiveTypeWithOptionalDimsSuffix", () => {
231-
$.SUBRULE($.unannPrimitiveType);
232-
$.OPTION({
233-
GATE: () => this.BACKTRACK_LOOKAHEAD($.isDims),
234-
DEF: () => $.SUBRULE2($.dims)
235-
});
236-
});
237-
238238
// https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-UnannPrimitiveType
239239
$.RULE("unannPrimitiveType", () => {
240240
$.OR([

packages/java-parser/src/productions/expressions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ function defineRules($, t) {
219219
{ ALT: () => $.SUBRULE($.literal) },
220220
{ ALT: () => $.CONSUME(t.This) },
221221
{ ALT: () => $.CONSUME(t.Void) },
222-
{ ALT: () => $.SUBRULE($.unannPrimitiveTypeWithOptionalDimsSuffix) },
222+
// should be extracted to primitive type with optional dims suffix?
223+
{ ALT: () => $.SUBRULE($.numericType) },
224+
{ ALT: () => $.CONSUME(t.Boolean) },
223225
{ ALT: () => $.SUBRULE($.fqnOrRefType) },
224226
{
225227
GATE: () => isCastExpression,

packages/java-parser/test/bugs-spec.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,4 @@ describe("The Java Parser fixed bugs", () => {
8787
const input = "(left) < right";
8888
expect(() => javaParser.parse(input, "expression")).to.not.throw();
8989
});
90-
91-
it("issue #412 - should parse a double[][] as primaryPrefix", () => {
92-
const input = "double[][]";
93-
expect(() => javaParser.parse(input, "primaryPrefix")).to.not.throw();
94-
});
9590
});

packages/prettier-plugin-java/src/options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ module.exports = {
7474
{ value: "variableInitializer" },
7575
{ value: "unannType" },
7676
{ value: "unannPrimitiveType" },
77-
{ value: "unannPrimitiveTypeWithOptionalDimsSuffix" },
7877
{ value: "unannReferenceType" },
7978
{ value: "unannClassOrInterfaceType" },
8079
{ value: "unannClassType" },

packages/prettier-plugin-java/src/printers/classes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ class ClassesPrettierVisitor {
300300
}
301301

302302
unannType(ctx) {
303-
return this.visitSingle(ctx);
304-
}
303+
if (ctx.unannReferenceType !== undefined) {
304+
return this.visit(ctx.unannReferenceType);
305+
}
305306

306-
unannPrimitiveTypeWithOptionalDimsSuffix(ctx) {
307307
const unannPrimitiveType = this.visit(ctx.unannPrimitiveType);
308308
const dims = this.visit(ctx.dims);
309309

packages/prettier-plugin-java/src/printers/expressions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class ExpressionsPrettierVisitor {
362362
}
363363

364364
primaryPrefix(ctx, params) {
365-
if (ctx.This || ctx.Void) {
365+
if (ctx.This || ctx.Void || ctx.Boolean) {
366366
return printTokenWithComments(this.getSingle(ctx));
367367
}
368368

packages/prettier-plugin-java/test/unit-test/expressions/_input.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void printIf() {
8989
}
9090

9191
if(myValue != 42 && 42/42 || myValue & 42 && myValue > 42 || myValue < 42 && myValue == 42) {
92-
92+
9393
}
9494

9595
if(myValue != 42 && myValue == 42) {
@@ -103,11 +103,11 @@ public void printSwitch() {
103103
}
104104

105105
switch(myValue != 42 && 42/42 || myValue & 42 && myValue > 42 || myValue < 42 && myValue == 42) {
106-
106+
107107
}
108108

109109
switch(myValue != 42) {
110-
110+
111111
}
112112

113113
switch(myValue != 42 && myValue == 42) {
@@ -117,17 +117,17 @@ public void printSwitch() {
117117

118118
public void printWhile() {
119119
while/*infinite*/ (true) /*stop the program*/throw new RuntimeException();
120-
120+
121121
while(myValue == 42 || myValue == 42 && myValue == 42 && myValue == 42 || myValue == 42 && myValue == 42) {
122122

123123
}
124124

125125
while(myValue != 42 && 42/42 || myValue & 42 && myValue > 42 || myValue < 42 && myValue == 42) {
126-
126+
127127
}
128128

129129
while(myValue != 42) {
130-
130+
131131
}
132132

133133
while(myValue != 42 && myValue == 42) {
@@ -178,12 +178,9 @@ public void longFullyQualifiedName() {
178178
com
179179
.me.very.very.very.very.very.very.very.very.very.very.very.very.very.longg.fully.qualified.name.FullyQualifiedName.builder()
180180
.build();
181-
181+
182182
com.FullyQualifiedName.builder();
183183
}
184184

185-
public void unannTypePrimitiveWithMethodReferenceSuffix(String[] args) {
186-
List.of(new double[][] { 1,2,3,4.1,5.6846465}, new double[][] { 1,2,3,4.1,5.6846465}, new double[][] { 1,2,3,4.1,5.6846465}).toArray(double[][]::new);
187-
}
188185
}
189186

packages/prettier-plugin-java/test/unit-test/expressions/_output.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,4 @@ public void longFullyQualifiedName() {
235235

236236
com.FullyQualifiedName.builder();
237237
}
238-
239-
public void unannTypePrimitiveWithMethodReferenceSuffix(String[] args) {
240-
List
241-
.of(
242-
new double[][] { 1, 2, 3, 4.1, 5.6846465 },
243-
new double[][] { 1, 2, 3, 4.1, 5.6846465 },
244-
new double[][] { 1, 2, 3, 4.1, 5.6846465 }
245-
)
246-
.toArray(double[][]::new);
247-
}
248238
}

0 commit comments

Comments
 (0)