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.

Bug 115176 - TreeMaker.ParameterizedType(...) requires list of ExpressionTrees
Summary: TreeMaker.ParameterizedType(...) requires list of ExpressionTrees
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords: API
Depends on:
Blocks:
 
Reported: 2007-09-10 16:31 UTC by Marian Petras
Modified: 2007-10-08 15:22 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marian Petras 2007-09-10 16:31:49 UTC
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.
Comment 1 Marian Petras 2007-09-10 16:59:09 UTC
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)
Comment 2 Pavel Flaska 2007-10-08 10:13:27 UTC
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
Comment 3 Pavel Flaska 2007-10-08 12:44:03 UTC
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
Comment 4 Marian Petras 2007-10-08 14:00:18 UTC
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.
Comment 5 Jan Lahoda 2007-10-08 14:10:46 UTC
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)
Comment 6 Marian Petras 2007-10-08 15:22:43 UTC
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