Skip to content

Commit

Permalink
WELD-1811 add warning when decorator declares inappropriate constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes committed Dec 8, 2015
1 parent e7a2ab8 commit 6e6114c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ protected void createClassBean(SlimAnnotatedType<?> annotatedType, SetMultimap<C
createManagedBean(weldClass);
}
} else {
if(Beans.isDecoratorDeclaringInAppropriateConstructor(annotatedType)){
BootstrapLogger.LOG.decoratorWithNonCdiConstructor(annotatedType.getJavaClass().getName());
}
otherWeldClasses.put(annotatedType.getJavaClass(), annotatedType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, Strin
}
}

if(Beans.isDecoratorDeclaringInAppropriateConstructor(classFileInfo)){
BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName());
}

// lastly, check if this class fulfills CDI managed bean requirements - if it does, add the class
if (Beans.isTypeManagedBeanOrDecoratorOrInterceptor(classFileInfo)) {
return createContext(className, classFileInfo, observerMethods, bdaId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ public interface BootstrapLogger extends WeldLogger {
@LogMessage(level = Level.WARN)
@Message(id = 146, value = "BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for {0} is deprecated from CDI 1.1!", format = Format.MESSAGE_FORMAT)
void deprecatedAddAnnotatedTypeMethodUsed(Class<?> clazz);

@LogMessage(level = Level.WARN)
@Message(id = 147, value = "Decorator {0} declares inappropriate constructor therefore will not available as a managed bean!", format = Format.MESSAGE_FORMAT)
void decoratorWithNonCdiConstructor(String clazzName);
}
8 changes: 8 additions & 0 deletions impl/src/main/java/org/jboss/weld/util/Beans.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ public static boolean isTypeManagedBeanOrDecoratorOrInterceptor(ClassFileInfo cl
&& (!Modifier.isAbstract(classFileInfo.getModifiers()) || classFileInfo.isAnnotationDeclared(Decorator.class));
}

public static boolean isDecoratorDeclaringInAppropriateConstructor(ClassFileInfo classFileInfo) {
return !classFileInfo.hasCdiConstructor() && classFileInfo.isAnnotationDeclared(Decorator.class);
}

public static boolean isDecoratorDeclaringInAppropriateConstructor(AnnotatedType<?> annotatedType) {
return !hasSimpleCdiConstructor(annotatedType) && annotatedType.isAnnotationPresent(Decorator.class);
}

public static boolean hasSimpleCdiConstructor(AnnotatedType<?> type) {
for (AnnotatedConstructor<?> constructor : type.getConstructors()) {
if (constructor.getParameters().isEmpty()) {
Expand Down

0 comments on commit 6e6114c

Please sign in to comment.