Author: scabanovich
Date: 2010-01-22 11:42:56 -0500 (Fri, 22 Jan 2010)
New Revision: 19888
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.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
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3125
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -26,7 +26,7 @@
*
* @return the required type of this injection point.
*/
- IType getType();
+ IParametedType getType();
/**
* Gets the required qualifiers of the injection point.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IParameter.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -33,7 +33,7 @@
*
* @return the declared type of this parameter.
*/
- IType getType();
+ IParametedType getType();
/**
* Returns the name of this parameter.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -19,6 +19,7 @@
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBeanMember;
import org.jboss.tools.cdi.core.IClassBean;
+import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.definition.BeanMemberDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
@@ -63,8 +64,8 @@
setParent(classBean);
}
- public IType getType() {
- return typeDeclaration == null ? null : typeDeclaration.getType();
+ public IParametedType getType() {
+ return typeDeclaration;
}
public int getLength() {
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-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -17,12 +17,15 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
@@ -33,6 +36,7 @@
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.core.IObserverMethod;
+import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
@@ -178,10 +182,108 @@
public Set<IBean> getBeans(IInjectionPoint injectionPoints) {
Set<IBean> result = new HashSet<IBean>();
- //TODO
+ IParametedType type = injectionPoints.getType();
+ if(type == null) {
+ return result;
+ }
+
+ Set<IAnnotationDeclaration> qs = injectionPoints.getQualifierDeclarations();
+
+ Set<IBean> beans = new HashSet<IBean>();
+ synchronized(allBeans) {
+ beans.addAll(allBeans);
+ }
+ for (IBean b: beans) {
+ Set<IParametedType> types = b.getLegalTypes();
+ if(containsType(types, type)) {
+ try {
+ Set<IAnnotationDeclaration> qsb = b.getQualifierDeclarations();
+ if(areMatchingQualifiers(qsb, qs)) {
+ result.add(b);
+ }
+ } catch (CoreException e) {
+
+ }
+ }
+ }
+
return result;
}
+ public static boolean containsType(Set<IParametedType> types, IParametedType type)
{
+ for (IParametedType t: types) {
+ if(t.equals(type)) return true;
+ }
+ return false;
+ }
+
+ public static boolean areMatchingQualifiers(Set<IAnnotationDeclaration>
beanQualifiers, Set<IAnnotationDeclaration> injectionQualifiers) throws
CoreException {
+ if(beanQualifiers == null || beanQualifiers.isEmpty()) {
+ if(injectionQualifiers == null || injectionQualifiers.isEmpty()) {
+ return true;
+ }
+ }
+
+ TreeSet<String> injectionKeys = new TreeSet<String>();
+ if(injectionQualifiers != null) for (IAnnotationDeclaration d: beanQualifiers) {
+ injectionKeys.add(getQualifierDeclarationKey(d));
+ }
+
+ if(injectionKeys.contains(CDIConstants.ANY_QUALIFIER_TYPE_NAME)) {
+ return true;
+ }
+ if(!injectionKeys.contains(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME)) {
+ injectionKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
+ }
+
+ TreeSet<String> beanKeys = new TreeSet<String>();
+ if(beanQualifiers == null || beanQualifiers.isEmpty()) {
+ beanKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
+ } else for (IAnnotationDeclaration d: beanQualifiers) {
+ beanKeys.add(getQualifierDeclarationKey(d));
+ }
+ if(beanKeys.size() == 1 &&
beanKeys.iterator().next().startsWith(CDIConstants.NAMED_QUALIFIER_TYPE_NAME)) {
+ beanKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
+ }
+
+ for(String k: injectionKeys) {
+ if(!beanKeys.contains(k)) return false;
+ }
+ return true;
+ }
+
+ static String getQualifierDeclarationKey(IAnnotationDeclaration d) throws CoreException
{
+ IType type = d.getType();
+ IMethod[] ms = type.getMethods();
+ StringBuffer result = new StringBuffer();
+ result.append(type.getFullyQualifiedName());
+ if(ms != null && ms.length > 0) {
+ TreeMap<String, String> values = new TreeMap<String, String>();
+ IMemberValuePair[] ps = d.getDeclaration().getMemberValuePairs();
+ if (ps != null) for (IMemberValuePair p: ps) {
+ String n = p.getMemberName();
+ Object o = p.getValue();
+ if(o != null) {
+ values.put(n, o.toString());
+ }
+ }
+ for (IMethod m: ms) {
+ String n = m.getElementName();
+ if(values.containsKey(n)) continue;
+ IMemberValuePair p = m.getDefaultValue();
+ n = p.getMemberName();
+ Object o = p.getValue();
+ if(values.containsKey(n) || o == null) continue;
+ values.put(n, o.toString());
+ }
+ for (String n: values.keySet()) {
+ String v = values.get(n);
+ result.append(';').append(n).append('=').append(v);
+ }
+ }
+ return result.toString();
+ }
+
public Set<IBean> getBeans(IPath path) {
Set<IBean> result = new HashSet<IBean>();
Set<IBean> beans = beansByPath.get(path);
@@ -408,7 +510,9 @@
StereotypeElement s = new StereotypeElement();
initAnnotationElement(s, d);
stereotypes.put(d.getQualifiedName(), s);
- stereotypesByPath.put(d.getResource().getFullPath(), s);
+ if(d.getResource() != null && d.getResource().getFullPath() != null) {
+ stereotypesByPath.put(d.getResource().getFullPath(), s);
+ }
} else if(d.getKind() == AnnotationDefinition.INTERCEPTOR_BINDING) {
InterceptorBindingElement s = new InterceptorBindingElement();
initAnnotationElement(s, d);
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-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
@@ -38,6 +39,7 @@
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.internal.core.impl.definition.FieldDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.MethodDefinition;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.common.model.project.ext.impl.ValueInfo;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -225,8 +227,43 @@
}
public Set<IParametedType> getLegalTypes() {
- // TODO
- return null;
+ Set<IParametedType> result = new HashSet<IParametedType>();
+ AnnotationDeclaration d = getDefinition().getTypedAnnotation();
+ if(d != null) {
+ try {
+ IMemberValuePair[] ps = d.getDeclaration().getMemberValuePairs();
+ if(ps != null) for (IMemberValuePair p: ps) {
+ Object o = p.getValue();
+ if(o instanceof Object[]) {
+ Object[] os = (Object[])o;
+ for (int i = 0; i < os.length; i++) {
+ String s = os[i].toString();
+ if(!s.endsWith(";")) s = "Q" + s + ";";
+ IParametedType t =
ParametedTypeFactory.getParametedType(getDefinition().getType(), s);
+ result.add(t);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ //TODO
+ }
+ }
+ IType type = getDefinition().getType();
+ if(type != null) {
+ ParametedType p = new ParametedType();
+ p.setType(type);
+ try {
+ String[] ps = type.getTypeParameterSignatures();
+ //TODO set parameters
+ p.setSignature(type.getFullyQualifiedName());
+ } catch (CoreException e) {
+ //TODO
+ }
+ result.add(p);
+ }
+ Set<IParametedType> inh = getDefinition().getInheritedTypes();
+ if(inh != null) result.addAll(inh);
+ return result;
}
public String getName() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -48,4 +48,14 @@
parameterTypes.add(p);
}
+ public boolean equals(Object object) {
+ if(!(object instanceof ParametedType)) return false;
+ ParametedType other = (ParametedType)object;
+ if(signature != null && signature.equals(other.signature)) {
+ return true;
+ }
+ //TODO
+ return false;
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -65,8 +65,9 @@
}
public Set<IParametedType> getLegalTypes() {
- // TODO
- return null;
+ Set<IParametedType> result = new HashSet<IParametedType>();
+ if(typeDeclaration != null) result.add(typeDeclaration);
+ return result;
}
public String getName() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-01-22
16:31:42 UTC (rev 19887)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-01-22
16:42:56 UTC (rev 19888)
@@ -75,8 +75,9 @@
}
public Set<IParametedType> getLegalTypes() {
- // TODO Auto-generated method stub
- return null;
+ Set<IParametedType> result = new HashSet<IParametedType>();
+ if(typeDeclaration != null) result.add(typeDeclaration);
+ return result;
}
public String getName() {