Support for wildcards in CopyFinder
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 06 Jan 2011 20:47:24 +0100
changeset 51195c8ab6e47f7
parent 510 455133155847
child 512 c70867b1de60
Support for wildcards in CopyFinder
api/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinder.java
api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinderTest.java
hintsimpl/test/unit/src/org/netbeans/modules/jackpot30/hintsimpl/jdk7/ConvertToDiamondBulkHintTest.java
     1.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinder.java	Thu Jan 06 19:27:11 2011 +0100
     1.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinder.java	Thu Jan 06 20:47:24 2011 +0100
     1.3 @@ -74,6 +74,7 @@
     1.4  import com.sun.source.tree.UnaryTree;
     1.5  import com.sun.source.tree.VariableTree;
     1.6  import com.sun.source.tree.WhileLoopTree;
     1.7 +import com.sun.source.tree.WildcardTree;
     1.8  import com.sun.source.util.SourcePositions;
     1.9  import com.sun.source.util.TreePath;
    1.10  import com.sun.source.util.TreeScanner;
    1.11 @@ -1383,10 +1384,15 @@
    1.12  
    1.13          return scan(node.getStatement(), t.getStatement(), p);
    1.14      }
    1.15 -///
    1.16 -//    public Boolean visitWildcard(WildcardTree node, TreePath p) {
    1.17 -//        throw new UnsupportedOperationException("Not supported yet.");
    1.18 -//    }
    1.19 +
    1.20 +    public Boolean visitWildcard(WildcardTree node, TreePath p) {
    1.21 +        if (p == null)
    1.22 +            return super.visitWildcard(node, p);
    1.23 +
    1.24 +        WildcardTree t = (WildcardTree) p.getLeaf();
    1.25 +
    1.26 +        return scan(node.getBound(), t.getBound(), p);
    1.27 +    }
    1.28  //
    1.29  //    public Boolean visitOther(Tree node, TreePath p) {
    1.30  //        throw new UnsupportedOperationException("Not supported yet.");
     2.1 --- a/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinderTest.java	Thu Jan 06 19:27:11 2011 +0100
     2.2 +++ b/api/test/unit/src/org/netbeans/modules/jackpot30/impl/pm/CopyFinderTest.java	Thu Jan 06 20:47:24 2011 +0100
     2.3 @@ -43,6 +43,7 @@
     2.4  import java.util.Arrays;
     2.5  import java.util.Collection;
     2.6  import java.util.HashMap;
     2.7 +import java.util.List;
     2.8  import java.util.Map;
     2.9  import java.util.Map.Entry;
    2.10  import java.util.concurrent.atomic.AtomicBoolean;
    2.11 @@ -251,4 +252,17 @@
    2.12                               false,
    2.13                               false);
    2.14      }
    2.15 +
    2.16 +    public void testWildcard1() throws Exception {
    2.17 +        performTest("package test; import java.util.*; public class Test { public void test() { |List<?>| l1; |List<?>| l2;} }");
    2.18 +    }
    2.19 +
    2.20 +    public void testWildcard2() throws Exception {
    2.21 +        performTest("package test; import java.util.*; public class Test { public void test() { |List<? extends String>| l1; |List<? extends String>| l2;} }");
    2.22 +    }
    2.23 +
    2.24 +    public void testWildcard3() throws Exception {
    2.25 +        performTest("package test; import java.util.*; public class Test { public void test() { |List<? super String>| l1; |List<? super String>| l2;} }");
    2.26 +    }
    2.27 +
    2.28  }
     3.1 --- a/hintsimpl/test/unit/src/org/netbeans/modules/jackpot30/hintsimpl/jdk7/ConvertToDiamondBulkHintTest.java	Thu Jan 06 19:27:11 2011 +0100
     3.2 +++ b/hintsimpl/test/unit/src/org/netbeans/modules/jackpot30/hintsimpl/jdk7/ConvertToDiamondBulkHintTest.java	Thu Jan 06 20:47:24 2011 +0100
     3.3 @@ -141,6 +141,16 @@
     3.4                              "2:43-2:71:error:");
     3.5      }
     3.6  
     3.7 +    public void testConfiguration2c() throws Exception {
     3.8 +        setSourceLevel("1.7");
     3.9 +        allBut("initializer");
    3.10 +        performAnalysisTest("test/Test.java",
    3.11 +                            "package test;\n" +
    3.12 +                            "public class Test {\n" +
    3.13 +                            "    { java.util.LinkedList<java.util.LinkedList<?>> l = new java.util.LinkedList<java.util.LinkedList<?>>(); }\n" +
    3.14 +                            "}\n");
    3.15 +    }
    3.16 +
    3.17      public void testConfiguration3() throws Exception {
    3.18          setSourceLevel("1.7");
    3.19          allBut("initializer");