This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 3081ac9a1e4 fix reformatting of annotated records.
     new cfa8c6372e7 Merge pull request #5374 from 
mbien/annotated-record-reformatter-fix
3081ac9a1e4 is described below

commit 3081ac9a1e45568f3641e95c61b95cb734bca455
Author: Michael Bien <mbie...@gmail.com>
AuthorDate: Fri Jan 27 04:55:00 2023 +0100

    fix reformatting of annotated records.
---
 .../modules/java/source/save/Reformatter.java      |  6 ++--
 .../modules/java/source/save/FormatingTest.java    | 39 +++++++++++++++++++++-
 2 files changed, 42 insertions(+), 3 deletions(-)

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 063fc0a194e..18a295b9949 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
@@ -1279,11 +1279,10 @@ public class Reformatter implements ReformatTask {
             boolean old = continuationIndent;
             int oldIndent = indent;
             try {
-                continuationIndent = true;
                 ModifiersTree mods = node.getModifiers();
                 if (mods != null) {
                     if (scan(mods, p)) {
-
+                        continuationIndent = true;
                         if (cs.placeNewLineAfterModifiers()) {
                             newline();
                         } else {
@@ -1295,6 +1294,7 @@ public class Reformatter implements ReformatTask {
                     afterAnnotation = false;
                 }
                 accept(IDENTIFIER);
+                continuationIndent = true;
                 space();
 
                 if (!ERROR.contentEquals(node.getSimpleName())) {
@@ -1826,6 +1826,7 @@ public class Reformatter implements ReformatTask {
                 case CLASS:
                 case ENUM:
                 case INTERFACE:
+                case RECORD:
                     bracePlacement = cs.getOtherBracePlacement();
                     if (node.isStatic())
                         spaceBeforeLeftBrace = 
cs.spaceBeforeStaticInitLeftBrace();
@@ -5512,6 +5513,7 @@ public class Reformatter implements ReformatTask {
                 case CLASS:
                 case ENUM:
                 case INTERFACE:
+                case RECORD:
                     for (Tree tree : ((ClassTree)path.getLeaf()).getMembers()) 
{
                         if (tree == lastTree) {
                             indent += tabSize;
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 c4afa398dd6..eb663a9d8fa 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
@@ -3498,7 +3498,44 @@ public class FormatingTest extends NbTestCase {
                 + "\n";
         reformat(doc, content, golden);
     }
-    
+
+    public void testAnnotatedRecord() throws Exception {
+        try {
+            SourceVersion.valueOf("RELEASE_19"); //NOI18N
+        } catch (IllegalArgumentException ex) {
+            //OK, no RELEASE_19, 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.getLookup().lookup(EditorCookie.class);
+        final Document doc = ec.openDocument();
+        doc.putProperty(Language.class, JavaTokenId.language());
+        String content =
+                  "package test;\n"
+                + "\n"
+                + "/**\n"
+                + " * @author duke\n"
+                + " */\n"
+                + "@Deprecated public record DeprecatedRecord(int a) {}"
+                + "\n";
+
+        String golden =
+                  "package test;\n"
+                + "\n"
+                + "/**\n"
+                + " * @author duke\n"
+                + " */\n"
+                + "@Deprecated\n"
+                + "public record DeprecatedRecord(int a) {\n"
+                + "\n"
+                + "}"
+                + "\n";
+        reformat(doc, content, golden);
+    }
+
     public void testDoWhile() throws Exception {
         testFile = new File(getWorkDir(), "Test.java");
         TestUtilities.copyStringToFile(testFile,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to