Author: akazakov
Date: 2010-02-10 16:44:01 -0500 (Wed, 10 Feb 2010)
New Revision: 20230
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.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.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
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-02-10
20:28:46 UTC (rev 20229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-02-10
21:44:01 UTC (rev 20230)
@@ -11,8 +11,10 @@
package org.jboss.tools.cdi.internal.core.validation;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -37,8 +39,10 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.IScopeDeclaration;
import org.jboss.tools.cdi.core.IStereotype;
+import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -235,11 +239,28 @@
if(reporter.isCancelled()) {
return;
}
+ // Collect all relations between the bean and other CDI elements.
String name = bean.getName();
if(name!=null) {
validationContext.addVariableNameForELValidation(name);
}
+ String beanPath = bean.getResource().getFullPath().toOSString();
+ Set<IScopeDeclaration> scopeDeclarations = bean.getScopeDeclarations();
+ for (IScopeDeclaration scopeDeclaration : scopeDeclarations) {
+ IScope scope = scopeDeclaration.getScope();
+ if(!scope.getSourceType().isReadOnly()) {
+ validationContext.addLinkedCoreResource(beanPath, scope.getResource().getFullPath(),
false);
+ }
+ }
+ Set<IStereotypeDeclaration> stereotypeDeclarations =
bean.getStereotypeDeclarations();
+ for (IStereotypeDeclaration stereotypeDeclaration : stereotypeDeclarations) {
+ IStereotype stereotype = stereotypeDeclaration.getStereotype();
+ if(!stereotype.getSourceType().isReadOnly()) {
+ validationContext.addLinkedCoreResource(beanPath,
stereotype.getResource().getFullPath(), false);
+ }
+ }
+ // validate
validateTyped(bean);
validateBeanScope(bean);
@@ -274,29 +295,51 @@
}
}
- /*
- * 2.4.3. Declaring the bean scope
- * - bean class or producer method or field specifies multiple scope type
annotations
- */
private void validateBeanScope(IBean bean) {
Set<IScopeDeclaration> scopes = bean.getScopeDeclarations();
+ // 2.4.3. Declaring the bean scope
+ // - bean class or producer method or field specifies multiple scope type
annotations
+ //
if(scopes.size()>1) {
for (IScopeDeclaration scope : scopes) {
addError(CDIValidationMessages.MULTIPLE_SCOPE_TYPE_ANNOTATIONS,
CDIPreferences.MULTIPLE_SCOPE_TYPE_ANNOTATIONS, scope, bean.getResource());
}
}
+
+ // 2.4.4. Default scope
+ // - bean does not explicitly declare a scope when there is no default scope
+ // (there are two different stereotypes declared by the bean that declare
different default scopes)
+ //
+ // Such bean definitions are invalid because they declares two stereotypes that
have different default scopes and the bean does not explictly define a scope to resolve
the conflict.
+ Set<IStereotypeDeclaration> stereotypeDeclarations =
bean.getStereotypeDeclarations();
+ if(!stereotypeDeclarations.isEmpty() && scopes.isEmpty()) {
+ Map<String, IStereotypeDeclaration> declarationMap = new HashMap<String,
IStereotypeDeclaration>();
+ for (IStereotypeDeclaration stereotypeDeclaration : stereotypeDeclarations) {
+ IStereotype stereotype = stereotypeDeclaration.getStereotype();
+ IScope scope = stereotype.getScope();
+ if(scope!=null) {
+ declarationMap.put(scope.getSourceType().getFullyQualifiedName(),
stereotypeDeclaration);
+ }
+ }
+ if(declarationMap.size()>1) {
+ for (IStereotypeDeclaration stereotypeDeclaration : declarationMap.values()) {
+ addError(CDIValidationMessages.MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE,
CDIPreferences.MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE, stereotypeDeclaration,
bean.getResource());
+ }
+ }
+ }
}
/**
* Validates a stereotype.
- * 2.7.1.3. Declaring a @Named stereotype
- * - stereotype declares a non-empty @Named annotation (Non-Portable behavior)
- * - stereotype declares any other qualifier annotation
- * - stereotype is annotated @Typed
*
* @param type
*/
private void validateStereotype(IStereotype stereotype) {
+ // 2.7.1.3. Declaring a @Named stereotype
+ // - stereotype declares a non-empty @Named annotation (Non-Portable
behavior)
+ // - stereotype declares any other qualifier annotation
+ // - stereotype is annotated @Typed
+
if(stereotype == null) {
return;
}
@@ -307,7 +350,7 @@
}
List<IAnnotationDeclaration> as = stereotype.getAnnotationDeclarations();
-// 1. non-empty name
+ // 1. non-empty name
IAnnotationDeclaration nameDeclaration = stereotype.getNameDeclaration();
if(nameDeclaration != null) {
IMemberValuePair[] ps = null;
@@ -325,19 +368,28 @@
}
}
-// 2. typed annotation
+ // 2. typed annotation
IAnnotationDeclaration typedDeclaration =
stereotype.getAnnotationDeclaration(CDIConstants.TYPED_ANNOTATION_TYPE_NAME);
if(typedDeclaration != null) {
ITextSourceReference location = typedDeclaration;
addError(CDIValidationMessages.STEREOTYPE_IS_ANNOTATED_TYPED,
CDIPreferences.STEREOTYPE_IS_ANNOTATED_TYPED, location, resource);
}
-// 3. Qualifier other than @Named
+ // 3. Qualifier other than @Named
for (IAnnotationDeclaration a: as) {
if(a instanceof IQualifierDeclaration && a != nameDeclaration) {
ITextSourceReference location = a;
addError(CDIValidationMessages.ILLEGAL_QUALIFIER_IN_STEREOTYPE,
CDIPreferences.ILLEGAL_QUALIFIER_IN_STEREOTYPE, location, resource);
}
}
+
+ // 2.7.1.1. Declaring the default scope for a stereotype
+ // - stereotype declares more than one scope
+ Set<IScopeDeclaration> scopeDeclarations = stereotype.getScopeDeclarations();
+ if(scopeDeclarations.size()>1) {
+ for (IScopeDeclaration scope : scopeDeclarations) {
+ addError(CDIValidationMessages.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE,
CDIPreferences.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE, scope, stereotype.getResource());
+ }
+ }
}
}
\ No newline at end of file
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-02-10
20:28:46 UTC (rev 20229)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-02-10
21:44:01 UTC (rev 20230)
@@ -59,8 +59,8 @@
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_scope,
new String[][]{
{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.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_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForSessionBean_label},
// {CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForProducerMethod_label},
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-02-10
20:28:46 UTC (rev 20229)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-02-10
21:44:01 UTC (rev 20230)
@@ -66,10 +66,23 @@
}
/*
+ * 2.7.1.1. Declaring the default scope for a stereotype
+ * - stereotype declares more than one scope
+ */
+ public void testStereotypeScope() throws Exception {
+ IProject p = importPreparedProject("/definition/stereotype");
+ IFile file =
p.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/tooManyScopes/StereotypeWithTooManyScopeTypes_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Stereotype declares more than one
scope", 16, 17);
+ int markerNumbers = getMarkersNumber(file);
+ assertEquals("StereotypeWithTooManyScopeTypes_Broken.java should has two error
markers.", markerNumbers, 2);
+ cleanProject("/definition/stereotype");
+ }
+
+ /*
* 2.4.3. Declaring the bean scope
* - bean class or producer method or field specifies multiple scope type
annotations
*/
- public void testBeanScope() throws Exception {
+ public void testMultipleBeanScope() throws Exception {
IProject p = importPreparedProject("/definition/scope");
IFile file =
p.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/scope/broken/tooManyScopes/BeanWithTooManyScopeTypes_Broken.java");
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Bean class or producer method or field
specifies multiple scope type annotations", 6, 7);
@@ -78,6 +91,20 @@
cleanProject("/definition/scope");
}
+ /*
+ * 2.4.4. Default scope
+ * - bean does not explicitly declare a scope when there is no default scope
+ * (there are two different stereotypes declared by the bean that declare
different default scopes)
+ */
+ public void testBeanWithMultipleScopedStereotypes() throws Exception {
+ IProject p = importPreparedProject("/definition/stereotype");
+ IFile file =
p.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/scopeConflict/Scallop_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Bean does not explicitly declare a scope
when there is no default scope", 8, 9);
+ int markerNumbers = getMarkersNumber(file);
+ assertEquals("Scallop_Broken.java should has two error markers.",
markerNumbers, 2);
+ cleanProject("/definition/stereotype");
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}