This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 976f6c7 [NETBEANS-4682] : Fixed Record Formatting issue with use of
annotation
976f6c7 is described below
commit 976f6c7a97fc9267eb1400719b1a31121c854f4f
Author: singhs-akhilesh <[email protected]>
AuthorDate: Tue Sep 22 20:26:06 2020 +0530
[NETBEANS-4682] : Fixed Record Formatting issue with use of annotation
---
.../modules/java/source/save/Reformatter.java | 15 +++++++++++-
.../modules/java/source/save/FormatingTest.java | 27 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git
a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
index 1df27b2..cf1f827 100644
---
a/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
+++
b/java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
@@ -1162,8 +1162,21 @@ public class Reformatter implements ReformatTask {
space();
}
} else if (afterAnnotation) {
+ WrapStyle newWrapStyle = cs.wrapAnnotations();
+ if (parent instanceof ClassTree) {
+ for (Tree member : ((ClassTree)
parent).getMembers()) {
+ if
(member.getKind().toString().equals(TreeShims.RECORD)) {
+ ClassTree cls = (ClassTree) member;
+ for (Tree recMember : cls.getMembers()) {
+ if
(recMember.equals(getCurrentPath().getLeaf())) {
+ newWrapStyle =
WrapStyle.WRAP_NEVER;
+ }
+ }
+ }
+ }
+ }
if
(org.netbeans.api.java.source.TreeUtilities.CLASS_TREE_KINDS.contains(parent.getKind())
|| parent.getKind() == Tree.Kind.BLOCK) {
- switch (cs.wrapAnnotations()) {
+ switch (newWrapStyle) {
case WRAP_ALWAYS:
newline();
break;
diff --git
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
index 7939666..c2e7a68 100644
---
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
+++
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
@@ -5225,6 +5225,33 @@ public class FormatingTest extends NbTestCase {
+ "}\n";
reformat(doc, content, golden);
}
+
+ public void testRecord4() throws Exception {
+ try {
+ SourceVersion.valueOf("RELEASE_14"); //NOI18N
+ } catch (IllegalArgumentException ex) {
+ //OK, no RELEASE_14, skip test
+ return;
+ }
+ testFile = new File(getWorkDir(), "Test.java");
+ TestUtilities.copyStringToFile(testFile, "");
+ FileObject testSourceFO = FileUtil.toFileObject(testFile);
+ DataObject testSourceDO = DataObject.find(testSourceFO);
+ EditorCookie ec = (EditorCookie)
testSourceDO.getCookie(EditorCookie.class);
+ final Document doc = ec.openDocument();
+ doc.putProperty(Language.class, JavaTokenId.language());
+ String content
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + "public record g3(@Override int a, @Override int b){}}";
+ String golden
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + " public record g3(@Override int a, @Override int b)
{\n\n"
+ + " }\n"
+ + "}\n";
+ reformat(doc, content, golden);
+ }
private void reformat(Document doc, String content, String golden) throws
Exception {
reformat(doc, content, golden, 0, content.length());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists