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(member.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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With