sorry for bothering you with this. However, unfortunately im not able to find
a way to implement the following scenario.
I want to add generics to TypeReferences and New statements. So my code looks
like
HashMap map = new HashMap();
I would like to transform it to
HashMap<String, Constant=""> map = new HashMap<String, Constant="">
Unfortunately, i am unable to find a way to add generics to the typeReference
or New statement. Would be great if you could give me a hint how I could add
generics to Statements.
regards
frederik
I try to add a type annotation to a List HashMap.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You'll first have to get the type reference.
For a "New" statement, that's just obtained through getTypeReference(). For a
"VariableDeclaration" (covers fields, parameters, and local variables), it's
also getTypeReference().
If you're sure that a TypeReference has no TypeArguments (otherwise, you
wouldn't want to add any anyway), the following approach should work:
// preparation
ASTList<TypeArgumentDeclaration> list = new
ASTList<TypeArgumentDeclaration>();
typeRef.setTypeArguments(list);
...
code to create proper typeArgs.
...
list.add(typeArg1);
list.add(typeArg2);
// don't forget the following:
typeRef.makeParentRoleValid();
changeHistory.attached(typeArg1);
changeHistory.attached(typeArg2);
Hope it helps, otherwise, don't hesitate to contact me!
Regards,
Tobias
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Recoder Developers,
sorry for bothering you with this. However, unfortunately im not able to find
a way to implement the following scenario.
I want to add generics to TypeReferences and New statements. So my code looks
like
HashMap map = new HashMap();
I would like to transform it to
HashMap<String, Constant=""> map = new HashMap<String, Constant="">
Unfortunately, i am unable to find a way to add generics to the typeReference
or New statement. Would be great if you could give me a hint how I could add
generics to Statements.
regards
frederik
I try to add a type annotation to a List HashMap.
Hi,
You'll first have to get the type reference.
For a "New" statement, that's just obtained through getTypeReference(). For a
"VariableDeclaration" (covers fields, parameters, and local variables), it's
also getTypeReference().
If you're sure that a TypeReference has no TypeArguments (otherwise, you
wouldn't want to add any anyway), the following approach should work:
// preparation
ASTList<TypeArgumentDeclaration> list = new
ASTList<TypeArgumentDeclaration>();
typeRef.setTypeArguments(list);
...
code to create proper typeArgs.
...
list.add(typeArg1);
list.add(typeArg2);
// don't forget the following:
typeRef.makeParentRoleValid();
changeHistory.attached(typeArg1);
changeHistory.attached(typeArg2);
Hope it helps, otherwise, don't hesitate to contact me!
Regards,
Tobias
Hi Tobias,
thanks for your immediate help. Works as anticipated!!!
cheers
fred