use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class PassivationAnnotationParsingProcessor method processPassivation.
private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
if (!(target instanceof MethodInfo)) {
throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final Type[] args = methodInfo.args();
if (args.length > 1) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
return;
} else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
return;
}
final MethodIdentifier methodIdentifier;
if (args.length == 0) {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
} else {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
}
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
if (annotationType == POST_ACTIVATE) {
builder.setPostActivate(methodIdentifier);
} else {
builder.setPrePassivate(methodIdentifier);
}
classDescription.setInterceptorClassDescription(builder.build());
}
use of org.jboss.jandex.MethodInfo in project wildfly-swarm by wildfly-swarm.
the class HealthAnnotationProcessor method process.
@Override
public void process() throws NamingException {
// first pass: jboss-web context root
Optional<String> jbossWebContext = Optional.empty();
// if (archive instanceof JBossWebContainer) {
if (archive.getName().endsWith(".war")) {
JBossWebContainer war = archive.as(WARArchive.class);
if (war.getContextRoot() != null) {
jbossWebContext = Optional.of(war.getContextRoot());
}
}
// second pass: JAX-RS applications
Optional<String> appPath = Optional.empty();
Collection<AnnotationInstance> appPathAnnotations = index.getAnnotations(APP_PATH);
for (AnnotationInstance annotation : appPathAnnotations) {
if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
appPath = Optional.of(annotation.value().asString());
}
}
// third pass: JAX-RS resources
Collection<AnnotationInstance> pathAnnotations = index.getAnnotations(PATH);
for (AnnotationInstance annotation : pathAnnotations) {
if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
ClassInfo classInfo = annotation.target().asClass();
for (MethodInfo methodInfo : classInfo.methods()) {
if (methodInfo.hasAnnotation(HEALTH)) {
StringBuilder sb = new StringBuilder();
boolean isSecure = false;
// prepend the jboss-web cntext if given
if (jbossWebContext.isPresent() && !jbossWebContext.get().equals("/")) {
safeAppend(sb, jbossWebContext.get());
}
// prepend the appPath if given
if (appPath.isPresent() && !appPath.get().equals("/")) {
safeAppend(sb, appPath.get());
}
// the class level @Path
for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) {
if (classAnnotation.name().equals(PATH)) {
String methodPathValue = classAnnotation.value().asString();
if (!methodPathValue.equals("/")) {
safeAppend(sb, methodPathValue);
}
}
}
if (methodInfo.hasAnnotation(PATH)) {
// the method level @Path
safeAppend(sb, methodInfo.annotation(PATH).value().asString());
// the method level @Health
AnnotationInstance healthAnnotation = methodInfo.annotation(HEALTH);
isSecure = healthAnnotation.value("inheritSecurity") != null ? healthAnnotation.value("inheritSecurity").asBoolean() : true;
} else {
throw new RuntimeException("@Health requires an explicit @Path annotation");
}
HealthMetaData metaData = new HealthMetaData(sb.toString(), isSecure);
Monitor.lookup().registerHealth(metaData);
}
}
}
}
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class JPAAnnotationProcessor method processPersistenceAnnotations.
private void processPersistenceAnnotations(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
for (AnnotationInstance annotation : persistenceContexts) {
ClassInfo declaringClass;
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof FieldInfo) {
FieldInfo fieldInfo = (FieldInfo) annotationTarget;
declaringClass = fieldInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof MethodInfo) {
MethodInfo methodInfo = (MethodInfo) annotationTarget;
declaringClass = methodInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof ClassInfo) {
declaringClass = (ClassInfo) annotationTarget;
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processClass(deploymentUnit, annotation, eeModuleClassDescription);
}
}
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class ServerInterceptorCache method findAnnotatedMethods.
private List<InterceptorFactory> findAnnotatedMethods(final Class<?> interceptorClass, final Index index, final Class<?> annotationClass) {
final List<InterceptorFactory> interceptorFactories = new ArrayList<>();
final DotName annotationName = DotName.createSimple(annotationClass.getName());
final List<AnnotationInstance> annotations = index.getAnnotations(annotationName);
for (final AnnotationInstance annotation : annotations) {
if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) {
final MethodInfo methodInfo = annotation.target().asMethod();
final Constructor<?> constructor;
try {
constructor = interceptorClass.getConstructor();
} catch (NoSuchMethodException e) {
throw EjbLogger.ROOT_LOGGER.serverInterceptorNoEmptyConstructor(interceptorClass.toString(), e);
}
try {
final Method annotatedMethod = interceptorClass.getMethod(methodInfo.name(), new Class[] { InvocationContext.class });
final InterceptorFactory interceptorFactory = createInterceptorFactoryForServerInterceptor(annotatedMethod, constructor);
interceptorFactories.add(interceptorFactory);
} catch (NoSuchMethodException e) {
throw EjbLogger.ROOT_LOGGER.serverInterceptorInvalidMethod(methodInfo.name(), interceptorClass.toString(), annotationClass.toString(), e);
}
}
}
return interceptorFactories;
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class JandexAnnotationRepositoryImpl method getAnnotation.
@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
Annotation annotation = null;
if (target instanceof MethodInfo) {
MethodInfo m = (MethodInfo) target;
List<String> parameterTypes = new ArrayList<String>(m.args().length);
for (Type type : m.args()) {
parameterTypes.add(type.toString());
}
String declaringClass = m.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
}
if (target instanceof FieldInfo) {
FieldInfo f = (FieldInfo) target;
String declaringClass = f.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
}
if (target instanceof ClassInfo) {
ClassInfo c = (ClassInfo) target;
annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
}
if (annotation != null) {
annotations.add(annotation);
}
}
annotations.trimToSize();
if (annotations.isEmpty()) {
return null;
} else {
return Collections.unmodifiableList(annotations);
}
}
Aggregations