Author: scabanovich
Date: 2012-08-14 19:33:07 -0400 (Tue, 14 Aug 2012)
New Revision: 43034
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.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/ProducerMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
JBIDE-12423
https://issues.jboss.org/browse/JBIDE-12423
Specializing beans are stored in map by class name to exclude storing several beans while
as-you-type model is refreshed.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java 2012-08-14
18:11:35 UTC (rev 43033)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java 2012-08-14
23:33:07 UTC (rev 43034)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
+import java.util.Collection;
import java.util.Set;
import org.jboss.tools.common.java.IJavaReference;
@@ -61,7 +62,7 @@
*
* @return all the directly derived classes that declare annotation @Specializes
*/
- Set<? extends IClassBean> getSpecializingBeans();
+ Collection<? extends IClassBean> getSpecializingBeans();
/**
* Returns class bean of super class of this bean, or null if it is not a bean.
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 2012-08-14
18:11:35 UTC (rev 43033)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2012-08-14
23:33:07 UTC (rev 43034)
@@ -11,9 +11,11 @@
package org.jboss.tools.cdi.internal.core.impl;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -60,7 +62,7 @@
*/
public class ClassBean extends AbstractBeanElement implements IClassBean {
protected ClassBean superClassBean = null;
- protected Set<ClassBean> specializingClassBeans = new HashSet<ClassBean>();
+ protected Map<String, ClassBean> specializingClassBeans = new HashMap<String,
ClassBean>();
protected List<BeanField> fields = new ArrayList<BeanField>();
protected List<BeanMethod> methods = new ArrayList<BeanMethod>();
@@ -210,8 +212,11 @@
return result;
}
- void addSpecializingClassBean(ClassBean bean) {
- specializingClassBeans.add(bean);
+ synchronized void addSpecializingClassBean(ClassBean bean) {
+ if(specializingClassBeans == null) {
+ specializingClassBeans = new Hashtable<String, ClassBean>();
+ }
+ specializingClassBeans.put(bean.getBeanClass().getFullyQualifiedName(), bean);
}
public ClassBean getSuperClassBean() {
@@ -403,8 +408,8 @@
return superClassBean;
}
- public Set<ClassBean> getSpecializingBeans() {
- return specializingClassBeans;
+ public synchronized Collection<ClassBean> getSpecializingBeans() {
+ return specializingClassBeans == null ? Collections.<ClassBean>emptySet() :
specializingClassBeans.values();
}
public IAnnotationDeclaration getSpecializesAnnotationDeclaration() {
@@ -416,9 +421,11 @@
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;
+ synchronized boolean hasEnabledSpecializingClassBean() {
+ if(specializingClassBeans != null) {
+ for (ClassBean sb: specializingClassBeans.values()) {
+ if(sb.hasEnabledSpecializingClassBean() || sb.isEnabled()) return true;
+ }
}
return false;
}
@@ -627,8 +634,8 @@
return getSourceMember();
}
- public void cleanCache() {
- specializingClassBeans.clear();
+ public synchronized void cleanCache() {
+ specializingClassBeans = null;
scope = null;
}
}
\ No newline at end of file
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 2012-08-14
18:11:35 UTC (rev 43033)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2012-08-14
23:33:07 UTC (rev 43034)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.core.IType;
@@ -41,7 +43,7 @@
protected AnnotationDeclaration produces;
ProducerMethod specialized = null;
- Set<ProducerMethod> specializingProducerMethods = new
HashSet<ProducerMethod>();
+ Map<String, ProducerMethod> specializingProducerMethods = null;
public ProducerMethod() {}
@@ -143,7 +145,12 @@
public void setSpecializedBean(ProducerMethod other) {
specialized = other;
if(other != null) {
- other.specializingProducerMethods.add(this);
+ synchronized (other) {
+ if(other.specializingProducerMethods == null) {
+ other.specializingProducerMethods = new HashMap<String, ProducerMethod>();
+ }
+ other.specializingProducerMethods.put(this.getBeanClass().getFullyQualifiedName(),
this);
+ }
}
}
@@ -163,9 +170,11 @@
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;
+ synchronized boolean hasEnabledSpecializingProducerMethod() {
+ if(specializingProducerMethods != null) {
+ for (ProducerMethod sb: specializingProducerMethods.values()) {
+ if(sb.hasEnabledSpecializingProducerMethod() || sb.isEnabled()) return true;
+ }
}
return false;
}
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 2012-08-14
18:11:35 UTC (rev 43033)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2012-08-14
23:33:07 UTC (rev 43034)
@@ -979,7 +979,7 @@
*/
if(bean.isEnabled() && specializedBean instanceof IClassBean) {
IClassBean supperClassBean = (IClassBean)specializedBean;
- Set<? extends IClassBean> allSpecializingBeans =
supperClassBean.getSpecializingBeans();
+ Collection<? extends IClassBean> allSpecializingBeans =
supperClassBean.getSpecializingBeans();
if(allSpecializingBeans.size()>1) {
StringBuffer sb = new StringBuffer(bean.getElementName());
boolean moreThanTwo = false;