Repository navigation
fix: handle comment at the end of a method declaration - #4996
Conversation
Multi line comment is allowed at almost any part of the Java source code where whitespace is allowed. The reloadable Java parser visitor however swallows multi line comment at the end of a method declaration, which happens to be a common pattern in GWT in order to embed JavaScript in a Java class. Note that this effectively is a partial revert of openrewrite#4412 (commit ac32851).
0ecf34a to
f1f6a63
Compare
|
Turns out this was indeed needed for those erroneous nodes you had helpfully linked above, thanks! diff --git a/com/example/demo/FooBar.java b/com/example/demo/FooBar.java
index 5028cf3..7e634ec 100644
--- a/com/example/demo/FooBar.java
+++ b/com/example/demo/FooBar.java
@@ -1,7 +1,7 @@
package com.example.demo;
class FooBar {
public void test(int num string s, int b) {
- String a; this.ownerR
+ String a this.ownerR
System.out.println();
}
}
\ No newline at end of file/cc @knutwannheden |
|
I wonder if we shouldn't remove that test case for now, which attempts to parse erroneous code like this (see first method parameter): public void test(int num string s, int b) {
String a; this.ownerR
System.out.println();
}While it would be nice to not fail to parse code like this, it seems like it would be higher priority to parse correct code correctly. @vudayani, @BoykoAlex : Maybe you can comment on which erroneous input we need to be able to successfully parse into an LST? |
|
Had another look and adjusted the tests: turns out it's a parameterized test that tests a couple of different cases, but the failing case had two separate compilation issues: one in the arguments, and then another with a missing field reference and semicolon. I've separated those cases as I believe the goal here was to support completions at the point where the user has their cursor, thus most closely matching a single erroneous node at that position. With that I think we can merge this already, and revise if needed asynchronously without indeed breaking valid usage. Thanks all! |
Multi line comment is allowed at almost any part of the Java source code
where whitespace is allowed. The reloadable Java parser visitor however
swallows multi line comment at the end of a method declaration, which
happens to be a common pattern in GWT in order to embed JavaScript in a
Java class.
Note that this effectively is a partial revert of Handle erroneous nodes in open rewrite #4412
(commit ac32851).
Fixes ChangePackage doesn't handle classes with GWT JNSI methods #4995