roaster
roaster copied to clipboard
How to Utilize generics while keeping typecasting minimum
currently if you have a java class and if you want to parse it(or obtain it) recursively.we need to do.
for(org.jboss.forge.roaster.model.JavaType jtypes:javaClass.getNestedTypes()){
org.jboss.forge.roaster.model.source.JavaClassSource assumetypeiscls=(org.jboss.forge.roaster.model.source.JavaClassSource)jtypes;
.........
is there any way to just not cast it into a classsource?or maybe cast to a more genric type? that may include interface.
JavaType
is the generic type. You can invoke the isClass()
,isInferface()
, etc methods to figure out the type (or instanceof if you like)
so i would need write ifelse checking and then cast the types accordingly?
Is there any more efficient way?
In the meantime, yes. A Visitor pattern could be introduced in the API, with visit(...)
methods for the existing types.
Would you like to contribute with it?
hmm sadly I have never implemented a visitor API before,so I dont think i can contribute it.