You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/06/19 11:32:08 UTC

[GitHub] geertjanw closed pull request #591: [NETBEANS-892] Fix lambda expr and multi catch rewrite issues

geertjanw closed pull request #591: [NETBEANS-892] Fix lambda expr and multi catch rewrite issues
URL: https://github.com/apache/incubator-netbeans/pull/591
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java b/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
index b5cb6bfea..a37dfc351 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
@@ -1452,11 +1452,13 @@ private int diffVarDef(JCVariableDecl oldT, JCVariableDecl newT, int[] bounds) {
                 localPointer = oldT.pos;
                 printer.suppressVariableType = suppressParameterTypes;
                 int l = printer.out.length();
-                printer.print(newT.vartype);
-                printer.suppressVariableType = false;
-                if (l < printer.out.length()) {
-                    printer.print(" ");
+                if (!suppressParameterTypes) {
+                    printer.print(newT.vartype);
+                    if (l < printer.out.length()) {
+                        printer.print(" ");
+                    }
                 }
+                printer.suppressVariableType = false;
             }
         } else {
             if (suppressParameterTypes) {
@@ -3760,7 +3762,8 @@ private int diffVarGroup(
 
     protected int diffUnionType(JCTypeUnion oldT, JCTypeUnion newT, int[] bounds) {
         int localPointer = bounds[0];
-        return diffParameterList(oldT.alternatives, newT.alternatives, null, localPointer, Measure.MEMBER, diffContext.style.spaceAroundBinaryOps(), diffContext.style.spaceAroundBinaryOps(), false, "|");
+        int pos = diffParameterList(oldT.alternatives, newT.alternatives, null, localPointer, Measure.MEMBER, diffContext.style.spaceAroundBinaryOps(), diffContext.style.spaceAroundBinaryOps(), false, "|");
+        return Math.min(pos, bounds[1]);
     }
 
     private boolean commaNeeded(ResultItem[] arr, ResultItem item) {
diff --git a/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/MultiCatchTest.java b/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/MultiCatchTest.java
index 36ebee78b..ddf9a891f 100644
--- a/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/MultiCatchTest.java
+++ b/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/MultiCatchTest.java
@@ -300,6 +300,58 @@ public void run(final WorkingCopy workingCopy) throws IOException {
         System.err.println(res);
         assertEquals(golden, res);
     }
+
+    public void testRemoveAddInMultiCatch() throws Exception {
+        testFile = new File(getWorkDir(), "Test.java");
+        TestUtilities.copyStringToFile(testFile,
+            "package hierbas.del.litoral;\n" +
+            "import java.io.*;\n" +
+            "import java.net.*;\n" +
+            "public class Test {\n" +
+            "    public void taragui() {\n" +
+            "        try {\n" +
+            "        } catch (MalformedURLException | FileNotFoundException ex) {\n" +
+            "        }\n" +
+            "    }\n" +
+            "}\n"
+            );
+        String golden =
+            "package hierbas.del.litoral;\n" +
+            "import java.io.*;\n" +
+            "import java.net.*;\n" +
+            "public class Test {\n" +
+            "    public void taragui() {\n" +
+            "        try {\n" +
+            "        } catch (IOException | RuntimeException ex) {\n" +
+            "        }\n" +
+            "    }\n" +
+            "}\n";
+        JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
+        Task task = new Task<WorkingCopy>() {
+
+            public void run(final WorkingCopy workingCopy) throws IOException {
+                workingCopy.toPhase(Phase.RESOLVED);
+                final TreeMaker make = workingCopy.getTreeMaker();
+
+                new ErrorAwareTreeScanner<Void, Void>() {
+                    @Override public Void visitUnionType(UnionTypeTree node, Void p) {
+                        List<Tree> alternatives = new ArrayList<Tree>(node.getTypeAlternatives());
+                        alternatives.remove(0);
+                        alternatives.remove(0);
+                        alternatives.add(0, make.Identifier("IOException"));
+                        alternatives.add(1, make.Identifier("RuntimeException"));
+                        workingCopy.rewrite(node, make.UnionType(alternatives));
+                        return null;
+                    }
+                }.scan(workingCopy.getCompilationUnit(), null);
+            }
+
+        };
+        testSource.runModificationTask(task).commit();
+        String res = TestUtilities.copyFileToString(testFile);
+        System.err.println(res);
+        assertEquals(golden, res);
+    }
     
     String getGoldenPckg() {
         return "";
diff --git a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/MoveClassTest.java b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/MoveClassTest.java
index 29f9df1f5..a62a93b2c 100644
--- a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/MoveClassTest.java
+++ b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/MoveClassTest.java
@@ -74,6 +74,55 @@ public void test204444() throws Exception { // #204444 - Improve Move Refactorin
                 + "}\n"));
     }
     
+    public void testNETBEANS892() throws Exception { // #204444 - Improve Move Refactoring to support nested/inner classes
+        writeFilesAndWaitForScan(src,
+                new File("a/A.java", "package a;\n"
+                + "import java.util.List;\n"
+                + "import java.util.function.Function;\n"
+                + "public class A {\n"
+                + "public void v() {try{String bar = \"foo\";}catch (RuntimeException | AssertionError e){}}\n"
+                + "public void breaks(){doStuff(x->x.substring(5));}\n"
+                + "public void doStuff(Function<String, String> stuff){}\n"
+                + "}\n"),
+                new File("a/B.java", "package a;\n"
+                + "import java.util.List;\n"
+                + "/** Class B */\n"
+                + "public class B {\n"
+                + "    public int i = 42;\n"
+                + "    private List list;\n"
+                + "}\n"),
+                new File("a/C.java", "package a;\n"
+                + "import java.util.function.Function;\n"
+                + "public class C {\n"
+                + "public void v() {try{String bar = \"foo\";}catch (RuntimeException | AssertionError e){}}\n"
+                + "public void breaks(){doStuff(x->x.substring(5));}\n"
+                + "public void doStuff(Function<String, String> stuff){}\n"
+                + "}\n"));
+        performMove(src.getFileObject("a/B.java"), 0, src.getFileObject("a/C.java"), 0);
+        verifyContent(src,
+                new File("a/A.java", "package a;\n"                
+                + "import java.util.List;\n"
+                + "import java.util.function.Function;\n"
+                + "public class A {\n"
+                + "public void v() {try{String bar = \"foo\";}catch (RuntimeException | AssertionError e){}}\n"
+                + "public void breaks(){doStuff(x->x.substring(5));}\n"
+                + "public void doStuff(Function<String, String> stuff){}\n"
+                + "}\n"),
+                new File("a/C.java", "package a;\n"
+                + "import java.util.List;\n"
+                + "import java.util.function.Function;\n"
+                + "public class C {\n"
+                + "public void v() {try{String bar = \"foo\";}catch (RuntimeException | AssertionError e){}}\n"
+                + "public void breaks(){doStuff(x->x.substring(5));}\n"
+                + "public void doStuff(Function<String, String> stuff){}\n"
+                + "/** Class B */\n"
+                + "public static class B {\n"
+                + "    public int i = 42;\n"
+                + "    private List list;\n"
+                + "}\n"
+                + "}\n"));
+    }
+    
     public void test243552() throws Exception { // #204444 - Improve Move Refactoring to support nested/inner classes
         writeFilesAndWaitForScan(src,
                 new File("t/A.java", "package t;\n"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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