How to get parameter type from javax.lang.model.VariableElement
I'm trying to find the types of the parameters of a method using the Java 6 metamodel API. If the type is an enum, I'd also like to know all of it's type's enum constant names. Here's what I've got so far:
for (Element member : members) {
if(memb开发者_StackOverflow社区er.getKind() == ElementKind.METHOD) {
ExecutableElement methodElement = (ExecutableElement) member;
List<? extends VariableElement> parameters = methodElement.getParameters();
for (VariableElement parameter : parameters) {
//How do I get the type of the parameter here?
}
}
}
Element#asType() gets you the DeclaredType.
For enums, use Types#asElement() with the DeclaredType to get the enum type's element, and then iterate over the members using either an ElementVisitor or by using getEnclosedElements().
精彩评论