Author: scabanovich
Date: 2010-07-23 10:19:15 -0400 (Fri, 23 Jul 2010)
New Revision: 23704
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
https://jira.jboss.org/browse/JBIDE-6701
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-07-23
14:11:14 UTC (rev 23703)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-07-23
14:19:15 UTC (rev 23704)
@@ -261,6 +261,16 @@
Set<IObserverMethod> resolveObserverMethods(IInjectionPoint injectionPoint);
/**
+ * Returns the set of injection points with event type observed by given
+ * parameter of an observer method.
+ *
+ * @param observedEventParameter
+ * @return the set of injection points with event type observed by given
+ * parameter of an observer method
+ */
+ public Set<IInjectionPoint> findObservedEvents(IInjectionPointParameter
observedEventParameter);
+
+ /**
* Applies the ambiguous dependency resolution rules to a set of beans.
*
* @param beans
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-07-23
14:11:14 UTC (rev 23703)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-07-23
14:19:15 UTC (rev 23704)
@@ -28,6 +28,7 @@
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
@@ -40,6 +41,7 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IInjectionPointField;
import org.jboss.tools.cdi.core.IInjectionPointParameter;
import org.jboss.tools.cdi.core.IInterceptorBinding;
import org.jboss.tools.cdi.core.IObserverMethod;
@@ -713,16 +715,11 @@
public Set<IObserverMethod> resolveObserverMethods(IInjectionPoint injectionPoint)
{
Set<IObserverMethod> result = new HashSet<IObserverMethod>();
- IParametedType t = injectionPoint.getType();
- if(t == null || t.getType() == null ||
!CDIConstants.EVENT_TYPE_NAME.equals(t.getType().getFullyQualifiedName())) {
+ IParametedType eventType = getEventType(injectionPoint.getType());
+
+ if(eventType == null) {
return result;
}
- List<? extends IParametedType> ps = t.getParameters();
- if(ps.isEmpty()) {
- return result;
- }
-
- IParametedType eventType = ps.get(0);
for (IClassBean b: classBeans.values()) {
Set<IBeanMethod> ms = b.getObserverMethods();
@@ -736,22 +733,67 @@
if(!((ParametedType)eventType).isAssignableTo((ParametedType)paramType, true)) {
continue;
}
- Set<IQualifier> qs = ((InjectionPointParameter)param).getQualifiers();
- List<IType> paramQualifiers = new ArrayList<IType>();
- for (IQualifier q: qs) {
- if(q.getSourceType() != null) paramQualifiers.add(q.getSourceType());
+ if(areMatchingEventQualifiers((InjectionPointParameter)param, injectionPoint)) {
+ result.add(om);
}
- try {
- if(areMatchingEventQualifiers(injectionPoint.getQualifierDeclarations(),
paramQualifiers.toArray(new IType[0]))) {
- result.add(om);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns type parameter of type javax.enterprise.event.Event<T>
+ * In all other cases returns null.
+ *
+ * @param t
+ * @return
+ */
+ private IParametedType getEventType(IParametedType t) {
+ if(t == null || t.getType() == null ||
!CDIConstants.EVENT_TYPE_NAME.equals(t.getType().getFullyQualifiedName())) {
+ return null;
+ }
+ List<? extends IParametedType> ps = t.getParameters();
+ return ps.isEmpty() ? null : ps.get(0);
+ }
+
+ private boolean areMatchingEventQualifiers(IInjectionPointParameter observerParam,
IInjectionPoint event) {
+ Set<IQualifier> qs = ((InjectionPointParameter)observerParam).getQualifiers();
+ List<IType> paramQualifiers = new ArrayList<IType>();
+ for (IQualifier q: qs) {
+ if(q.getSourceType() != null) paramQualifiers.add(q.getSourceType());
+ }
+ try {
+ if(areMatchingEventQualifiers(event.getQualifierDeclarations(),
paramQualifiers.toArray(new IType[0]))) {
+ return true;
+ }
+ } catch (CoreException err) {
+ CDICorePlugin.getDefault().logError(err);
+ }
+ return false;
+ }
+
+ public Set<IInjectionPoint> findObservedEvents(IInjectionPointParameter
observedEventParameter) {
+ Set<IInjectionPoint> result = new HashSet<IInjectionPoint>();
+
+ if(observedEventParameter.getBeanMethod() instanceof IObserverMethod) {
+ IParametedType paramType = observedEventParameter.getType();
+ for (IClassBean b: classBeans.values()) {
+ Set<IInjectionPoint> ps = b.getInjectionPoints();
+ for (IInjectionPoint p: ps) {
+ if(p instanceof IInjectionPointField) {
+ IParametedType eventType = getEventType(p.getType());
+ if(eventType != null &&
((ParametedType)eventType).isAssignableTo((ParametedType)paramType, true)) {
+ if(areMatchingEventQualifiers(observedEventParameter, p)) {
+ result.add(p);
+ }
}
- } catch (CoreException err) {
- CDICorePlugin.getDefault().logError(err);
}
}
}
}
-
+
return result;
}
@@ -895,6 +937,7 @@
QualifierElement s = new QualifierElement();
initAnnotationElement(s, d);
qualifiers.put(d.getQualifiedName(), s);
+ System.out.println(d.getQualifiedName());
if(d.getResource() != null && d.getResource().getFullPath() != null) {
qualifiersByPath.put(d.getResource().getFullPath(), s);
}
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-23
14:11:14 UTC (rev 23703)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-23
14:19:15 UTC (rev 23704)
@@ -1910,7 +1910,7 @@
private void validateQualifierAnnotationTypeAnnotations(IQualifier qualifier, IResource
resource) throws JavaModelException {
/*
- * Qualifier annotation type should be annotated with @Target({METHOD, FIELD,
PARAMETER, TYPE})
+ * Qualifier annotation type should be annotated with @Target({METHOD, FIELD,
PARAMETER, TYPE}) or @Target({"FIELD", "PARAMETER"})
* Qualifier annotation type should be annotated with @Retention(RUNTIME)
*/
IAnnotationDeclaration target =
qualifier.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
@@ -1918,9 +1918,14 @@
addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE,
CDIPreferences.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE,
CDIUtil.convertToSourceReference(qualifier.getSourceType().getNameRange()), resource);
} else {
Set<String> vs = getTargetAnnotationValues(target);
- boolean ok = vs.size() == 4;
- if(ok) for (String s: new String[]{"TYPE", "METHOD",
"FIELD", "PARAMETER"}) {
- if(!vs.contains(s)) ok = false;
+ boolean ok = vs.size() == 4 || vs.size() == 2;
+ if(ok) {
+ String[] values = (vs.size() == 4)
+ ? new String[]{"TYPE", "METHOD", "FIELD",
"PARAMETER"}
+ : new String[]{"FIELD", "PARAMETER"};
+ for (String s: values) {
+ if(!vs.contains(s)) ok = false;
+ }
}
if(!ok) {
addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE,
CDIPreferences.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, target, resource);