Author: scabanovich
Date: 2009-12-24 12:04:18 -0500 (Thu, 24 Dec 2009)
New Revision: 19578
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.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/ClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/DecoratorBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InterceptorBean.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-4943
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -24,6 +24,7 @@
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
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.internal.core.impl.definition.AbstractMemberDefinition;
@@ -61,6 +62,16 @@
return null;
}
+ public boolean isAlternative() {
+ if(getDefinition().getAlternativeAnnotation() != null) return true;
+ Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
+ for (IStereotypeDeclaration d: ds) {
+ IStereotype s = d.getStereotype();
+ if(s != null && s.isAlternative()) return true;
+ }
+ return false;
+ }
+
public Set<IStereotypeDeclaration> getStereotypeDeclarations() {
Set<IStereotypeDeclaration> result = new
HashSet<IStereotypeDeclaration>();
for (AnnotationDeclaration d: definition.getAnnotations()) {
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 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/BeanMember.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -58,8 +58,9 @@
return classBean;
}
- public void setClassBean(IClassBean classBean) {
+ public void setClassBean(ClassBean classBean) {
this.classBean = classBean;
+ setParent(classBean);
}
public IType getType() {
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 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -11,8 +11,10 @@
package org.jboss.tools.cdi.internal.core.impl;
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.jdt.core.IAnnotation;
@@ -71,7 +73,7 @@
bm = new BeanMethod();
}
bm.setDefinition(m);
- bm.setParent(this);
+ bm.setClassBean(this);
methods.add(bm);
}
List<FieldDefinition> fs = definition.getFields();
@@ -86,7 +88,7 @@
bf = new BeanField();
}
bf.setDefinition(f);
- bf.setParent(this);
+ bf.setClassBean(this);
fields.add(bf);
}
}
@@ -108,10 +110,43 @@
public void setSuperClassBean(ClassBean bean) {
superClassBean = bean;
if(superClassBean != null && isSpecializing()) {
- superClassBean.specializingClassBeans.add(this);
+ superClassBean.addSpecializingClassBean(this);
}
+ if(bean != null) {
+ Map<String, ProducerMethod> thisProducers = getProducerMethodsForSignatures();
+ Map<String, ProducerMethod> superProducers =
bean.getProducerMethodsForSignatures();
+ for (String s: thisProducers.keySet()) {
+ ProducerMethod thisProducer = thisProducers.get(s);
+ ProducerMethod superProducer = superProducers.get(s);
+ if(thisProducer != null && superProducer != null) {
+ if(thisProducer.getSpecializesAnnotationDeclaration() != null) {
+ thisProducer.setSpecializedBean(superProducer);
+ }
+ }
+ }
+ }
}
+ Map<String, ProducerMethod> getProducerMethodsForSignatures() {
+ Map<String, ProducerMethod> result = new HashMap<String,
ProducerMethod>();
+ for (BeanMethod b: methods) {
+ if(b instanceof ProducerMethod) {
+ String s = b.getMethod().getElementName();
+ try {
+ s += ":" + b.getMethod().getSignature();
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ result.put(s, (ProducerMethod)b);
+ }
+ }
+ return result;
+ }
+
+ void addSpecializingClassBean(ClassBean bean) {
+ specializingClassBeans.add(bean);
+ }
+
public ClassBean getSuperClassBean() {
return superClassBean;
}
@@ -245,31 +280,35 @@
return getDefinition().getSpecializesAnnotation();
}
- public boolean isAlternative() {
- if(getDefinition().getAlternativeAnnotation() != null) return true;
- Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
- for (IStereotypeDeclaration d: ds) {
- IStereotype s = d.getStereotype();
- if(s != null && s.isAlternative()) return true;
- }
- return false;
- }
-
public boolean isDependent() {
IScope scope = getScope();
return scope != null &&
CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName());
}
+ boolean hasEnabledSpecializingClassBean() {
+ for (ClassBean sb: specializingClassBeans) {
+ if(sb.hasEnabledSpecializingClassBean() || sb.isEnabled()) return true;
+ }
+ return false;
+ }
+
public boolean isEnabled() {
- if(!specializingClassBeans.isEmpty()) {
+ if(hasEnabledSpecializingClassBean()) {
return false;
}
- if(getDefinition().getAlternativeAnnotation() != null) {
- if(!getCDIProject().isClassAlternativeActivated(getDefinition().getQualifiedName()))
{
- return false;
+ if(isAlternative()) {
+ if(getCDIProject().isClassAlternativeActivated(getDefinition().getQualifiedName())) {
+ return true;
}
+ Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
+ for (IStereotypeDeclaration d: ds) {
+ IStereotype s = d.getStereotype();
+ if(s != null && s.isAlternative() &&
!getCDIProject().getAlternatives(s.getSourceType().getFullyQualifiedName()).isEmpty()) {
+ return true;
+ }
+ }
+ return false;
}
- // TODO
return true;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/DecoratorBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/DecoratorBean.java 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/DecoratorBean.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -33,4 +33,8 @@
return getDefinition().getDecoratorAnnotation();
}
+ public boolean isEnabled() {
+ return
!getCDIProject().getDecoratorClasses(getBeanClass().getFullyQualifiedName()).isEmpty();
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InterceptorBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InterceptorBean.java 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/InterceptorBean.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -26,4 +26,8 @@
return getDefinition().getInterceptorAnnotation();
}
+ public boolean isEnabled() {
+ return
!getCDIProject().getInterceptorClasses(getBeanClass().getFullyQualifiedName()).isEmpty();
+ }
+
}
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 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -107,22 +107,28 @@
return null;
}
- public boolean isAlternative() {
- if(getDefinition().getAlternativeAnnotation() != null) return true;
- Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
- for (IStereotypeDeclaration d: ds) {
- IStereotype s = d.getStereotype();
- if(s != null && s.isAlternative()) return true;
- }
- return false;
- }
-
public boolean isDependent() {
IScope scope = getScope();
return scope != null &&
CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName());
}
public boolean isEnabled() {
+ if(classBean != null && !classBean.isEnabled()) {
+ return false;
+ }
+ if(isAlternative()) {
+ if(classBean != null &&
!getCDIProject().getAlternatives(classBean.getBeanClass().getFullyQualifiedName()).isEmpty())
{
+ return true;
+ }
+ Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
+ for (IStereotypeDeclaration d: ds) {
+ IStereotype s = d.getStereotype();
+ if(s != null && s.isAlternative() &&
!getCDIProject().getAlternatives(s.getSourceType().getFullyQualifiedName()).isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
return true;
}
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 2009-12-24
16:41:41 UTC (rev 19577)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2009-12-24
17:04:18 UTC (rev 19578)
@@ -44,6 +44,9 @@
public class ProducerMethod extends BeanMethod implements IProducerMethod {
protected AnnotationDeclaration produces;
+ ProducerMethod specialized = null;
+ Set<ProducerMethod> specializingProducerMethods = new
HashSet<ProducerMethod>();
+
public ProducerMethod() {}
public void setDefinition(MethodDefinition definition) {
@@ -77,6 +80,10 @@
}
public String getName() {
+ ProducerMethod specialized = getSpecializedBean();
+ if(specialized != null) {
+ return specialized.getName();
+ }
AnnotationDeclaration named = findNamedAnnotation();
if(named == null) return null;
@@ -111,36 +118,56 @@
return null;
}
- public IBean getSpecializedBean() {
+ public void setSpecializedBean(ProducerMethod other) {
+ specialized = other;
+ if(other != null) {
+ other.specializingProducerMethods.add(this);
+ }
+ }
+
+ public ProducerMethod getSpecializedBean() {
if(getDefinition().getSpecializesAnnotation() == null) {
return null;
}
- //TODO find producer method in super type
-
- return null;
+ return specialized;
}
public IAnnotationDeclaration getSpecializesAnnotationDeclaration() {
return getDefinition().getSpecializesAnnotation();
}
- public boolean isAlternative() {
- if(getDefinition().getAlternativeAnnotation() != null) return true;
- Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
- for (IStereotypeDeclaration d: ds) {
- IStereotype s = d.getStereotype();
- if(s != null && s.isAlternative()) return true;
- }
- return false;
- }
-
public boolean isDependent() {
IScope scope = getScope();
return scope != null &&
CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName());
}
+ boolean hasEnabledSpecializingProducerMethod() {
+ for (ProducerMethod sb: specializingProducerMethods) {
+ if(sb.hasEnabledSpecializingProducerMethod() || sb.isEnabled()) return true;
+ }
+ return false;
+ }
+
public boolean isEnabled() {
- //if it is overrided by producer method which specializes it, return false!
+ if(classBean != null && !classBean.isEnabled()) {
+ return false;
+ }
+ if(hasEnabledSpecializingProducerMethod()) {
+ return false;
+ }
+ if(isAlternative()) {
+ if(classBean != null &&
!getCDIProject().getAlternatives(classBean.getBeanClass().getFullyQualifiedName()).isEmpty())
{
+ return true;
+ }
+ Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
+ for (IStereotypeDeclaration d: ds) {
+ IStereotype s = d.getStereotype();
+ if(s != null && s.isAlternative() &&
!getCDIProject().getAlternatives(s.getSourceType().getFullyQualifiedName()).isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
return true;
}