java - How to extract the single type of a parameterized type using jdt -


i trying parse java source files , info using ast. want somehow type of parameterized types eg list<string> need string.

public boolean visit(variabledeclarationfragment f) { if (f.getparent() instanceof fielddeclaration) {     fielddeclaration d = (fielddeclaration) f.getparent();     if (d.gettype().isparameterizedtype()) {         system.out.println("par type : " + d.gettype().tostring());     } } } 

this snippet gives me list<string>. ideas on how proceed?

you need cast type parametrizedtype , extract inner type.

public boolean visit(variabledeclarationfragment f) {   if (f.getparent() instanceof fielddeclaration) {     fielddeclaration d = (fielddeclaration) f.getparent();     if (d.gettype().isparameterizedtype()) {       parameterizedtype partype = (parameterizedtype) d.gettype();       system.out.println("par type : " + partype.typearguments().get(0).tostring());     }   } } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -