Author: akazakov
Date: 2010-07-02 15:32:56 -0400 (Fri, 02 Jul 2010)
New Revision: 23204
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.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/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/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added new validation rule: bean with scope
@Dependent has an observer method declared notifyObserver=IF_EXISTS
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-07-02
19:32:56 UTC (rev 23204)
@@ -46,5 +46,6 @@
defaultPreferences.put(CDIPreferences.INJECTED_INTERCEPTOR, CDIPreferences.WARNING);
defaultPreferences.put(CDIPreferences.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING,
CDIPreferences.WARNING);
defaultPreferences.put(CDIPreferences.MISSING_NONBINDING_IN_INTERCEPTOR_BINDING_TYPE_MEMBER,
CDIPreferences.WARNING);
+ defaultPreferences.put(CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferences.WARNING);
}
}
\ 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-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-02
19:32:56 UTC (rev 23204)
@@ -30,9 +30,11 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
@@ -543,6 +545,29 @@
ITextSourceReference declaration =
param.getAnnotationPosition(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME);
if (declaration != null) {
declarations.add(declaration);
+
+ /*
+ * 10.4.2. Declaring an observer method
+ * - bean with scope @Dependent has an observer method declared
notifyObserver=IF_EXISTS
+ */
+ if(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(bean.getScope().getSourceType().getFullyQualifiedName()))
{
+ ICompilationUnit unit = observer.getMethod().getCompilationUnit();
+ if(unit!=null) {
+ try {
+ String source = unit.getSource();
+ ISourceRange unitRange = unit.getSourceRange();
+ int start = declaration.getStartPosition() - unitRange.getOffset();
+ int end = start + declaration.getLength();
+ int position = source.substring(start, end).indexOf("IF_EXISTS");
+ // TODO Shecks if IF_EXISTS as a string. But this string may be in a comment then
we will show incorrect error message.
+ if(position>11) {
+ addError(CDIValidationMessages.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER, declaration, bean.getResource());
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+ }
}
}
/*
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-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-07-02
19:32:56 UTC (rev 23204)
@@ -187,7 +187,7 @@
10.4.3. Conditional observer methods
-- bean with scope @Dependent has an observer method declared receive=IF_EXISTS
+- bean with scope @Dependent has an observer method declared notifyObserver=IF_EXISTS
12.1. Bean archives
- bean class is deployed in two different bean archives (Non-Portable behavior)
\ No newline at end of file
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-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-07-02
19:32:56 UTC (rev 23204)
@@ -55,7 +55,7 @@
STATIC_METHOD_ANNOTATED_INJECT=Static method of a bean is annotated @Inject
MULTIPLE_OBSERVING_PARAMETERS=Method has more than one parameter annotated @Observes
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
+ILLEGAL_CONDITIONAL_OBSERVER=Beans with scope @Dependent may not have conditional
observer methods [JSR-299 �10.4.3]
BOTH_INTERCEPTOR_AND_DECORATOR=The bean class of a managed bean is annotated with both
the @Interceptor and @Decorator stereotypes
SESSION_BEAN_ANNOTATED_INTERCEPTOR=Bean class of a session bean is annotated
@Interceptor
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-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-07-02
19:32:56 UTC (rev 23204)
@@ -95,7 +95,7 @@
{CDIPreferences.GENERIC_METHOD_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_genericMethodAnnotatedInject_label},
{CDIPreferences.MULTIPLE_OBSERVING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleObservingParameters_label},
{CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalObserverInSessionBean_label},
-// {CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalConditionalObserver_label},
+ {CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalConditionalObserver_label},
},
CDICorePlugin.PLUGIN_ID
);
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-07-02
19:20:11 UTC (rev 23203)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-07-02
19:32:56 UTC (rev 23204)
@@ -1389,6 +1389,17 @@
assertMarkerIsCreated(file, CDIValidationMessages.OBSERVER_IN_DECORATOR, 14);
}
+ /**
+ * 10.4.3. Conditional observer methods
+ * - bean with scope @Dependent has an observer method declared
notifyObserver=IF_EXISTS
+ *
+ * @throws Exception
+ */
+ public void testDependentBeanWithConditionalObserverMethodIsDefinitionError() throws
Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/event/broken/observer/dependentIsConditionalObserver/AlarmSystem.java");
+ assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_CONDITIONAL_OBSERVER, 24);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}