Improving reindenter and code completion behavior for Java compact source files (JEP 512).#8676
Conversation
|
edit: this fixes the test: diff --git a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBParserFactoryTest.java b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBParserFactoryTest.java
index 543146d..6b47586 100644
--- a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBParserFactoryTest.java
+++ b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBParserFactoryTest.java
@@ -125,6 +125,7 @@
Context context = new Context();
NBParserFactory.preRegister(context);
+ NBTreeMaker.preRegister(context);
final JavacTaskImpl ct = (JavacTaskImpl) ((JavacTool)tool).getTask(null, std, null, Arrays.asList("-source", "21"), null, Arrays.asList(new MyFileObject(code)), context);
CompilationUnitTree cut = ct.parse().iterator().next();
Details |
I think this is a good candidate for NB 27 since compact java files are now final and many will likely give them now a try if they haven't yet. This would also qualify as regression since I don't think javac 24 did use the synthetic class wrapper - so we wouldn't break our own rules by including this fix. |
Right, sorry for that. Thanks! FWIW, I believe even JDK 24 and before where using synthetic class for the previous round of the current compact source files, although sometimes details differed. |
mbien
left a comment
There was a problem hiding this comment.
forgot to approve. Please squash and leave PR open as always since it targets delivery.
…urce files (JEP 512).
64884a6 to
0041c7c
Compare
I was writing some compact source file (JEP 512[1]) and the reindenter was really struggling with that. Looking into it, it turned out it is because of the positions - there's a synthetic class generated, which has
-1as the end position, and moreover, even the wholeCompilationUnitTreehas consequently-1as the end position(!!).I have filled this to re-evaluate the positions for javac for the synthetic class positions:
https://bugs.openjdk.org/browse/JDK-8364015
but here, the proposal is to start with some "workarounds":
0, or the end pos of the last import (a bit vaguely speaking). This allows the code completion to provide the "inside class" code completion results on more or less all relevant places in the file.CompilationUnitTreewith the synthetic class is the end of the last tokenTreeUtilities.pathForis adjusted to also consider the end of the last token as the end pos of the synthetic classReindentersimilarly now special-cases the end position of the synthetic classI am a bit on the fence whether (try to) put this into NB27 or not. Suggestions welcome.
[1] https://openjdk.org/jeps/512
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)