[jbosstools-commits] JBoss Tools SVN: r43139 - trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Aug 21 19:07:21 EDT 2012


Author: scabanovich
Date: 2012-08-21 19:07:21 -0400 (Tue, 21 Aug 2012)
New Revision: 43139

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/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/ProducerField.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
Log:
JBIDE-12417
https://issues.jboss.org/browse/JBIDE-12417


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	2012-08-21 23:02:53 UTC (rev 43138)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java	2012-08-21 23:07:21 UTC (rev 43139)
@@ -287,69 +287,43 @@
 	}
 
 	public Collection<ITypeDeclaration> getRestrictedTypeDeclarations(Collection<IParametedType> alltypes) {
+		AnnotationDeclaration typed = getDefinition().getTypedAnnotation();
+		if(typed == null) {
+			return new ArrayList<ITypeDeclaration>(0);
+		}
 		Map<String, IParametedType> map = new HashMap<String, IParametedType>();
 		for (IParametedType t: alltypes) {
 			map.put(t.getType().getFullyQualifiedName(), t);
 		}
 		Collection<ITypeDeclaration> result = new ArrayList<ITypeDeclaration>();
-		AnnotationDeclaration typed = getDefinition().getTypedAnnotation();
-		if(typed != null) {
-			int s = typed.getStartPosition();
-			int l = typed.getLength();
-			try {
-				String txt = null;
-				if(s >= 0 && typed.getResource() instanceof IFile) {
-					AbstractTypeDefinition td = getDefinition().getTypeDefinition();
-					if(getDefinition().getOriginalDefinition() != null) {
-						ITextSourceReference r = getDefinition().getOriginalDefinition();
-						String content = FileUtil.readStream((IFile)r.getResource());
-						if(content != null && content.length() > s + l) {
-							txt = content.substring(s);
-						}
-					} else if(td != null) {
-						String content = td.getContent();
-						if(content != null && content.length() > s + l) {
-							txt = content.substring(s, s + l);
-						}
-					}					
+		int s = typed.getStartPosition();
+		int l = typed.getLength();
+		try {
+			String txt = null;
+			if(s >= 0 && typed.getResource() instanceof IFile) {
+				AbstractTypeDefinition td = getDefinition().getTypeDefinition();
+				if(getDefinition().getOriginalDefinition() != null) {
+					ITextSourceReference r = getDefinition().getOriginalDefinition();
+					String content = FileUtil.readStream((IFile)r.getResource());
+					if(content != null && content.length() > s + l) {
+						txt = content.substring(s);
+					}
+				} else if(td != null) {
+					String content = td.getContent();
+					if(content != null && content.length() > s + l) {
+						txt = content.substring(s, s + l);
+					}
 				}
-				
-				Object value = typed.getMemberValue(null);
-				if(value == null) return result;
-				IMember member = (IMember)definition.getMember();
-				IType declaringType = member instanceof IType ? (IType)member : member.getDeclaringType();
-				if(value instanceof Object[]) {
-					Object[] os = (Object[])value;
-					for (int i = 0; i < os.length; i++) {
-						String rawTypeName = os[i].toString();
-						String typeName = rawTypeName;
-						if(!typeName.endsWith(";")) typeName = "Q" + typeName + ";";
-						ParametedType p = getCDIProject().getNature().getTypeFactory().getParametedType(declaringType, typeName);
-						if(p != null) {
-							int offset = 0;
-							int length = 0;
-							if(txt != null) {
-								int q = txt.indexOf(rawTypeName);
-								if(q >= 0) {
-									offset = s + q;
-									length = rawTypeName.length();
-								}
-							}
-							IParametedType other = p.getType() == null ? null : map.get(p.getType().getFullyQualifiedName());
-							if(other != null) {
-								String s1 = p.getSignature();
-								String s2 = other.getSignature();
-								if(!s1.equals(s2) && Signature.getArrayCount(s1) == Signature.getArrayCount(s2)) {
-									p.setSignature(s2);
-								}
-								result.add(new TypeDeclaration((ParametedType)other, typed.getResource(), offset, length));
-							} else {
-								result.add(new TypeDeclaration(p, typed.getResource(), offset, length));
-							}
-						}
-					}
-				} else if(value != null) {
-					String rawTypeName = value.toString();
+			}
+			
+			Object value = typed.getMemberValue(null);
+			if(value == null) return result;
+			IMember member = (IMember)definition.getMember();
+			IType declaringType = member instanceof IType ? (IType)member : member.getDeclaringType();
+			if(value instanceof Object[]) {
+				Object[] os = (Object[])value;
+				for (int i = 0; i < os.length; i++) {
+					String rawTypeName = os[i].toString();
 					String typeName = rawTypeName;
 					if(!typeName.endsWith(";")) typeName = "Q" + typeName + ";";
 					ParametedType p = getCDIProject().getNature().getTypeFactory().getParametedType(declaringType, typeName);
@@ -376,9 +350,36 @@
 						}
 					}
 				}
-			} catch (CoreException e) {
-				CDICorePlugin.getDefault().logError(e);
+			} else if(value != null) {
+				String rawTypeName = value.toString();
+				String typeName = rawTypeName;
+				if(!typeName.endsWith(";")) typeName = "Q" + typeName + ";";
+				ParametedType p = getCDIProject().getNature().getTypeFactory().getParametedType(declaringType, typeName);
+				if(p != null) {
+					int offset = 0;
+					int length = 0;
+					if(txt != null) {
+						int q = txt.indexOf(rawTypeName);
+						if(q >= 0) {
+							offset = s + q;
+							length = rawTypeName.length();
+						}
+					}
+					IParametedType other = p.getType() == null ? null : map.get(p.getType().getFullyQualifiedName());
+					if(other != null) {
+						String s1 = p.getSignature();
+						String s2 = other.getSignature();
+						if(!s1.equals(s2) && Signature.getArrayCount(s1) == Signature.getArrayCount(s2)) {
+							p.setSignature(s2);
+						}
+						result.add(new TypeDeclaration((ParametedType)other, typed.getResource(), offset, length));
+					} else {
+						result.add(new TypeDeclaration(p, typed.getResource(), offset, length));
+					}
+				}
 			}
+		} catch (CoreException e) {
+			CDICorePlugin.getDefault().logError(e);
 		}
 		return result;
 	}

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	2012-08-21 23:02:53 UTC (rev 43138)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2012-08-21 23:07:21 UTC (rev 43139)
@@ -99,6 +99,7 @@
 	private Set<IBean> declaredBeans = new HashSet<IBean>();
 	private Map<IPath, Set<IBean>> beansByPath = new HashMap<IPath, Set<IBean>>();
 	private Map<String, Set<IBean>> beansByName = new HashMap<String, Set<IBean>>();
+	private List<Set<IBean>> beansByTypes = new ArrayList<Set<IBean>>();
 	private Set<IBean> namedBeans = new HashSet<IBean>();
 	private Map<IType, IClassBean> classBeans = new HashMap<IType, IClassBean>();
 	private Set<IBean> alternatives = new HashSet<IBean>();
@@ -113,7 +114,9 @@
 	BeansXMLData allBeansXMLData = new BeansXMLData();
 	BeansXMLData projectBeansXMLData = new BeansXMLData();
 
-	public CDIProject() {}
+	public CDIProject() {
+		for (int i = 0; i < BEANS_BY_TYPE_SIZE; i++) beansByTypes.add(new HashSet<IBean>());
+	}
 
 	public CDIProject getModifiedCopy(IFile file, Collection<IBean> beans) {
 		CDIProject p = null;
@@ -291,7 +294,7 @@
 				}
 			}
 		}
