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

neilcsmith 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 8f536817b5 Don't add space with implicit final modifier in try with 
resources formatting.
     new c564ee6df2 Merge pull request #4648 from neilcsmith-net/gh3720
8f536817b5 is described below

commit 8f536817b5ebc19c4844f8819344b498a6f334c6
Author: Neil C Smith <neilcsm...@apache.org>
AuthorDate: Sat Sep 17 18:01:45 2022 +0100

    Don't add space with implicit final modifier in try with resources 
formatting.
---
 .../modules/java/source/save/Reformatter.java      |  2 +-
 .../modules/java/source/save/FormatingTest.java    | 55 ++++++++++++++++++++++
 2 files changed, 56 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 35b1f39032..941da1c039 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
@@ -1151,7 +1151,7 @@ public class Reformatter implements ReformatTask {
                                 newline();
                             else
                                 space();
-                        } else {
+                        } else if (sp.getStartPosition(root, mods) != 
sp.getStartPosition(root, node.getType())) {
                             space();
                         }
                     } else if (afterAnnotation) {
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 a55ea973d0..a7b245a078 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
@@ -6099,6 +6099,61 @@ public class FormatingTest extends NbTestCase {
         reformat(doc, content, golden);
     }
 
+    public void testTryWithResources() throws Exception {
+        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 static void main(String[] args) {\n"
+                + "        try (PrintStream out = System.out) {\n"
+                + "            System.out.println(\"TEST\");\n"
+                + "        } catch (Exception e) {\n"
+                + "            System.out.println(\"CATCH\");\n"
+                + "        } finally {\n"
+                + "            System.out.println(\"FINALLY\");\n"
+                + "        }\n"
+                + "    }\n"
+                + "}\n";
+        String golden
+                = "package hierbas.del.litoral;\n\n"
+                + "public class Test {\n\n"
+                + "    public static void main(String[] args) {\n"
+                + "        try (PrintStream out = System.out) {\n"
+                + "            System.out.println(\"TEST\");\n"
+                + "        } catch (Exception e) {\n"
+                + "            System.out.println(\"CATCH\");\n"
+                + "        } finally {\n"
+                + "            System.out.println(\"FINALLY\");\n"
+                + "        }\n"
+                + "    }\n"
+                + "}\n";
+        reformat(doc, content, golden);
+
+        content = "package hierbas.del.litoral;\n\n"
+                + "public class Test {\n\n"
+                + "    public static void main(String[] args) {\n"
+                + "        try ( final   PrintStream  out = System.out) {\n"
+                + "            System.out.println(\"TEST\");\n"
+                + "        }\n"
+                + "    }\n"
+                + "}\n";
+        golden = "package hierbas.del.litoral;\n\n"
+                + "public class Test {\n\n"
+                + "    public static void main(String[] args) {\n"
+                + "        try (final PrintStream out = System.out) {\n"
+                + "            System.out.println(\"TEST\");\n"
+                + "        }\n"
+                + "    }\n"
+                + "}\n";
+        reformat(doc, content, golden);
+    }
 
     public void testSynchronizedBlockAfterFor() throws Exception {
         testFile = new File(getWorkDir(), "Test.java");


---------------------------------------------------------------------
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