Author: scabanovich
Date: 2010-07-23 08:15:09 -0400 (Fri, 23 Jul 2010)
New Revision: 23699
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IObserverMethod.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/impl/ClassBean.java
Log:
https://jira.jboss.org/browse/JBIDE-3124
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-07-23
12:12:07 UTC (rev 23698)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-07-23
12:15:09 UTC (rev 23699)
@@ -73,4 +73,6 @@
public String PRE_DESTROY_TYPE_NAME = "javax.annotation.PreDestroy";
public String POST_CONSTRUCTOR_TYPE_NAME = "javax.annotation.PostConstruct";
+
+ public String EVENT_TYPE_NAME = "javax.enterprise.event.Event";
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IObserverMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IObserverMethod.java 2010-07-23
12:12:07 UTC (rev 23698)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IObserverMethod.java 2010-07-23
12:15:09 UTC (rev 23699)
@@ -20,9 +20,9 @@
public interface IObserverMethod extends IBeanMethod {
/**
- * Returns the set of @Observes annotations of parameters of this method.
+ * Returns the set of parameters of this method with @Observes annotation.
*
- * @return the set of @Observes annotations of parameters of this method
+ * @return the set of parameters of this method with @Observes annotation
*/
- Set<IAnnotationDeclaration> getObservesAnnotationDeclarations();
+ Set<IParameter> getObservedParameters();
}
\ No newline at end of file
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
12:12:07 UTC (rev 23698)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-07-23
12:15:09 UTC (rev 23699)
@@ -40,6 +40,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.IInjectionPointParameter;
import org.jboss.tools.cdi.core.IInterceptorBinding;
import org.jboss.tools.cdi.core.IObserverMethod;
import org.jboss.tools.cdi.core.IParametedType;
@@ -425,6 +426,33 @@
return true;
}
+ public static boolean areMatchingEventQualifiers(Set<IQualifierDeclaration>
eventQualifiers, IType... paramQualifiers) throws CoreException {
+ if(eventQualifiers == null || eventQualifiers.isEmpty()) {
+ if(paramQualifiers == null || paramQualifiers.length == 0) {
+ return true;
+ }
+ }
+
+ TreeSet<String> paramKeys = new TreeSet<String>();
+ if(paramQualifiers != null) for (IType d: paramQualifiers) {
+ paramKeys.add(d.getFullyQualifiedName());
+ }
+
+ TreeSet<String> eventKeys = new TreeSet<String>();
+ if(eventQualifiers != null) for (IAnnotationDeclaration d: eventQualifiers) {
+ eventKeys.add(d.getType().getFullyQualifiedName());
+ }
+
+ if(!eventKeys.contains(CDIConstants.ANY_QUALIFIER_TYPE_NAME)) {
+ eventKeys.add(CDIConstants.ANY_QUALIFIER_TYPE_NAME);
+ }
+
+ for(String k: paramKeys) {
+ if(!eventKeys.contains(k)) return false;
+ }
+ return true;
+ }
+
public static String getAnnotationDeclarationKey(IAnnotationDeclaration d) throws
CoreException {
ICDIAnnotation annotation = d.getAnnotation();
Set<IMethod> nb = annotation == null ? new HashSet<IMethod>() :
annotation.getNonBindingMethods();
@@ -682,10 +710,49 @@
return result;
}
- public Set<IObserverMethod> resolveObserverMethods(
- IInjectionPoint injectionPoint) {
- // TODO
- return new HashSet<IObserverMethod>();
+ 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())) {
+ 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();
+ for (IBeanMethod m: ms) {
+ if(m instanceof IObserverMethod) {
+ IObserverMethod om = (IObserverMethod)m;
+ Set<IParameter> params = om.getObservedParameters();
+ if(params.isEmpty()) continue;
+ IParameter param = params.iterator().next();
+ IParametedType paramType = param.getType();
+ 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());
+ }
+ try {
+ if(areMatchingEventQualifiers(injectionPoint.getQualifierDeclarations(),
paramQualifiers.toArray(new IType[0]))) {
+ result.add(om);
+ }
+ } catch (CoreException err) {
+ CDICorePlugin.getDefault().logError(err);
+ }
+ }
+ }
+ }
+
+ return result;
}
public Set<IBeanMethod> resolveDisposers(IProducerMethod producer) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-07-23
12:12:07 UTC (rev 23698)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-07-23
12:15:09 UTC (rev 23699)
@@ -74,8 +74,10 @@
bm = new ProducerMethod();
} else if(m.getInjectAnnotation() != null) {
bm = new InjectionPointMethod();
+ } else if(m.isObserver()) {
+ bm = new ObserverMethod();
} else {
- //add observer case
+ //add other cases
bm = new BeanMethod();
}
bm.setClassBean(this);
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java 2010-07-23
12:15:09 UTC (rev 23699)
@@ -0,0 +1,25 @@
+package org.jboss.tools.cdi.internal.core.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.IObserverMethod;
+import org.jboss.tools.cdi.core.IParameter;
+
+public class ObserverMethod extends BeanMethod implements IObserverMethod {
+
+ @Override
+ protected Parameter newParameter() {
+ return new InjectionPointParameter();
+ }
+
+ public Set<IParameter> getObservedParameters() {
+ Set<IParameter> result = new HashSet<IParameter>();
+ for (IParameter p: parameters) {
+ if(p.isAnnotationPresent(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME)) result.add(p);
+ }
+ return result;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ObserverMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain