Skip to content

Commit 3d2412b

Browse files
refactor: use unnamed variables
finally supported by palantir-java-format
1 parent 7987739 commit 3d2412b

File tree

6 files changed

+27
-34
lines changed

6 files changed

+27
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
<configuration>
175175
<java>
176176
<palantirJavaFormat>
177-
<version>2.73.0</version>
177+
<version>2.74.0</version>
178178
<style>PALANTIR</style>
179179
<formatJavadoc>false</formatJavadoc>
180180
</palantirJavaFormat>

src/main/java/io/github/treesitter/jtreesitter/Parser.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ public Parser setLogger(@Nullable Logger logger) {
9696
} else {
9797
var segment = TSLogger.allocate(arena);
9898
TSLogger.payload(segment, MemorySegment.NULL);
99-
// NOTE: can't use _ because of palantir/palantir-java-format#934
10099
var log = TSLogger.log.allocate(
101-
(p, type, message) -> {
100+
(_, type, message) -> {
102101
var logType = Logger.Type.values()[type];
103102
logger.accept(logType, message.getString(0));
104103
},
@@ -305,9 +304,8 @@ public Optional<Tree> parse(
305304
var input = TSInput.allocate(arena);
306305
TSInput.payload(input, MemorySegment.NULL);
307306
TSInput.encoding(input, encoding.ordinal());
308-
// NOTE: can't use _ because of palantir/palantir-java-format#934
309307
var read = TSInput.read.allocate(
310-
(payload, index, point, bytes) -> {
308+
(_, index, point, bytes) -> {
311309
var result = parseCallback.apply(index, Point.from(point));
312310
if (result == null) {
313311
bytes.set(C_INT, 0, 0);
@@ -437,8 +435,7 @@ public long get() {
437435
/** Set the value of the flag. */
438436
@SuppressWarnings("unused")
439437
public void set(long value) {
440-
// NOTE: can't use _ because of palantir/palantir-java-format#934
441-
segment.set(C_LONG_LONG, 0L, this.value.updateAndGet(o -> value));
438+
segment.set(C_LONG_LONG, 0L, this.value.updateAndGet(_ -> value));
442439
}
443440
}
444441
}

src/main/java/io/github/treesitter/jtreesitter/internal/ChainedLibraryLookup.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ private ChainedLibraryLookup() {}
1616
@Override
1717
public SymbolLookup get(Arena arena) {
1818
var serviceLoader = ServiceLoader.load(NativeLibraryLookup.class);
19-
// NOTE: can't use _ because of palantir/palantir-java-format#934
20-
SymbolLookup lookup = (name) -> Optional.empty();
19+
SymbolLookup lookup = (_) -> Optional.empty();
2120
for (var libraryLookup : serviceLoader) {
2221
lookup = lookup.or(libraryLookup.get(arena));
2322
}

src/test/java/io/github/treesitter/jtreesitter/ParserTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ void parseLogger() {
106106
@DisplayName("parse(callback)")
107107
void parseCallback() {
108108
var source = "class Foo {}";
109-
// NOTE: can't use _ because of palantir/palantir-java-format#934
110-
ParseCallback callback = (offset, p) -> source.substring(offset, Integer.min(offset, source.length()));
109+
ParseCallback callback = (offset, _) -> source.substring(offset, Integer.min(offset, source.length()));
111110
parser.setLanguage(language);
112111
try (var tree = parser.parse(callback, InputEncoding.UTF_8).orElseThrow()) {
113112
assertNull(tree.getText());
@@ -120,8 +119,7 @@ void parseCallback() {
120119
@SuppressWarnings("deprecation")
121120
void parseTimeout() {
122121
var source = "}".repeat(1024);
123-
// NOTE: can't use _ because of palantir/palantir-java-format#934
124-
ParseCallback callback = (offset, p) -> source.substring(offset, Integer.min(source.length(), offset + 1));
122+
ParseCallback callback = (offset, _) -> source.substring(offset, Integer.min(source.length(), offset + 1));
125123

126124
parser.setLanguage(language).setTimeoutMicros(2L);
127125
assertTrue(parser.parse(callback, InputEncoding.UTF_8).isEmpty());
@@ -132,8 +130,7 @@ void parseTimeout() {
132130
@SuppressWarnings("deprecation")
133131
void parseCancellation() {
134132
var source = "}".repeat(1024 * 1024);
135-
// NOTE: can't use _ because of palantir/palantir-java-format#934
136-
ParseCallback callback = (offset, p) -> source.substring(offset, Integer.min(source.length(), offset + 1));
133+
ParseCallback callback = (offset, _) -> source.substring(offset, Integer.min(source.length(), offset + 1));
137134

138135
var flag = new Parser.CancellationFlag();
139136
parser.setLanguage(language).setCancellationFlag(flag);
@@ -158,8 +155,7 @@ void parseCancellation() {
158155
@DisplayName("parse(options)")
159156
void parseOptions() {
160157
var source = "}".repeat(1024);
161-
// NOTE: can't use _ because of palantir/palantir-java-format#934
162-
ParseCallback callback = (offset, p) -> source.substring(offset, Integer.min(source.length(), offset + 1));
158+
ParseCallback callback = (offset, _) -> source.substring(offset, Integer.min(source.length(), offset + 1));
163159
var options = new Parser.Options((state) -> state.getCurrentByteOffset() >= 1000);
164160

165161
parser.setLanguage(language);
@@ -169,8 +165,7 @@ void parseOptions() {
169165
@Test
170166
void reset() {
171167
var source = "class foo bar() {}";
172-
// NOTE: can't use _ because of palantir/palantir-java-format#934
173-
ParseCallback callback = (offset, p) -> source.substring(offset, Integer.min(source.length(), offset + 1));
168+
ParseCallback callback = (offset, _) -> source.substring(offset, Integer.min(source.length(), offset + 1));
174169
var options = new Parser.Options(Parser.State::hasError);
175170

176171
parser.setLanguage(language);

src/test/java/io/github/treesitter/jtreesitter/QueryCursorTest.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ void findMatches() {
107107
try (var tree = parser.parse("int y = x + 1;").orElseThrow()) {
108108
var source =
109109
"""
110-
((variable_declarator
111-
(identifier) @y
112-
(binary_expression
113-
(identifier) @x))
114-
(#not-eq? @y @x))
115-
"""
110+
((variable_declarator
111+
(identifier) @y
112+
(binary_expression
113+
(identifier) @x))
114+
(#not-eq? @y @x))
115+
"""
116116
.stripIndent();
117117
assertCursor(source, cursor -> {
118118
var matches = cursor.findMatches(tree.getRootNode()).toList();
@@ -178,17 +178,20 @@ void findMatches() {
178178

179179
// Verify that `eq?` predicate works with quantified captures
180180
try (var tree = parser.parse("/* 1 */ /* 1 */ /* 1 */").orElseThrow()) {
181-
var source = """
182-
(program
183-
. (block_comment) @b (block_comment)+ @a
184-
(#eq? @a @b)
185-
)
186-
""";
181+
var source =
182+
"""
183+
(program
184+
.
185+
(block_comment) @b
186+
(block_comment)+ @a
187+
(#eq? @a @b))
188+
""";
187189
assertCursor(source, cursor -> {
188190
var matches = cursor.findMatches(tree.getRootNode()).toList();
189191
assertEquals(1, matches.size());
190192
assertEquals(
191-
"/* 1 */", matches.getFirst().captures().getFirst().node().getText());
193+
"/* 1 */",
194+
matches.getFirst().captures().getFirst().node().getText());
192195
});
193196
}
194197
}

src/test/java/io/github/treesitter/jtreesitter/QueryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ static void afterAll() {
3636

3737
@SuppressWarnings("unused")
3838
private static void assertError(Class<? extends QueryError> type, String source, String message) {
39-
// NOTE: can't use _ because of palantir/palantir-java-format#934
40-
try (var q = new Query(language, source)) {
39+
try (var _ = new Query(language, source)) {
4140
fail("Expected QueryError to be thrown, but nothing was thrown.");
4241
} catch (QueryError ex) {
4342
assertInstanceOf(type, ex);

0 commit comments

Comments
 (0)