Skip to content

Commit

Permalink
CDI-481 Introduce AnnotatedParameter.getJavaParameter() (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba authored and antoinesd committed Nov 18, 2016
1 parent b155833 commit 2c30ec2
Showing 1 changed file with 19 additions and 0 deletions.
Expand Up @@ -17,13 +17,18 @@

package javax.enterprise.inject.spi;

import java.lang.reflect.Executable;
import java.lang.reflect.Member;
import java.lang.reflect.Parameter;

/**
* <p>
* Represents a parameter of a method or constructor.
* </p>
*
* @author Gavin King
* @author Pete Muir
* @author Jozef Hartinger
*
* @param <X> the type that declares the method or constructor
*/
Expand All @@ -47,4 +52,18 @@ public interface AnnotatedParameter<X> extends Annotated {
*/
public AnnotatedCallable<X> getDeclaringCallable();

/**
* Get the underlying {@link Parameter}.
*
* @return the {@link Parameter}
*/
default Parameter getJavaParameter() {
Member member = getDeclaringCallable().getJavaMember();
if (!(member instanceof Executable)) {
throw new IllegalStateException("Parameter does not belong to an executable: " + member);
}
Executable executable = (Executable) member;
return executable.getParameters()[getPosition()];
}

}

0 comments on commit 2c30ec2

Please sign in to comment.