Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"dist"
],
"scripts": {
"build": "tsdown && cp src/tree-sitter-java_orchard.wasm dist/",
"build": "tsdown && cp node_modules/tree-sitter-java-orchard/tree-sitter-java_orchard.wasm dist/",
"ci": "yarn build && yarn lint && yarn format:validate && yarn test",
"clone-samples": "node scripts/clone-samples.js",
"format:fix": "prettier --write \"**/*.@(js|json|ts)\"",
"format:validate": "prettier --list-different \"**/*.@(js|json|ts)\"",
"postinstall": "cp node_modules/tree-sitter-java-orchard/tree-sitter-java_orchard.wasm src/ && node scripts/generate-node-types.ts && prettier --write src/node-types.ts",
"postinstall": "node scripts/generate-node-types.ts && prettier --write src/node-types.ts",
"lerna:publish": "lerna publish from-git --yes",
"lerna:version": "lerna version --exact --no-private",
"lint": "eslint src test",
Expand All @@ -52,7 +52,7 @@
]
},
"dependencies": {
"web-tree-sitter": "0.26.6"
"web-tree-sitter": "0.26.7"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
Expand All @@ -68,7 +68,7 @@
"mitata": "^1.0.34",
"mocha": "^11.7.5",
"prettier": "^3.8.1",
"tree-sitter-java-orchard": "0.5.4",
"tree-sitter-java-orchard": "0.5.6",
"tsdown": "^0.21.4",
"typescript": "^5.9.3",
"typescript-eslint": "^8.57.1"
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ export interface InstanceofExpressionNode extends NamedNodeBase {
leftNode: ExpressionNode;
nameNode?: IdentifierNode;
patternNode?: RecordPatternNode;
rightNode?: TypeNode;
rightNode?: UnannotatedTypeNode;
}

export interface IntegralTypeNode extends NamedNodeBase {
Expand Down
5 changes: 3 additions & 2 deletions src/printers/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ export default {
return group(
indent(
path.map(child => {
const doc = print(child, { annotationMode: "noBreak" });
if (!child.previous) {
return print(child);
return doc;
}

const separator = (
Expand All @@ -310,7 +311,7 @@ export default {
? line
: " ";

return [separator, print(child)];
return [separator, doc];
}, "children")
)
);
Expand Down
Binary file removed src/tree-sitter-java_orchard.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cpSync, existsSync, readdirSync, readFileSync, rmSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import prettier from "prettier";
import plugin from "../src/index.ts";
import plugin from "../dist/index.mjs";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
Integer[][] annotatedArray = (Integer[][]) new Object[4][2];
@RandomAnnotationWithObject({"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"})
V[][] annotatedArray = (V[][]) new Object[rowList.size()][columnList.size()];
record Config(String a, String b) {}
}
2 changes: 2 additions & 0 deletions test/unit-test/annotation_interface_declaration/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
"Ten",
})
V[][] annotatedArray = (V[][]) new Object[rowList.size()][columnList.size()];

record Config(String a, String b) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,16 @@ void instanceOf() {
Foo.get(longlinelonglinelonglinelonglinelongline) instanceof
NumberNumberNumberNumber n &&
n.foo();

e instanceof @Ann final E baz;
f instanceof final @Ann E qux;
}

void unaryExpression() {
int a = -x + y;
int b = ~x & y;
boolean c = !x && !y;
int d = -(x + y);
Object e = (int) -x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,16 @@ void instanceOf() {
var a =
Foo.get(longlinelonglinelonglinelonglinelongline) instanceof
NumberNumberNumberNumber n && n.foo();

e instanceof @Ann final E baz;
f instanceof final @Ann E qux;
}

void unaryExpression() {
int a = -x + y;
int b = ~x & y;
boolean c = !x && !y;
int d = -(x + y);
Object e = (int) -x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,16 @@ void instanceOf() {
Foo.get(longlinelonglinelonglinelonglinelongline) instanceof
NumberNumberNumberNumber n &&
n.foo();

e instanceof @Ann final E baz;
f instanceof final @Ann E qux;
}

void unaryExpression() {
int a = -x + y;
int b = ~x & y;
boolean c = !x && !y;
int d = -(x + y);
Object e = (int) -x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,16 @@ void instanceOf() {
var a =
Foo.get(longlinelonglinelonglinelonglinelongline)
instanceof NumberNumberNumberNumber n && n.foo();

e instanceof @Ann final E baz;
f instanceof final @Ann E qux;
}

void unaryExpression() {
int a = -x + y;
int b = ~x & y;
boolean c = !x && !y;
int d = -(x + y);
Object e = (int) -x;
}
}
8 changes: 8 additions & 0 deletions test/unit-test/cast/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ void many_nested_casts() {
((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map)((Map) ((Map) map).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1)).get(1);
}

void intersectionCastExpression() {
Object o1 = (A & B) (C) o;
Object o2 = (A & B) ~0;
Object o3 = (A & B) switch (x) { default -> null; };
Object o4 = (A & B) !x;
Object o5 = (A & B) + x;
Object o6 = (A & B) - x;
}
}
11 changes: 11 additions & 0 deletions test/unit-test/cast/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ void many_nested_casts() {
).get(1)
).get(1);
}

void intersectionCastExpression() {
Object o1 = (A & B) (C) o;
Object o2 = (A & B) ~0;
Object o3 = (A & B) switch (x) {
default -> null;
};
Object o4 = (A & B) !x;
Object o5 = (A & B) + x;
Object o6 = (A & B) - x;
}
}
10 changes: 10 additions & 0 deletions test/unit-test/constructors/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public Constructors() {

public <T> GenericConstructor(T genericParameter) {}
public <T>GenericConstructor(T genericParameter) {}

FlexibleConstructorBody(int x) {
this.x = x;
super(x);
}

FlexibleConstructorBody() {
var v = 42;
this(v);
}
}
10 changes: 10 additions & 0 deletions test/unit-test/constructors/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ public Constructors() {
public <T> GenericConstructor(T genericParameter) {}

public <T> GenericConstructor(T genericParameter) {}

FlexibleConstructorBody(int x) {
this.x = x;
super(x);
}

FlexibleConstructorBody() {
var v = 42;
this(v);
}
}
9 changes: 9 additions & 0 deletions test/unit-test/expressions/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,13 @@ void parenthesesWithoutBreak() {
Aaaaaaaaaa aaaaaaaaaa = (bbbbbbbbbb -> cccccccccc ? dddddddddd : eeeeeeeeee)::ffffffffff;
Aaaaaaaaaa aaaaaaaaaa = (bbbbbbbbbb -> cccccccccc ? dddddddddd : eeeeeeeeee)[ffffffffff];
}

