Allow patterns like if ($cond) $then else $else$, where the else section is optional.
1.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinder.java Tue Feb 08 19:23:13 2011 +0100
1.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinder.java Tue Feb 08 22:08:44 2011 +0100
1.3 @@ -332,8 +332,13 @@
1.4 return false;
1.5 }
1.6
1.7 - if (node == null)
1.8 - return p == null;
1.9 + if (node == null) {
1.10 + if (p == null) return true;
1.11 + if (Utilities.isMultistatementWildcardTree(p.getLeaf())) {
1.12 + return true;
1.13 + }
1.14 + return false;
1.15 + }
1.16
1.17 if (p != null && p.getLeaf().getKind() == Kind.IDENTIFIER) {
1.18 String ident = ((IdentifierTree) p.getLeaf()).getName().toString();
1.19 @@ -555,9 +560,12 @@
1.20 }
1.21
1.22 private Boolean scan(Tree node, Tree p, TreePath pOrigin) {
1.23 - if (node == null || p == null)
1.24 - return node == p;
1.25 + if (node == null && p == null)
1.26 + return true;
1.27
1.28 + if (node != null && p == null)
1.29 + return false;
1.30 +
1.31 return scan(node, new TreePath(pOrigin, p));
1.32 }
1.33
2.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinderTest.java Tue Feb 08 19:23:13 2011 +0100
2.2 +++ b/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinderTest.java Tue Feb 08 22:08:44 2011 +0100
2.3 @@ -265,4 +265,37 @@
2.4 performTest("package test; import java.util.*; public class Test { public void test() { |List<? super String>| l1; |List<? super String>| l2;} }");
2.5 }
2.6
2.7 + public void testSingleVariableStrict() throws Exception {
2.8 + performVariablesTest("package test; public class Test { public void test() { if (true) System.err.println(1); } }",
2.9 + "if ($c) $then; else $else;",
2.10 + new Pair[0],
2.11 + new Pair[0],
2.12 + new Pair[0],
2.13 + true,
2.14 + true);
2.15 + }
2.16 +
2.17 + public void testMultiVariableZeroOrOne1() throws Exception {
2.18 + performVariablesTest("package test; public class Test { public void test() { if (true) System.err.println(1); } }",
2.19 + "if ($c) $then; else $else$;",
2.20 + new Pair[] {new Pair<String, int[]>("$c", new int[] {59, 63}),
2.21 + new Pair<String, int[]>("$then", new int[] {65, 87})},
2.22 + new Pair[0],
2.23 + new Pair[0],
2.24 + false,
2.25 + true);
2.26 + }
2.27 +
2.28 + public void testMultiVariableZeroOrOne2() throws Exception {
2.29 + performVariablesTest("package test; public class Test { public void test() { if (true) System.err.println(1); else System.err.println(2); } }",
2.30 + "if ($c) $then; else $else$;",
2.31 + new Pair[] {new Pair<String, int[]>("$c", new int[] {59, 63}),
2.32 + new Pair<String, int[]>("$then", new int[] {65, 87}),
2.33 + new Pair<String, int[]>("$else$", new int[] {93, 115})},
2.34 + new Pair[0],
2.35 + new Pair[0],
2.36 + false,
2.37 + true);
2.38 + }
2.39 +
2.40 }