java - How to get the super class name in annotation processing -


i run annotation processor written self generate new java code based on annotated classes. following tried super class name of processed class.

typemirror supertypemirror = typeelement.getsuperclass(); final typekind superclassname = supertypemirror.getkind(); log("a==================" + superclassname.getclass()); log("b==================" + superclassname.getdeclaringclass()); 

typeelement returns me current class annotation processor processing. want know classes extends , classes implemented class. methods used not helpful @ all.

thankx

if understood question correctly, types.directsupertypes() method need.

it return type of direct superclass first, followed (directly) implemented interfaces, if there any.

regardless of whether represent superclass or superinterface, should able cast them declaredtype, has aselement() method, can used query things simple , qualified name.

so you'll have this:

for (typemirror supertype : types.directsupertypes(typeelement)) {    declaredtype declared = (declaredtype)supertype; //you should of course check possible first    element supertypeelement = declared.aselement();    system.out.println( "supertype name: " + supertypeelement.getsimplename() ); } 

the above works if typeelement typemirror, if typeelement, can superclass , superinterfaces directly calling typeelement.getsuperclass() , typeelement.getinterfaces() separately ( instead of types.directsupertypes()) rest of process same.


Comments