Skip to content

Commit

Permalink
Another idea
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn committed Oct 1, 2024
1 parent 342acb0 commit 7f5117c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import jakarta.enterprise.inject.spi.AnnotatedConstructor;
import jakarta.enterprise.inject.spi.AnnotatedField;
import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.inject.Inject;

import org.jboss.weld.annotated.enhanced.ConstructorSignature;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedConstructor;
Expand All @@ -45,8 +44,6 @@
import org.jboss.weld.annotated.slim.AnnotatedTypeIdentifier;
import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType;
import org.jboss.weld.interceptor.spi.model.InterceptionType;
import org.jboss.weld.interceptor.util.InterceptionTypeRegistry;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.collections.ImmutableSet;
import org.jboss.weld.util.collections.ListMultimap;
Expand All @@ -71,17 +68,6 @@
*/
public class EnhancedAnnotatedTypeImpl<T> extends AbstractEnhancedAnnotated<T, Class<T>> implements EnhancedAnnotatedType<T> {

private static final Set<Class<? extends Annotation>> MAPPED_METHOD_ANNOTATIONS;

static {
Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes()) {
annotations.add(InterceptionTypeRegistry.getAnnotationClass(interceptionType));
}
annotations.add(Inject.class);
MAPPED_METHOD_ANNOTATIONS = ImmutableSet.copyOf(annotations);
}

@SuppressFBWarnings("unchecked")
private static final Set<Class<? extends Annotation>> MAPPED_METHOD_PARAMETER_ANNOTATIONS = ImmutableSet.of(Observes.class,
ObservesAsync.class);
Expand Down Expand Up @@ -158,7 +144,18 @@ protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType,
this.superclass = classTransformer.getEnhancedAnnotatedType(superclass, slim.getIdentifier().getBdaId());
}
} else {
this.superclass = classTransformer.getEnhancedAnnotatedType(Object.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
// TODO do we need the try-catch block? Since the class comes from an extension, do we always have access to it superclasses?
EnhancedAnnotatedType<? super T> superclassAt = null;
try {
Class<? super T> superclass = annotatedType.getJavaClass().getSuperclass();
if (superclass != null) {
superclassAt = classTransformer.getEnhancedAnnotatedType(superclass, slim.getIdentifier().getBdaId());
}
} catch (Exception e) {
// fallback, we just use Object as superclass
superclassAt = classTransformer.getEnhancedAnnotatedType(Object.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
}
this.superclass = superclassAt;
}

// Assign class field information
Expand Down Expand Up @@ -345,10 +342,8 @@ protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType,
Set<EnhancedAnnotatedMethod<?, ? super T>> effectiveMethods) {
Multimap<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ? super T>> result = SetMultimap.newSetMultimap();
for (EnhancedAnnotatedMethod<?, ? super T> method : effectiveMethods) {
for (Class<? extends Annotation> annotation : MAPPED_METHOD_ANNOTATIONS) {
if (method.isAnnotationPresent(annotation)) {
result.put(annotation, method);
}
for (Annotation ann : method.getAnnotations()) {
result.put(ann.annotationType(), method);
}
}
return Multimaps.unmodifiableMultimap(result);
Expand Down Expand Up @@ -490,8 +485,6 @@ public boolean isSerializable() {

/**
* Gets the abstracted methods that have a certain annotation type present
* <p/>
* If the annotated methods map is null, initialize it first
*
* @param annotationType The annotation type to match
* @return A set of matching method abstractions. Returns an empty set if no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected <T> Set<ResourceInjection<?>> createResourceInjections(Bean<?> declari
}

Class<? extends Annotation> marker = getMarkerAnnotation(processorContext);
final Collection<EnhancedAnnotatedField<?, ? super T>> fields = type.getEnhancedFields(marker);
final Collection<EnhancedAnnotatedField<?, ? super T>> fields = type.getDeclaredEnhancedFields(marker);
final Collection<EnhancedAnnotatedMethod<?, ? super T>> methods = type.getDeclaredEnhancedMethods(marker);

return createResourceInjections(fields, methods, declaringBean, type.getJavaClass(), manager);
Expand Down

0 comments on commit 7f5117c

Please sign in to comment.