void unaryExpression() {
int a = +x;
int b = -x;
int c = ~x;
boolean d = !x;
int e = ~~x;
int f = -+x;
}
}
9 changes: 9 additions & 0 deletions test/unit-test/expressions/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,13 @@ void parenthesesWithoutBreak() {
Aaaaaaaaaa aaaaaaaaaa = (bbbbbbbbbb ->
cccccccccc ? dddddddddd : eeeeeeeeee)[ffffffffff];
}

void unaryExpression() {
int a = +x;
int b = -x;
int c = ~x;
boolean d = !x;
int e = ~~x;
int f = -+x;
}
}
6 changes: 6 additions & 0 deletions test/unit-test/pattern-matching/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ case Buyer b when (
}

int recordPatterns(MyRecord r) {
if (o instanceof Foo(@Bar String s)) {}
switch (obj) {
case final String s: break;
}
return switch (r) {
case null, default -> 0;
case MyRecord(A a) -> 0;
Expand All @@ -52,6 +56,8 @@ int recordPatterns(MyRecord r) {
case MyRecord(LongTypeName longVariableName, LongTypeName longVariableName) -> 0;
case MyRecord(LongTypeName longVariableName, LongTypeName longVariableName) when this.longVariableName > longVariableName && this.longVariableName > longVariableName -> 0;
case MyRecord(LongTypeName longVariableName, LongTypeName longVariableName) when this.longVariableName > longVariableName && this.longVariableName > longVariableName -> longMethodName(longVariableName, longVariableName, longVariableName, longVariableName);
case Outer.Inner(String s) -> {}
case final String s -> s;
};
}
}
9 changes: 9 additions & 0 deletions test/unit-test/pattern-matching/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ case Buyer b when (
}

