[jbosstools-commits] JBoss Tools SVN: r43672 - in trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core: impl/definition and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Sep 13 20:11:44 EDT 2012


Author: scabanovich
Date: 2012-09-13 20:11:39 -0400 (Thu, 13 Sep 2012)
New Revision: 43672

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/definition/AbstractMemberDefinition.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
Log:
JBIDE-12446
https://issues.jboss.org/browse/JBIDE-12446
Lightweight map.

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-09-13 23:47:57 UTC (rev 43671)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java	2012-09-14 00:11:39 UTC (rev 43672)
@@ -280,7 +280,7 @@
 	}
 
 	public Collection<ITypeDeclaration> getAllTypeDeclarations() {
-		Set<IParametedType> ps = getDefinition().getInheritedTypes();
+		Collection<IParametedType> ps = getDefinition().getInheritedTypes();
 		Set<ITypeDeclaration> result = new HashSet<ITypeDeclaration>();
 		for (IParametedType p: ps) {
 			if(p instanceof TypeDeclaration) {

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java	2012-09-13 23:47:57 UTC (rev 43671)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java	2012-09-14 00:11:39 UTC (rev 43672)
@@ -50,9 +50,9 @@
 	public static int FLAG_ALL_MEMBERS = 2;
 
 	CDICoreNature project;
-	protected List<IAnnotationDeclaration> annotations = new ArrayList<IAnnotationDeclaration>();
+	protected List<IAnnotationDeclaration> annotations = new ArrayList<IAnnotationDeclaration>(2);
 	protected IAnnotatable member;
-	protected Map<String, AnnotationDeclaration> annotationsByType = new HashMap<String, AnnotationDeclaration>();
+	private IAnnotationMap annotationsByType = EmptyMap.instance;
 	protected IResource resource;
 	
 	protected ITextSourceReference originalDefinition = null;
@@ -152,7 +152,7 @@
 		}
 		
 		if(a.getTypeName() != null) {
-			annotationsByType.put(a.getTypeName(), a);
+			annotationsByType = annotationsByType.put(a.getTypeName(), a);
 		}
 	}
 
@@ -173,7 +173,7 @@
 		String name = ((AnnotationDeclaration)a).getTypeName();
 		IAnnotationDeclaration b = getAnnotation(name);
 		if(a == b) {
-			annotationsByType.remove(name);
+			annotationsByType = annotationsByType.remove(name);
 			annotations.remove(a);
 		}
 	}
@@ -237,4 +237,108 @@
 	public boolean exists() {
 		return member instanceof IJavaElement && ((IJavaElement)member).exists();
 	}
-}
\ No newline at end of file
+}
+
+interface IAnnotationMap {
+	IAnnotationMap put(String type, AnnotationDeclaration d);
+	AnnotationDeclaration get(String type);
+	IAnnotationMap remove(String type);
+}
+
+class EmptyMap implements IAnnotationMap {
+	static EmptyMap instance = new EmptyMap();
+	
+	private EmptyMap() {}
+
+	public IAnnotationMap put(String type, AnnotationDeclaration d) {
+		return new OneEntryMap(d);
+	}
+
+	public AnnotationDeclaration get(String type) {
+		return null;
+	}
+
+	public IAnnotationMap remove(String type) {
+		return this;
+	}
+}
+
+class OneEntryMap implements IAnnotationMap {
+	AnnotationDeclaration d;
+	
+	public OneEntryMap(AnnotationDeclaration d) {
+		this.d = d;
+	}
+
+	@Override
+	public IAnnotationMap put(String type, AnnotationDeclaration d) {
+		if(this.d.getTypeName().equals(type)) {
+			this.d = d;
+			return this;
+		}
+		return new TwoEntryMap(this.d, d);
+	}
+
+	public AnnotationDeclaration get(String type) {
+		return (d.getTypeName().equals(type)) ? d : null;
+	}
+
+	public IAnnotationMap remove(String type) {
+		return (get(type) != null) ? EmptyMap.instance : this;
+	}	
+}
+
+class TwoEntryMap implements IAnnotationMap {
+	AnnotationDeclaration d1;
+	AnnotationDeclaration d2;
+	
+	public TwoEntryMap(AnnotationDeclaration d1,AnnotationDeclaration d2) {
+		this.d1 = d1;
+		this.d2 = d2;
+	}
+
+	public IAnnotationMap put(String type, AnnotationDeclaration d) {
+		AnnotationDeclaration dc = get(type);
+		if(dc == d1) {
+			d1 = d;
+			return this;
+		} else if(dc == d2) {
+			d2 = d;
+			return this;
+		}
+		AnnotationMap map = new AnnotationMap();
+		map.put(this.d1.getTypeName(), this.d1);
+		map.put(this.d2.getTypeName(), this.d2);
+		map.put(type, d);
+		return map;
+	}
+
+	public AnnotationDeclaration get(String type) {
+		return (d1.getTypeName().equals(type)) ? d1 : (d2.getTypeName().equals(type)) ? d2 : null;
+	}
+
+	public IAnnotationMap remove(String type) {
+		AnnotationDeclaration d = get(type);
+		return (d == d1) ? new OneEntryMap(d2) : (d == d2) ? new OneEntryMap(d1) : this;
+	}	
+}
+
+class AnnotationMap implements IAnnotationMap {
+	Map<String, AnnotationDeclaration> annotationsByType = new HashMap<String, AnnotationDeclaration>(8);
+	
+	AnnotationMap() {}
+	
+	public IAnnotationMap put(String type, AnnotationDeclaration d) {
+		annotationsByType.put(type, d);
+		return this;
+	}
+
+	public AnnotationDeclaration get(String type) {
+		return annotationsByType.get(type);
+	}
+
+	public IAnnotationMap remove(String type) {
+		annotationsByType.remove(type);
+		return this;
+	}
+}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java	2012-09-13 23:47:57 UTC (rev 43671)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java	2012-09-14 00:11:39 UTC (rev 43672)
@@ -93,9 +93,9 @@
 		parametedType = (ParametedType)t;
 	}
 
-	public Set<IParametedType> getInheritedTypes() {
+	public Collection<IParametedType> getInheritedTypes() {
 		if(parametedType == null) {
-			return Collections.emptySet(); 
+			return Collections.emptyList(); 
 		}
 		return parametedType.getInheritedTypes();
 	}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java	2012-09-13 23:47:57 UTC (rev 43671)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/ImplementationCollector.java	2012-09-14 00:11:39 UTC (rev 43672)
@@ -40,8 +40,7 @@
 			IType type = typeDef.getType();
 			if(type == null || !type.exists() || type.isInterface()) continue;
 			if(!mayBeRelevant(type)) continue;
-			Set<IParametedType> types = typeDef.getInheritedTypes();
-			for (IParametedType t: types) {
+			for (IParametedType t: typeDef.getInheritedTypes()) {
 				IType q = t.getType();
 				if(q == null) continue;
 				String cn = q.getFullyQualifiedName();



More information about the jbosstools-commits mailing list