Author: akazakov
Date: 2010-05-12 10:34:08 -0400 (Wed, 12 May 2010)
New Revision: 22038
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeStereotype.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeInterceptorBroken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added new CDI validation rule: The bean
class of a managed bean is annotated with both the @Interceptor and @Decorator
stereotypes; Managed bean with a public field declares any scope other than @Dependent;
Managed bean with a parameterized bean class declares any scope other than @Dependent
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -23,6 +23,7 @@
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.text.ITextSourceReference;
import org.jboss.tools.jst.web.kb.IKbProject;
/**
@@ -39,8 +40,7 @@
try {
EclipseUtil.addNatureToProject(project, CDICoreNature.NATURE_ID);
if (!project.hasNature(IKbProject.NATURE_ID)) {
- EclipseResourceUtil.addNatureToProject(project,
- IKbProject.NATURE_ID);
+ EclipseResourceUtil.addNatureToProject(project, IKbProject.NATURE_ID);
}
EclipseResourceUtil.addBuilderToProject(project,
ValidationPlugin.VALIDATION_BUILDER_ID);
} catch (CoreException e) {
@@ -55,62 +55,190 @@
*/
public static void disableCDI(IProject project) {
try {
- EclipseUtil.removeNatureFromProject(project,
- CDICoreNature.NATURE_ID);
+ EclipseUtil.removeNatureFromProject(project, CDICoreNature.NATURE_ID);
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
}
}
-
+
/**
* Finds CDI injected point in beans for particular java element.
*
* @param beans
* @param element
*/
- public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element){
- if(!(element instanceof IField) && (element instanceof IMethod) )
+ public static IInjectionPoint findInjectionPoint(Set<IBean> beans, IJavaElement
element) {
+ if (!(element instanceof IField) && (element instanceof IMethod)) {
return null;
-
- for(IBean bean : beans){
+ }
+
+ for (IBean bean : beans) {
Set<IInjectionPoint> injectionPoints = bean.getInjectionPoints();
- for(IInjectionPoint iPoint : injectionPoints){
- if(element instanceof IField && iPoint instanceof IInjectionPointField){
- if(((IInjectionPointField)iPoint).getField() != null &&
((IInjectionPointField)iPoint).getField().equals(element))
+ for (IInjectionPoint iPoint : injectionPoints) {
+ if (element instanceof IField && iPoint instanceof IInjectionPointField) {
+ if (((IInjectionPointField) iPoint).getField() != null &&
((IInjectionPointField) iPoint).getField().equals(element)) {
return iPoint;
- }else if(element instanceof IMethod && iPoint instanceof
IInjectionPointMethod){
- if(((IInjectionPointMethod)iPoint).getMethod() != null &&
((IInjectionPointMethod)iPoint).getMethod().equals(element))
+ }
+ } else if (element instanceof IMethod && iPoint instanceof
IInjectionPointMethod) {
+ if (((IInjectionPointMethod) iPoint).getMethod() != null &&
((IInjectionPointMethod) iPoint).getMethod().equals(element)) {
return iPoint;
-
+ }
}
}
}
- return null;
+ return null;
}
/**
- * Sorts CDI beans which may be injected. Sets for alternative beans higher position and
for nonalternative beans lower position.
+ * Sorts CDI beans which may be injected. Sets for alternative beans higher
+ * position and for nonalternative beans lower position.
*
* @param beans
* @param element
*/
- public static List<IBean> sortBeans(Set<IBean> beans){
+ public static List<IBean> sortBeans(Set<IBean> beans) {
Set<IBean> alternativeBeans = new HashSet<IBean>();
Set<IBean> nonAlternativeBeans = new HashSet<IBean>();
-
- for(IBean bean : beans){
- if(bean == null || bean instanceof IDecorator || bean instanceof IInterceptor)
+
+ for (IBean bean : beans) {
+ if (bean == null || bean instanceof IDecorator || bean instanceof IInterceptor) {
continue;
-
- if(bean.isAlternative())
+ }
+ if (bean.isAlternative()) {
alternativeBeans.add(bean);
- else
+ } else {
nonAlternativeBeans.add(bean);
+ }
}
-
+
ArrayList<IBean> sortedBeans = new ArrayList<IBean>();
sortedBeans.addAll(alternativeBeans);
sortedBeans.addAll(nonAlternativeBeans);
return sortedBeans;
}
+
+ /**
+ * Checks if the bean has @Depended scope. If it has different scope then @Depended
+ * then returns this scope declaration or a stereotype which declares the
+ * scope. Otherwise returns null.
+ *
+ * @param bean
+ * @param scopeTypeName
+ * @return
+ */
+ public static IAnnotationDeclaration getDifferentScopeDeclarationThanDepentend(IScoped
scoped) {
+ return getAnotherScopeDeclaration(scoped,
CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
+ }
+
+ /**
+ * Checks if the bean has given scope. If it has different scope then given
+ * then returns this scope declaration or a stereotype which declares the
+ * scope. Otherwise returns null.
+ *
+ * @param bean
+ * @param scopeTypeName
+ * @return
+ */
+ public static IAnnotationDeclaration getAnotherScopeDeclaration(IScoped scoped, String
scopeTypeName) {
+ IScope scope = scoped.getScope();
+ if (!scopeTypeName.equals(scope.getSourceType().getFullyQualifiedName())) {
+ Set<IScopeDeclaration> scopeDeclarations = scoped.getScopeDeclarations();
+ if (!scopeDeclarations.isEmpty()) {
+ return scopeDeclarations.iterator().next();
+ }
+ if (scoped instanceof IStereotyped) {
+ Set<IStereotypeDeclaration> stereoTypeDeclarations = ((IStereotyped)
scoped).getStereotypeDeclarations();
+ for (IStereotypeDeclaration stereotypeDeclaration : stereoTypeDeclarations) {
+ IStereotype stereotype = stereotypeDeclaration.getStereotype();
+ IScope stereotypeScope = stereotype.getScope();
+ if (stereotypeScope != null &&
!scopeTypeName.equals(stereotypeScope.getSourceType().getFullyQualifiedName())) {
+ return stereotypeDeclaration;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the scope annotation declaration if it exists in the bean. If the
+ * scope declared in a stereotype then returns this stereotype declaration.
+ * Returns null if there is not this scope declaration neither corresponding
+ * stereotype declaration.
+ *
+ * @param bean
+ * @param scopeTypeName
+ * @return
+ */
+ public static IAnnotationDeclaration getScopeDeclaration(IBean bean, String
scopeTypeName) {
+ IScope scope = bean.getScope();
+ if (scopeTypeName.equals(scope.getSourceType().getFullyQualifiedName())) {
+ Set<IScopeDeclaration> scopeDeclarations = bean.getScopeDeclarations();
+ for (IScopeDeclaration scopeDeclaration : scopeDeclarations) {
+ if
(scopeTypeName.equals(scopeDeclaration.getScope().getSourceType().getFullyQualifiedName()))
{
+ return scopeDeclaration;
+ }
+ }
+ Set<IStereotypeDeclaration> stereoTypeDeclarations =
bean.getStereotypeDeclarations();
+ for (IStereotypeDeclaration stereotypeDeclaration : stereoTypeDeclarations) {
+ IScope stereotypeScope = stereotypeDeclaration.getStereotype().getScope();
+ if (stereotypeScope != null &&
scopeTypeName.equals(stereotypeScope.getSourceType().getFullyQualifiedName())) {
+ return stereotypeDeclaration;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return @Named declaration or the stereotype declaration if it declares
+ *
+ * @Named.
+ *
+ * @param stereotyped
+ * @return
+ */
+ public static IAnnotationDeclaration getNamedDeclaration(IBean bean) {
+ IAnnotationDeclaration declaration =
bean.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if (declaration == null) {
+ return getNamedStereotypeDeclaration(bean);
+ }
+ return declaration;
+ }
+
+ /**
+ * Return the stereotype declaration which declares @Named.
+ *
+ * @param stereotyped
+ * @return
+ */
+ public static IAnnotationDeclaration getNamedStereotypeDeclaration(IStereotyped
stereotyped) {
+ Set<IStereotypeDeclaration> declarations =
stereotyped.getStereotypeDeclarations();
+ for (IStereotypeDeclaration declaration : declarations) {
+ if
(CDIConstants.NAMED_QUALIFIER_TYPE_NAME.equals(declaration.getType().getFullyQualifiedName())
+ || getNamedStereotypeDeclaration(declaration.getStereotype()) != null) {
+ return declaration;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns all found annotations for parameters of the method.
+ *
+ * @param method
+ * @param annotationTypeName
+ * @return
+ */
+ public static Set<ITextSourceReference> getAnnotationPossitions(IBeanMethod
method, String annotationTypeName) {
+ List<IParameter> params = method.getParameters();
+ Set<ITextSourceReference> declarations = new
HashSet<ITextSourceReference>();
+ for (IParameter param : params) {
+ ITextSourceReference declaration = param.getAnnotationPosition(annotationTypeName);
+ if (declaration != null) {
+ declarations.add(declaration);
+ }
+ }
+ return declarations;
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -28,6 +28,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
@@ -39,6 +40,7 @@
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.CDIUtil;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IBeanMethod;
@@ -59,7 +61,6 @@
import org.jboss.tools.cdi.core.ISessionBean;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
-import org.jboss.tools.cdi.core.IStereotyped;
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -311,6 +312,9 @@
private void validateClassBean(IClassBean bean) {
validateDisposers(bean);
+ if(!(bean instanceof ISessionBean)) {
+ validateManagedBean(bean);
+ }
}
private void validateDisposers(IClassBean bean) {
@@ -332,7 +336,7 @@
* - there are multiple disposer methods for a single producer method
*/
for (IBeanMethod disposerMethod : disposerMethods) {
- Set<ITextSourceReference> disposerDeclarations =
getAnnotationPossitions(disposerMethod, CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ Set<ITextSourceReference> disposerDeclarations =
CDIUtil.getAnnotationPossitions(disposerMethod,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
for (ITextSourceReference declaration : disposerDeclarations) {
addError(CDIValidationMessages.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER, declaration, bean.getResource());
}
@@ -446,18 +450,6 @@
}
}
- private Set<ITextSourceReference> getAnnotationPossitions(IBeanMethod method,
String annotationTypeName) {
- List<IParameter> params = method.getParameters();
- Set<ITextSourceReference> declarations = new
HashSet<ITextSourceReference>();
- for (IParameter param : params) {
- ITextSourceReference declaration = param.getAnnotationPosition(annotationTypeName);
- if(declaration!=null) {
- declarations.add(declaration);
- }
- }
- return declarations;
- }
-
/**
* If the method is not a static method and is not a business method of the session bean
and is observer or disposer then mark it as incorrect.
*
@@ -553,21 +545,13 @@
* - producer field with a parameterized type with a type variable declares any
scope other than @Dependent
*/
if(paramTypes.length>0) {
- IScope scope = producer.getScope();
- if(!CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName()))
{
- ITextSourceReference declaration = typeDeclaration;
- Set<IScopeDeclaration> decls = producer.getScopeDeclarations();
- for (IScopeDeclaration decl : decls) {
- if(decl.getParentMember().getResource().equals(producer.getResource())) {
- declaration = decl;
- break;
- }
- }
+ IAnnotationDeclaration scopeOrStereotypeDeclaration =
CDIUtil.getDifferentScopeDeclarationThanDepentend(producer);
+ if(scopeOrStereotypeDeclaration!=null) {
boolean field = producer instanceof IProducerField;
addError(
field?CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD:CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
field?CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD:CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
- declaration, producer.getResource());
+ scopeOrStereotypeDeclaration, producer.getResource());
}
}
}
@@ -722,6 +706,47 @@
}
}
+ private void validateManagedBean(IClassBean bean) {
+ /*
+ * 3.1. Managed beans
+ * - the bean class of a managed bean is annotated with both the @Interceptor and
@Decorator stereotypes
+ */
+ IAnnotationDeclaration decorator =
bean.getAnnotation(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME);
+ IAnnotationDeclaration interceptor =
bean.getAnnotation(CDIConstants.INTERCEPTOR_ANNOTATION_TYPE_NAME);
+ if(decorator!=null && interceptor!=null) {
+ addError(CDIValidationMessages.BOTH_INTERCEPTOR_AND_DECORATOR,
CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR, decorator, bean.getResource());
+ addError(CDIValidationMessages.BOTH_INTERCEPTOR_AND_DECORATOR,
CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR, interceptor, bean.getResource());
+ }
+
+ IAnnotationDeclaration declaration =
CDIUtil.getDifferentScopeDeclarationThanDepentend(bean);
+ if(declaration!=null) {
+ IType type = bean.getBeanClass();
+ try {
+ /*
+ * 3.1. Managed beans
+ * - managed bean with a public field declares any scope other than @Dependent
+ */
+ IField[] fields = type.getFields();
+ for (IField field : fields) {
+ if(Flags.isPublic(field.getFlags())) {
+ addError(CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD,
CDIPreferences.ILLEGAL_SCOPE_FOR_MANAGED_BEAN, declaration, bean.getResource());
+ break;
+ }
+ }
+ /*
+ * 3.1. Managed beans
+ * - managed bean with a parameterized bean class declares any scope other than
@Dependent
+ */
+ String[] typeVariables = type.getTypeParameterSignatures();
+ if(typeVariables.length>0) {
+ addError(CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_GENERIC_TYPE,
CDIPreferences.ILLEGAL_SCOPE_FOR_MANAGED_BEAN, declaration, bean.getResource());
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+ }
+
private void validateInterceptor(IInterceptor interceptor) {
/*
* 2.5.3. Beans with no EL name
@@ -733,7 +758,7 @@
declaration =
interceptor.getAnnotation(CDIConstants.INTERCEPTOR_ANNOTATION_TYPE_NAME);
}
if(declaration==null) {
- declaration = getNamedStereotypeDeclaration(interceptor);
+ declaration = CDIUtil.getNamedStereotypeDeclaration(interceptor);
}
addError(CDIValidationMessages.INTERCEPTOR_HAS_NAME,
CDIPreferences.INTERCEPTOR_HAS_NAME, declaration, interceptor.getResource());
}
@@ -742,8 +767,11 @@
* 2.6.1. Declaring an alternative
* - interceptor is an alternative (Non-Portable behavior)
*/
- ITextSourceReference declaration = interceptor.getAlternativeDeclaration();
- if(declaration!=null) {
+ if(interceptor.isAlternative()) {
+ ITextSourceReference declaration = interceptor.getAlternativeDeclaration();
+ if(declaration==null) {
+ declaration = interceptor.getInterceptorAnnotation();
+ }
addError(CDIValidationMessages.INTERCEPTOR_IS_ALTERNATIVE,
CDIPreferences.INTERCEPTOR_OR_DECORATOR_IS_ALTERNATIVE, declaration,
interceptor.getResource());
}
}
@@ -759,7 +787,7 @@
declaration = decorator.getAnnotation(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME);
}
if(declaration==null) {
- declaration = getNamedStereotypeDeclaration(decorator);
+ declaration = CDIUtil.getNamedStereotypeDeclaration(decorator);
}
addError(CDIValidationMessages.DECORATOR_HAS_NAME, CDIPreferences.DECORATOR_HAS_NAME,
declaration, decorator.getResource());
}
@@ -768,23 +796,15 @@
* 2.6.1. Declaring an alternative
* - decorator is an alternative (Non-Portable behavior)
*/
- ITextSourceReference declaration = decorator.getAlternativeDeclaration();
- if(declaration!=null) {
+ if(decorator.isAlternative()) {
+ ITextSourceReference declaration = decorator.getAlternativeDeclaration();
+ if(declaration==null) {
+ declaration = decorator.getDecoratorAnnotation();
+ }
addError(CDIValidationMessages.DECORATOR_IS_ALTERNATIVE,
CDIPreferences.INTERCEPTOR_OR_DECORATOR_IS_ALTERNATIVE, declaration,
decorator.getResource());
}
}
- private IAnnotationDeclaration getNamedStereotypeDeclaration(IStereotyped stereotyped)
{
- Set<IStereotypeDeclaration> declarations =
stereotyped.getStereotypeDeclarations();
- for (IStereotypeDeclaration declaration : declarations) {
- if(CDIConstants.NAMED_QUALIFIER_TYPE_NAME.equals(declaration.getType().getFullyQualifiedName())
||
- getNamedStereotypeDeclaration(declaration.getStereotype())!=null) {
- return declaration;
- }
- }
- return null;
- }
-
/*
* 2.2.2. Restricting the bean types of a bean
* - bean class or producer method or field specifies a @Typed annotation,
@@ -853,28 +873,15 @@
boolean interceptor = bean instanceof IInterceptor;
boolean decorator = bean instanceof IDecorator;
if(interceptor || decorator) {
- IScope scope = bean.getScope();
- if(!CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName()))
{
- String key;
- String message;
- ITextSourceReference declaration = null;
- if(!scopes.isEmpty()) {
- declaration = scopes.iterator().next();
- }
+ IAnnotationDeclaration scopeOrStereotypeDeclaration =
CDIUtil.getDifferentScopeDeclarationThanDepentend(bean);
+ if(scopeOrStereotypeDeclaration!=null) {
+ String key = CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR;
+ String message = CDIValidationMessages.ILLEGAL_SCOPE_FOR_DECORATOR;
if(interceptor) {
key = CDIPreferences.ILLEGAL_SCOPE_FOR_INTERCEPTOR;
message = CDIValidationMessages.ILLEGAL_SCOPE_FOR_INTERCEPTOR;
- if(declaration==null) {
- declaration = ((IInterceptor)bean).getInterceptorAnnotation();
- }
- } else {
- key = CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR;
- message = CDIValidationMessages.ILLEGAL_SCOPE_FOR_DECORATOR;
- if(declaration==null) {
- declaration = ((IDecorator)bean).getDecoratorAnnotation();
- }
}
- addError(message, key, declaration, bean.getResource());
+ addError(message, key, scopeOrStereotypeDeclaration, bean.getResource());
}
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -41,7 +41,8 @@
public static String MULTIPLE_SCOPE_TYPE_ANNOTATIONS;
public static String MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE;
public static String STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE;
- public static String ILLEGAL_SCOPE_FOR_MANAGED_BEAN;
+ public static String ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD;
+ public static String ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_GENERIC_TYPE;
public static String ILLEGAL_SCOPE_FOR_SESSION_BEAN;
public static String ILLEGAL_SCOPE_FOR_PRODUCER_METHOD;
public static String ILLEGAL_SCOPE_FOR_PRODUCER_FIELD;
@@ -68,6 +69,7 @@
public static String ILLEGAL_CONDITIONAL_OBSERVER;
public static String BOTH_INTERCEPTOR_AND_DECORATOR;
+ public static String SESSION_BEAN_ANNOTATED_INTERCEPTOR_OR_DECORATOR;
public static String PRODUCER_IN_INTERCEPTOR;
public static String PRODUCER_IN_DECORATOR;
public static String DISPOSER_IN_INTERCEPTOR;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-12
14:34:08 UTC (rev 22038)
@@ -29,16 +29,17 @@
- stereotype declares any other qualifier annotation
- stereotype is annotated @Typed
-
-
-
-
3.1. Managed beans
- the bean class of a managed bean is annotated with both
the @Interceptor and @Decorator stereotypes
- managed bean with a public field declares any scope other than @Dependent
- managed bean with a parameterized bean class declares any scope other than @Dependent
+
+
+
+
+
3.1.4. Specializing a managed bean
- managed bean class annotated @Specializes does not directly extend
the bean class of another managed bean
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-05-12
14:34:08 UTC (rev 22038)
@@ -20,7 +20,8 @@
MULTIPLE_SCOPE_TYPE_ANNOTATIONS=Bean class or producer method or field specifies multiple
scope type annotations
MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE=Bean does not explicitly declare a scope
when there is no default scope
STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE=Stereotype declares more than one scope
-ILLEGAL_SCOPE_FOR_MANAGED_BEAN=Managed bean with a public field or a parameterized bean
class declares any scope other than @Dependent
+ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD=Managed bean with a public field
declares any scope other than @Dependent
+ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_GENERIC_TYPE=Managed bean with a parameterized bean
class declares any scope other than @Dependent
ILLEGAL_SCOPE_FOR_SESSION_BEAN=Session bean specifies an illegal scope (a stateless
session bean must belong to the @Dependent pseudo-scope; a singleton bean must belong to
either the @ApplicationScoped scope or to the @Dependent pseudo-scope, a stateful session
bean may have any scope)
ILLEGAL_SCOPE_FOR_PRODUCER_METHOD=Producer method with a parameterized return type with a
type variable declares any scope other than @Dependent
ILLEGAL_SCOPE_FOR_PRODUCER_FIELD=Producer field with a parameterized type with a type
variable declares any scope other than @Dependent
@@ -46,7 +47,7 @@
ILLEGAL_OBSERVER_IN_SESSION_BEAN=Non-static method of a session bean class has a
parameter annotated @Observes, and the method is not a business method of the EJB
ILLEGAL_CONDITIONAL_OBSERVER=Bean with scope @Dependent has an observer method declared
receive=IF_EXISTS
-BOTH_INTERCEPTOR_AND_DECORATOR=the bean class of a managed bean is annotated with both
the @Interceptor and @Decorator stereotypes
+BOTH_INTERCEPTOR_AND_DECORATOR=The bean class of a managed bean is annotated with both
the @Interceptor and @Decorator stereotypes
SESSION_BEAN_ANNOTATED_INTERCEPTOR_OR_DECORATOR=Bean class of a session bean is annotated
@Interceptor or @Decorator
PRODUCER_IN_INTERCEPTOR=Interceptor has a member annotated @Produces
PRODUCER_IN_OR_DECORATOR=Decorator has a member annotated @Produces
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -62,7 +62,7 @@
{CDIPreferences.MULTIPLE_SCOPE_TYPE_ANNOTATIONS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleScopeTypeAnnotations_label},
{CDIPreferences.MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_missingScopeWhenThereIsNoDefaultScope_label},
{CDIPreferences.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_stereotypeDeclaresMoreThanOneScope_label},
-// {CDIPreferences.ILLEGAL_SCOPE_FOR_MANAGED_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForManagedBean_label},
+ {CDIPreferences.ILLEGAL_SCOPE_FOR_MANAGED_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForManagedBean_label},
// {CDIPreferences.ILLEGAL_SCOPE_FOR_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForSessionBean_label},
{CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForProducerMethod_label},
{CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForProducerField_label},
@@ -100,7 +100,7 @@
private static SectionDescription SECTION_INTERCEPTOR = new SectionDescription(
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_interceptor_and_decorator,
new String[][]{
-// {CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_bothInterceptorAndDecorator_label},
+ {CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_bothInterceptorAndDecorator_label},
// {CDIPreferences.SESSION_BEAN_ANNOTATED_INTERCEPTOR_OR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_sessionBeanAnnotatedInterceptorOrDecorator_label},
// {CDIPreferences.PRODUCER_IN_INTERCEPTOR_OR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerInInterceptorOrDecorator_label},
{CDIPreferences.DISPOSER_IN_INTERCEPTOR_OR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_disposerInInterceptorOrDecorator_label},
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeInterceptorBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeInterceptorBroken.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeInterceptorBroken.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -1,12 +1,11 @@
package org.jboss.jsr299.tck.tests.jbt.validation.interceptors;
-import javax.enterprise.inject.Alternative;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Interceptor
-@Alternative
+@AlternativeStereotype
public class AlternativeInterceptorBroken {
@AroundInvoke
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeStereotype.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeStereotype.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeStereotype.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.interceptors;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Stereotype;
+
+@Stereotype
+@Target( { TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+@Inherited
+@Alternative
+@interface AlternativeStereotype {
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/AlternativeStereotype.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-12
14:31:35 UTC (rev 22037)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-12
14:34:08 UTC (rev 22038)
@@ -43,7 +43,7 @@
*/
public void testInterceptorWithWrongScope() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_INTERCEPTOR, 7);
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_INTERCEPTOR, 8);
}
/**
@@ -118,7 +118,7 @@
*/
public void testAlternativeInterceptor() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/AlternativeInterceptorBroken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_IS_ALTERNATIVE,
9);
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_IS_ALTERNATIVE,
7);
}
/**
@@ -185,6 +185,39 @@
}
/**
+ * 3.1. Managed beans
+ * - the bean class of a managed bean is annotated with both the @Interceptor and
@Decorator stereotypes
+ *
+ * @throws Exception
+ */
+ public void testInterceptorCanNotAlsoBeDecorator() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/interceptors/definition/broken/interceptorCanNotBeDecorator/InterceptingDecorator.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.BOTH_INTERCEPTOR_AND_DECORATOR, 24, 25);
+ }
+
+ /**
+ * 3.1. Managed beans
+ * - managed bean with a public field declares any scope other than @Dependent
+ *
+ * @throws Exception
+ */
+ public void testNonDependentScopedBeanCanNotHavePublicField() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/simple/definition/dependentWithPublicField/Leopard_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD, 21);
+ }
+
+ /**
+ * 3.1. Managed beans
+ * - managed bean with a parameterized bean class declares any scope other than
@Dependent
+ *
+ * @throws Exception
+ */
+ public void testNonDependentGenericManagedBeanNotOk() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/genericbroken/FooBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_GENERIC_TYPE, 21);
+ }
+
+ /**
* 3.5.1. Declaring a resource
* - producer field declaration specifies an EL name (together with one of @Resource,
@PersistenceContext, @PersistenceUnit, @EJB, @WebServiceRef)
*
@@ -368,10 +401,10 @@
*/
public void testParameterizedReturnTypeWithWrongScope() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 25, 41);
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 25, 39);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 21);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 35);
- AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 32);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 31);
}
/**
@@ -382,7 +415,7 @@
*/
public void testParameterizedTypeWithWrongScope() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 11, 19);
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 11, 18);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 9);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 14);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 16);