-		if(result.size() < 1 || !attemptToResolveAmbiguousness) {
+		if(result.isEmpty() || !attemptToResolveAmbiguousness) {
 			return result;
 		}
 		
@@ -369,11 +372,7 @@
 		Set<IQualifierDeclaration> qs = new HashSet<IQualifierDeclaration>();
 		if(qualifiers != null) for (IQualifierDeclaration d: qualifiers) qs.add(d);
 		
-		Set<IBean> beans = new HashSet<IBean>();
-		synchronized(this) {
-			beans.addAll(allBeans);
-		}
-		for (IBean b: beans) {
+		for (IBean b: getBeansByLegalType(type)) {
 			if(containsType(b.getLegalTypes(), type)) {
 				try {
 					Collection<IQualifierDeclaration> qsb = b.getQualifierDeclarations(true);
@@ -389,6 +388,22 @@
 		return getResolvedBeans(result, attemptToResolveAmbiguousDependency);
 	}
 
+	static int BEANS_BY_TYPE_SIZE = 167;
+	static int OBJECT_INDEX = Math.abs("java.lang.Object".hashCode()) % BEANS_BY_TYPE_SIZE;
+	
+	static int toTypeIndex(IType type) {
+		return Math.abs(type.getFullyQualifiedName().hashCode()) % BEANS_BY_TYPE_SIZE;
+	}
+
+	private IBean[] getBeansByLegalType(IParametedType type) {
+		if(type.getType() == null) return new IBean[0];
+		int index = toTypeIndex(type.getType());
+		Collection<IBean> bs = index == OBJECT_INDEX ? allBeans : beansByTypes.get(index);
+		synchronized (this) {
+			return bs.toArray(new IBean[bs.size()]);
+		}
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * @see org.jboss.tools.cdi.core.IBeanManager#getBeans(boolean, org.jboss.tools.cdi.core.IInjectionPoint)
@@ -404,6 +419,14 @@
 		}
 		
 		IType jType = type.getType();
+		boolean isObjectType = jType != null && "java.lang.Object".equals(jType.getFullyQualifiedName());
+		
+		if(isObjectType && injectionPoint.getAnnotation(CDIConstants.ANY_QUALIFIER_TYPE_NAME) != null) {
+			synchronized(this) {
+				result.addAll(allBeans);
+			}
+			return getResolvedBeans(result, attemptToResolveAmbiguousDependency);
+		}
 	
 		if(jType != null && CDIConstants.EVENT_TYPE_NAME.equals(jType.getFullyQualifiedName())) {
 			List<? extends IParametedType> ps = type.getParameters();
@@ -437,16 +460,12 @@
 			}				
 		}
 	
-		Set<IBean> beans = new HashSet<IBean>();
-		synchronized(this) {
-			beans.addAll(allBeans);
-		}
 		boolean delegateInjectionPoint = injectionPoint.isDelegate();
 
 		String injectionPointName = injectionPoint.getBeanName();
-
-		for (IBean b: beans) {
-			if(containsType(b.getLegalTypes(), type)) {
+		
+		for (IBean b: getBeansByLegalType(type)) {
+			if(isObjectType || containsType(b.getLegalTypes(), type)) {
 				try {
 					if(delegateInjectionPoint && b == injectionPoint.getClassBean()) {
 						continue;
@@ -559,7 +578,7 @@
 		for (IParametedType t: types) {
 			IType jType1 = t.getType();
 			if(jType1 == null || !jType.getFullyQualifiedName().equals(jType1.getFullyQualifiedName())) continue;
-			if(!((ParametedType)t).getArrayPrefix().equals(((ParametedType)type).getArrayPrefix())) continue;
+			if(((ParametedType)t).getArrayIndex() != ((ParametedType)type).getArrayIndex()) continue;
 			if(((ParametedType)t).isAssignableTo((ParametedType)type, false)) {
 				return true;
 			}
@@ -574,7 +593,7 @@
 			}
 		}
 
-		TreeSet<String> injectionKeys = new TreeSet<String>();
+		Set<String> injectionKeys = new HashSet<String>();
 		for (IQualifierDeclaration d: injectionQualifiers) {
 			injectionKeys.add(getAnnotationDeclarationKey(d));
 		}
@@ -586,7 +605,7 @@
 			injectionKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
 		}
 
-		TreeSet<String> beanKeys = new TreeSet<String>();
+		Set<String> beanKeys = new HashSet<String>();
 		if(beanQualifiers.isEmpty()) {
 			beanKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
 		} else for (IQualifierDeclaration d: beanQualifiers) {
@@ -612,7 +631,7 @@
 	public static boolean areMatchingQualifiers(Collection<IQualifierDeclaration> beanQualifiers, IType... injectionQualifiers) throws CoreException {
 		if(!beanQualifiers.isEmpty() || injectionQualifiers.length != 0) {
 
-			TreeSet<String> injectionKeys = new TreeSet<String>();
+			Set<String> injectionKeys = new HashSet<String>();
 			for (IType d: injectionQualifiers) {
 				injectionKeys.add(d.getFullyQualifiedName().replace('$', '.'));
 			}
@@ -622,7 +641,7 @@
 					injectionKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
 				}
 		
-				TreeSet<String> beanKeys = new TreeSet<String>();
+				Set<String> beanKeys = new HashSet<String>();
 				if(beanQualifiers.isEmpty()) {
 					beanKeys.add(CDIConstants.DEFAULT_QUALIFIER_TYPE_NAME);
 				} else {
@@ -1357,6 +1376,8 @@
 			allBeans.clear();
 			declaredBeans.clear();
 			injectionPointsByType.clear();
+			
+			for (int i = 0; i < BEANS_BY_TYPE_SIZE; i++) beansByTypes.get(i).clear();
 		}
 
 		classBeans = newClassBeans;
@@ -1452,6 +1473,14 @@
 			if(bean.getDeclaringProject() == this) {
 				declaredBeans.add(bean);
 			}
+			for (IParametedType t: bean.getLegalTypes()) {
+				if(t.getType() != null && t.getType().exists()) {
+					int index = toTypeIndex(t.getType());
+					if(index != OBJECT_INDEX) {
+						beansByTypes.get(index).add(bean);
+					}
+				}
+			}
 		}
 	}
 
@@ -1534,11 +1563,8 @@
 			IParametedType beanType, IType... qualifiers) {
 		Collection<IBean> result = new HashSet<IBean>();
 		IParametedType type = beanType;
-		Collection<IBean> beans = new ArrayList<IBean>();
-		synchronized(this) {
-			beans.addAll(allBeans);
-		}
-		for (IBean b: beans) {
+
+		for (IBean b: getBeansByLegalType(type)) {
 			if(containsType(b.getLegalTypes(), type)) {
 				try {
 					Collection<IQualifierDeclaration> qsb = b.getQualifierDeclarations(true);

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-21 23:02:53 UTC (rev 43138)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java	2012-08-21 23:07:21 UTC (rev 43139)
@@ -583,10 +583,8 @@
 	 * (non-Javadoc)
 	 * @see org.jboss.tools.cdi.core.IClassBean#getAllMethods()
 	 */
-	public Set<IBeanMethod> getAllMethods() {
-		Set<IBeanMethod> result = new HashSet<IBeanMethod>();
-		result.addAll(methods);
-		return result;
+	public Collection<IBeanMethod> getAllMethods() {
+		return new ArrayList<IBeanMethod>(methods);
 	}
 
 	/*

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	2012-08-21 23:02:53 UTC (rev 43138)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java	2012-08-21 23:07:21 UTC (rev 43139)
@@ -144,20 +144,19 @@
 		if(!ds.isEmpty()) {
 			return ds.iterator().next().getScope();
 		}
-		Collection<IScope> defaults = new HashSet<IScope>();
+		IScope defaultScope = null;
 		for (IStereotypeDeclaration d: getStereotypeDeclarations()) {
 			IStereotype s = d.getStereotype();
 			IScope sc = s.getScope();
 			if(sc != null) {
-				defaults.add(sc);
+				if(defaultScope == null) {
+					defaultScope = sc;
+				} else if(defaultScope != sc) {
+					return null;
+				}
 			}
 		}
-		if(defaults.size() == 1) {
-			return defaults.iterator().next();
-		} else if(defaults.size() > 1) {
-			return null;
-		}
-		return getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
+		return defaultScope != null ? defaultScope : getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
 	}
 
 	public IAnnotationDeclaration getProducesAnnotation() {

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-21 23:02:53 UTC (rev 43138)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java	2012-08-21 23:07:21 UTC (rev 43139)
@@ -15,7 +15,6 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 import org.eclipse.jdt.core.IType;
 import org.jboss.tools.cdi.core.CDIConstants;
@@ -61,7 +60,7 @@
 	}
 
 	public Collection<ITypeDeclaration> getAllTypeDeclarations() {
-		Collection<ITypeDeclaration> result = new HashSet<ITypeDeclaration>();
+		Collection<ITypeDeclaration> result = new ArrayList<ITypeDeclaration>(1);
 		if(typeDeclaration != null && typeDeclaration.getStartPosition() > 0) {
 			result.add(typeDeclaration);
 		}
@@ -212,20 +211,19 @@
 		if(!ds.isEmpty()) {
 			return ds.iterator().next().getScope();
 		}
-		Set<IScope> defaults = new HashSet<IScope>();
+		IScope defaultScope = null;
 		for (IStereotypeDeclaration d: getStereotypeDeclarations()) {
 			IStereotype s = d.getStereotype();
 			IScope sc = s.getScope();
 			if(sc != null) {
-				defaults.add(sc);
+				if(defaultScope == null) {
+					defaultScope = sc;
+				} else if(defaultScope != sc) {
+					return null;
+				}
 			}
 		}
-		if(defaults.size() == 1) {
-			return defaults.iterator().next();
-		} else if(defaults.size() > 1) {
-			return null;
-		}
-		return getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
+		return defaultScope != null ? defaultScope : getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
 	}
 
 	public IAnnotationDeclaration getProducesAnnotation() {



More information about the jbosstools-commits mailing list