use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class EjbValidationsUtil method assertEjbClassValidity.
/**
* Returns true if the passed <code>mdbClass</code> meets the requirements set by the Enterprise Beans 3 spec about bean implementation
* classes. The passed <code>mdbClass</code> must not be an interface and must be public and not final and not abstract. If
* it passes these requirements then this method returns true. Else it returns false.
*
* @param mdbClass The MDB class
* @return
* @throws DeploymentUnitProcessingException
*/
public static Collection<MdbValidityStatus> assertEjbClassValidity(final ClassInfo mdbClass) throws DeploymentUnitProcessingException {
Collection<MdbValidityStatus> mdbComplianceIssueList = new ArrayList<>(MdbValidityStatus.values().length);
final String className = mdbClass.name().toString();
verifyModifiers(className, mdbClass.flags(), mdbComplianceIssueList);
for (MethodInfo method : mdbClass.methods()) {
if ("onMessage".equals(method.name())) {
verifyOnMessageMethod(className, method.flags(), mdbComplianceIssueList);
}
if ("finalize".equals(method.name())) {
EjbLogger.DEPLOYMENT_LOGGER.mdbCantHaveFinalizeMethod(className);
mdbComplianceIssueList.add(MdbValidityStatus.MDB_SHOULD_NOT_HAVE_FINALIZE_METHOD);
}
}
return mdbComplianceIssueList;
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class JaxrsScanningProcessor method scan.
protected void scan(final DeploymentUnit du, final ClassLoader classLoader, final ResteasyDeploymentData resteasyDeploymentData) throws DeploymentUnitProcessingException, ModuleLoadException {
final CompositeIndex index = du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (!resteasyDeploymentData.shouldScan()) {
return;
}
if (!resteasyDeploymentData.isDispatcherCreated()) {
final Set<ClassInfo> applicationClasses = index.getAllKnownSubclasses(APPLICATION);
try {
for (ClassInfo c : applicationClasses) {
if (Modifier.isAbstract(c.flags()))
continue;
@SuppressWarnings("unchecked") Class<? extends Application> scanned = (Class<? extends Application>) classLoader.loadClass(c.name().toString());
resteasyDeploymentData.getScannedApplicationClasses().add(scanned);
}
} catch (ClassNotFoundException e) {
throw JaxrsLogger.JAXRS_LOGGER.cannotLoadApplicationClass(e);
}
}
List<AnnotationInstance> resources = null;
List<AnnotationInstance> providers = null;
if (resteasyDeploymentData.isScanResources()) {
resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName());
}
if (resteasyDeploymentData.isScanProviders()) {
providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName());
}
if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty()))
return;
final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>();
if (resources != null) {
for (AnnotationInstance e : resources) {
final ClassInfo info;
if (e.target() instanceof ClassInfo) {
info = (ClassInfo) e.target();
} else if (e.target() instanceof MethodInfo) {
// ignore
continue;
} else {
JAXRS_LOGGER.classOrMethodAnnotationNotFound("@Path", e.target());
continue;
}
if (info.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (info.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString());
} else {
pathInterfaces.add(info);
}
}
}
if (providers != null) {
for (AnnotationInstance e : providers) {
if (e.target() instanceof ClassInfo) {
ClassInfo info = (ClassInfo) e.target();
if (info.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (info.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString());
}
} else {
JAXRS_LOGGER.classAnnotationNotFound("@Provider", e.target());
}
}
}
// look for all implementations of interfaces annotated @Path
for (final ClassInfo iface : pathInterfaces) {
final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name());
for (final ClassInfo implementor : implementors) {
if (implementor.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (implementor.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString());
}
}
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class AroundInvokeAnnotationParsingProcessor method processAroundInvoke.
private void processAroundInvoke(final EEModuleDescription eeModuleDescription, final AnnotationTarget target) throws DeploymentUnitProcessingException {
if (!(target instanceof MethodInfo)) {
throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(AROUND_INVOKE_ANNOTATION_NAME);
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final List<AnnotationInstance> classAroundInvokes = classInfo.annotations().get(AROUND_INVOKE_ANNOTATION_NAME);
if (classAroundInvokes.size() > 1) {
throw EeLogger.ROOT_LOGGER.aroundInvokeAnnotationUsedTooManyTimes(classInfo.name(), classAroundInvokes.size());
}
validateArgumentType(classInfo, methodInfo);
InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
builder.setAroundInvoke(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class));
classDescription.setInterceptorClassDescription(builder.build());
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class ClassAnnotationInformationFactory method getMethodIdentifier.
private MethodIdentifier getMethodIdentifier(final AnnotationTarget target) {
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final String[] args = new String[methodInfo.args().length];
for (int i = 0; i < methodInfo.args().length; i++) {
args[i] = methodInfo.args()[i].name().toString();
}
return MethodIdentifier.getIdentifier(methodInfo.returnType().name().toString(), methodInfo.name(), args);
}
use of org.jboss.jandex.MethodInfo in project wildfly by wildfly.
the class ClassAnnotationInformationFactory method createAnnotationInformation.
public Map<String, ClassAnnotationInformation<A, T>> createAnnotationInformation(final CompositeIndex index, final PropertyReplacer propertyReplacer) {
final List<TargetAnnotation> annotations = new ArrayList<TargetAnnotation>();
if (multiAnnotationDotName != null) {
for (AnnotationInstance multiInstance : index.getAnnotations(multiAnnotationDotName)) {
annotations.addAll(fromMultiAnnotation(multiInstance));
}
}
final List<AnnotationInstance> simpleAnnotations = index.getAnnotations(annotationDotName);
if (simpleAnnotations != null) {
for (AnnotationInstance annotation : simpleAnnotations) {
annotations.add(new TargetAnnotation(annotation, annotation.target()));
}
}
final Map<DotName, List<TargetAnnotation>> classLevel = new HashMap<DotName, List<TargetAnnotation>>();
final Map<DotName, List<TargetAnnotation>> methodLevel = new HashMap<DotName, List<TargetAnnotation>>();
final Map<DotName, List<TargetAnnotation>> fieldLevel = new HashMap<DotName, List<TargetAnnotation>>();
for (TargetAnnotation instance : annotations) {
final DotName targetClass = getAnnotationClass(instance.target()).name();
if (instance.target() instanceof ClassInfo) {
List<TargetAnnotation> data = classLevel.get(targetClass);
if (data == null)
classLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof MethodInfo) {
List<TargetAnnotation> data = methodLevel.get(targetClass);
if (data == null)
methodLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof FieldInfo) {
List<TargetAnnotation> data = fieldLevel.get(targetClass);
if (data == null)
fieldLevel.put(targetClass, data = new ArrayList<TargetAnnotation>(1));
data.add(instance);
} else if (instance.target() instanceof MethodParameterInfo) {
// ignore for now
} else {
throw EeLogger.ROOT_LOGGER.unknownAnnotationTargetType(instance.target());
}
}
final Map<String, ClassAnnotationInformation<A, T>> ret = new HashMap<String, ClassAnnotationInformation<A, T>>();
final Set<DotName> allClasses = new HashSet<DotName>(classLevel.keySet());
allClasses.addAll(methodLevel.keySet());
allClasses.addAll(fieldLevel.keySet());
for (DotName clazz : allClasses) {
final List<TargetAnnotation> classAnnotations = classLevel.get(clazz);
final List<T> classData;
if (classAnnotations == null) {
classData = Collections.emptyList();
} else {
classData = new ArrayList<T>(classAnnotations.size());
for (TargetAnnotation instance : classAnnotations) {
classData.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
final List<TargetAnnotation> fieldAnnotations = fieldLevel.get(clazz);
final Map<String, List<T>> fieldData;
// field level annotations
if (fieldAnnotations == null) {
fieldData = Collections.emptyMap();
} else {
fieldData = new HashMap<String, List<T>>();
for (TargetAnnotation instance : fieldAnnotations) {
final String name = ((FieldInfo) instance.target()).name();
List<T> data = fieldData.get(name);
if (data == null) {
fieldData.put(name, data = new ArrayList<T>(1));
}
data.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
final List<TargetAnnotation> methodAnnotations = methodLevel.get(clazz);
final Map<MethodIdentifier, List<T>> methodData;
// method level annotations
if (methodAnnotations == null) {
methodData = Collections.emptyMap();
} else {
methodData = new HashMap<MethodIdentifier, List<T>>();
for (TargetAnnotation instance : methodAnnotations) {
final MethodIdentifier identifier = getMethodIdentifier(instance.target());
List<T> data = methodData.get(identifier);
if (data == null) {
methodData.put(identifier, data = new ArrayList<T>(1));
}
data.add(fromAnnotation(instance.instance(), propertyReplacer));
}
}
ClassAnnotationInformation<A, T> information = new ClassAnnotationInformation<A, T>(annotationType, classData, methodData, fieldData);
ret.put(clazz.toString(), information);
}
return ret;
}
Aggregations