Skip to content

Commit

Permalink
[NETBEANS-4682] : Fixed Record Formatting issue with use of annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
singh-akhilesh authored and lkishalmi committed Sep 23, 2020
1 parent 8c073c3 commit 976f6c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,21 @@ public Boolean visitVariable(VariableTree node, Void p) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5225,6 +5225,33 @@ public void testRecord3() throws Exception {
+ "}\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());
Expand Down

0 comments on commit 976f6c7

Please sign in to comment.