This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Method TreeMaker.ParameterizedType(Tree, List<ExpressionTree>) requires that the second argument is a list of ExpressionTrees, although the method itself declares that it returns just Tree-s. As a result, it is not possible to build a parametrized tree with parametrized type arguments.
This bug does blocks a proper fix of bug #103183 ("Create Unittests drops parameterized types (generics)"). Specifically, it does not allow creation of source code like: List<Map.Entry<String,String>> (nested parametrized types)
See test method test115176HowTo(), there is an example how to implement it without fixed TreeMaker. Fix will be provided too, but the way shown in the test case can be useful anyway. For the time being, removing dependency, there is a way how to do that. Checking in test/unit/src/org/netbeans/api/java/source/gen/ParameterizedTypeTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/ParameterizedTypeTest.java,v <-- ParameterizedTypeTest.java initial revision: 1.1 done
t/src/org/netbeans/api/java/source/gen/ParameterizedTypeTest.java Checking in src/org/netbeans/api/java/source/TreeMaker.java; /cvs/java/source/src/org/netbeans/api/java/source/TreeMaker.java,v <-- TreeMaker.java new revision: 1.28; previous revision: 1.27 done Checking in src/org/netbeans/modules/java/source/builder/TreeFactory.java; /cvs/java/source/src/org/netbeans/modules/java/source/builder/TreeFactory.java,v <-- TreeFactory.java new revision: 1.22; previous revision: 1.21 done Checking in test/unit/src/org/netbeans/api/java/source/gen/ParameterizedTypeTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/ParameterizedTypeTest.java,v <-- ParameterizedTypeTest.java new revision: 1.2; previous revision: 1.1 done
Thanks for the proper fix. The temporary workaround would not work well for me (I would have to generate the type string first, just to pass it to the parser). Verified in custom build #071008.
Please note that the "temporary workaround" (actually, two of them, see option 1. below) are generally better than using ParameterizedType&Identifier directly, because they handle imports automatically. Please note that when using TreeMaker.Identifier you are on your own with imports. Better is: 1. use of TreeMaker.Type(TypeMirror) (the TypeMirror can be constructed either using TreeUtilities.parseType or by combination of Types.getDeclaredType, Elements.getTypeElement and TypeElement.asType). 2. use of TreeMaker.QualIdent (and TreeMaker.ParameterizedType)
I have not been using TreeMaker.Identifier(...) for class names (maybe with the exception of classes from java.lang). But thank you for the hint about TreeMaker.Type(...). I have not been using this method and I had my own method providing the same functionality. I could remove my method now and call TreeMaker.Type(...) instead: http://deadlock.netbeans.org/fisheye/browse/netbeans/junit/src/org/netbeans/modules/junit/AbstractTestGenerator.java?r1=1.13&r2=1.14