int recordPatterns(MyRecord r) {
if (o instanceof Foo(@Bar String s)) {
}
switch (obj) {
case final String s:
break;
}
return switch (r) {
case null, default -> 0;
case MyRecord(A a) -> 0;
Expand Down Expand Up @@ -104,6 +110,9 @@ case MyRecord(
longVariableName,
longVariableName
);
case Outer.Inner(String s) -> {
}
case final String s -> s;
};
}
}
13 changes: 13 additions & 0 deletions test/unit-test/text-blocks/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@ public void print(%s object) {
);
}

String escapes = """
1+1 equals \
2 maybe
""";

String escapes = """
\"""var msg = hello world!\""";
""";

String escapes = """
\n\t\r\f\b\s\\
\077
\u0041""";
}
14 changes: 14 additions & 0 deletions test/unit-test/text-blocks/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,18 @@ public void print(%s object) {
abc"""
);
}

String escapes = """
1+1 equals \
2 maybe
""";

String escapes = """
\"""var msg = hello world!\""";
""";

String escapes = """
\n\t\r\f\b\s\\
\077
\u0041""";
}
21 changes: 20 additions & 1 deletion test/unit-test/variables/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,27 @@ public class Variables {
private Range<Date> creator3 = this.dateRangeField.new <Integer>Range<>(from, to);
private Range<Date> creator3 = new <Integer>Range<>(from, to);

private int intLiteral = 1__0;
private int intLiteral = 0_00_00;
private int intLiteral = 0_7;
private int intLiteral = 0__7;
private int hexLiteral = 0x0000;
private int octLiteral = 001;
private int hexLiteral = 0xa__b;
private int hexLiteral = 0x1p0993;
private int hexLiteral = 0x1p-0993;
private int octLiteral = 001;
private int binaryLiteral = 0b1__0;
private double floatingPointLiteral = 0d;
private double floatingPointLiteral = 0D;
private double floatingPointLiteral = 00d;
private double floatingPointLiteral = 1.0d;
private double floatingPointLiteral = 1.0D;
private float floatingPointLiteral = 1.0f;
private float floatingPointLiteral = 1.0F;
private float floatingPointLiteral = 1e4f;
private double floatingPointLiteral = 1e4d;
private float floatingPointLiteral = 007f;
private double floatingPointLiteral = 00e1;

private Interface anonymousClassVariable = new Interface(){
@Override
Expand Down
19 changes: 19 additions & 0 deletions test/unit-test/variables/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,27 @@ public class Variables {
);
private Range<Date> creator3 = new <Integer>Range<>(from, to);

private int intLiteral = 1__0;
private int intLiteral = 0_00_00;
private int intLiteral = 0_7;
private int intLiteral = 0__7;
private int hexLiteral = 0x0000;
private int hexLiteral = 0xa__b;
private int hexLiteral = 0x1p0993;
private int hexLiteral = 0x1p-0993;
private int octLiteral = 001;
private int binaryLiteral = 0b1__0;
private double floatingPointLiteral = 0d;
private double floatingPointLiteral = 0D;
private double floatingPointLiteral = 00d;
private double floatingPointLiteral = 1.0d;
private double floatingPointLiteral = 1.0D;
private float floatingPointLiteral = 1.0f;
private float floatingPointLiteral = 1.0F;
private float floatingPointLiteral = 1e4f;
private double floatingPointLiteral = 1e4d;
private float floatingPointLiteral = 007f;
private double floatingPointLiteral = 00e1;

private Interface anonymousClassVariable = new Interface() {
@Override
Expand Down
Loading