-
Notifications
You must be signed in to change notification settings - Fork 13
Get default type for new class tree #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
df5d7e0
09ffa38
f6279cf
fb56232
493963a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| import com.sun.source.tree.AnnotatedTypeTree; | ||
| import com.sun.source.tree.ArrayTypeTree; | ||
| import com.sun.source.tree.ClassTree; | ||
| import com.sun.source.tree.ExpressionTree; | ||
| import com.sun.source.tree.NewClassTree; | ||
| import com.sun.source.tree.ParameterizedTypeTree; | ||
| import com.sun.source.tree.PrimitiveTypeTree; | ||
| import com.sun.source.tree.Tree; | ||
|
|
@@ -185,5 +187,16 @@ public Void visitAnnotatedType(AnnotatedTypeTree tree, Void unused) { | |
|
|
||
| return super.visitAnnotatedType(tree, unused); | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitNewClass(NewClassTree tree, Void unused) { | ||
| AnnotatedTypeMirror defaultType = getDefaultTypeFor(tree); | ||
| ExpressionTree type = tree.getIdentifier(); | ||
| if ((type instanceof ParameterizedTypeTree) && !((ParameterizedTypeTree) type).getTypeArguments().isEmpty()) | ||
| return super.visitNewClass(tree, unused); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't need the logic here. We should always save
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the |
||
|
|
||
| defaultTypes.put(type, defaultType); | ||
| return super.visitNewClass(tree, unused); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to loop through the type arguments and put the corresponding types into
defaultTypes. You can takevisitParameterizedTypeas a reference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small example like
new ArrayList<String>(), and I findsuper.VisitNewClass()already recursively call the visitParameterizedType() method for treeArrayList<String>. So, I don't think I need to call that method again.Besides, what are the type arguments of a new class tree?
As said in the javadoc in NewClassTree.java
The typearguments is in front of the identifier. And when I played around with this example
new ArrayList<String>(), usingtree.getTypeArguments()returns an empty list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I forgot the
typeArgumentsare not arguments to the class' type parameters. Those are arguments to type parameters on the constructor.