use of org.glassfish.hk2.classmodel.reflect.AnnotationModel in project Payara by payara.
the class WeldUtils method getCDIEnablingAnnotations.
/**
* Get the names of any annotation types that are applied to beans, which should enable CDI
* processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
*
* @return An array of annotation type names; The array could be empty if none are found.
*/
public static String[] getCDIEnablingAnnotations(DeploymentContext context) {
List<String> result = new ArrayList<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at)) {
if (!result.contains(at.getName())) {
result.add(at.getName());
}
}
}
}
}
}
return result.toArray(new String[result.size()]);
}
use of org.glassfish.hk2.classmodel.reflect.AnnotationModel in project Payara by payara.
the class GlassFishInjectionProvider method getAnnotatedClassesInCurrentModule.
@Override
public Map<String, List<ScannedAnnotation>> getAnnotatedClassesInCurrentModule(ServletContext servletContext) throws InjectionProviderException {
Map<String, List<ScannedAnnotation>> classesByAnnotation = new HashMap<String, List<ScannedAnnotation>>();
Collection<Type> allTypes = ((DeploymentContext) servletContext.getAttribute(DEPLOYMENT_CONTEXT_ATTRIBUTE)).getTransientAppMetaData(Types.class.getName(), Types.class).getAllTypes();
for (Type type : allTypes) {
for (AnnotationModel annotationModel : type.getAnnotations()) {
String annotationName = annotationModel.getType().getName();
List<ScannedAnnotation> classesWithThisAnnotation = classesByAnnotation.get(annotationName);
if (classesWithThisAnnotation == null) {
classesWithThisAnnotation = new ArrayList<ScannedAnnotation>();
classesByAnnotation.put(annotationName, classesWithThisAnnotation);
}
ScannedAnnotation toAdd = new ScannedAnnotation() {
@Override
public boolean equals(Object obj) {
boolean result = false;
if (obj instanceof ScannedAnnotation) {
String otherName = ((ScannedAnnotation) obj).getFullyQualifiedClassName();
if (otherName != null) {
result = type.getName().equals(otherName);
}
}
return result;
}
@Override
public int hashCode() {
String str = getFullyQualifiedClassName();
Collection<URI> obj = getDefiningURIs();
int result = str != null ? str.hashCode() : 0;
result = 31 * result + (obj != null ? obj.hashCode() : 0);
return result;
}
@Override
public String getFullyQualifiedClassName() {
return type.getName();
}
@Override
public Collection<URI> getDefiningURIs() {
return type.getDefiningURIs();
}
};
if (!classesWithThisAnnotation.contains(toAdd)) {
classesWithThisAnnotation.add(toAdd);
}
}
}
return classesByAnnotation;
}
use of org.glassfish.hk2.classmodel.reflect.AnnotationModel in project Payara by payara.
the class WeldUtils method hasCDIEnablingAnnotations.
/**
* Determine whether there are any beans annotated with annotations that should enable CDI
* processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
* @param paths The paths to check for annotated beans
*
* @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
*/
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
List<String> result = new ArrayList<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at) && type.wasDefinedIn(paths)) {
if (!result.contains(at.getName())) {
result.add(at.getName());
}
}
}
}
}
}
return !(result.isEmpty());
}
use of org.glassfish.hk2.classmodel.reflect.AnnotationModel in project Payara by payara.
the class WeldUtils method getCDIAnnotatedClassNames.
/**
* Get the names of any classes that are annotated with bean-defining annotations, which should
* enable CDI processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
*
* @return A collection of class names; The collection could be empty if none are found.
*/
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
Set<String> result = new HashSet<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at)) {
if (!result.contains(at.getName())) {
result.add(type.getName());
}
}
}
}
}
}
return result;
}
Aggregations