[jbosstools-commits] JBoss Tools SVN: r43670 - trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Sep 13 19:41:38 EDT 2012


Author: scabanovich
Date: 2012-09-13 19:41:38 -0400 (Thu, 13 Sep 2012)
New Revision: 43670

Modified:
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java
Log:
JBIDE-12446
https://issues.jboss.org/browse/JBIDE-12446
Lightweight map.

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java	2012-09-13 20:39:41 UTC (rev 43669)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java	2012-09-13 23:41:38 UTC (rev 43670)
@@ -10,8 +10,8 @@
  ******************************************************************************/ 
 package org.jboss.tools.common.java.impl;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -37,7 +37,7 @@
  */
 public class AnnotationDeclaration implements IAnnotationDeclaration {
 	protected IJavaAnnotation annotation;
-	protected Map<String, Object> values;
+	protected IValues values = EmptyValues.instance;
 
 	public AnnotationDeclaration() {}
 
@@ -45,12 +45,11 @@
 		this.annotation = annotation;
 		IMemberValuePair[] pairs = getMemberValuePairs();
 		if(pairs.length > 0) {
-			values = new HashMap<String, Object>();
 			for (IMemberValuePair pair: pairs) {
 				String name = pair.getMemberName();
 				Object value = resolveMemberValue(pair);
 				if(value != null) {
-					values.put(name, value);
+					values = values.put(name, value);
 				}
 			}
 		}
@@ -196,4 +195,58 @@
 	public IJavaElement getSourceElement() {
 		return annotation.getParentElement();
 	}
+}
+
+interface IValues {
+	Object get(String name);
+	IValues put(String name, Object value);
+}
+
+class EmptyValues implements IValues {
+	static EmptyValues instance = new EmptyValues();
+	public Object get(String name) {
+		return null;
+	}
+	public IValues put(String name, Object value) {
+		return ("value".equals(name)) ? new Value(value) : new Values(name, value);
+	}
+}
+
+class Value implements IValues {
+	Object value;
+	Value(Object value) {
+		this.value = value;
+	}
+
+	public Object get(String name) {
+		return "value".equals(name) ? value : null;
+	}
+
+	public IValues put(String name, Object value) {
+		Values values = new Values("value", this.value);
+		values.put(name, value);
+		return values;
+	}
+}
+
+class Values implements IValues {
+	List<String> names = new ArrayList<String>(2);
+	List<Object> values = new ArrayList<Object>(2);
+
+	public Values(String name, Object value) {
+		names.add(name);
+		values.add(value);
+	}
+	public Object get(String name) {
+		for (int i = 0; i < names.size(); i++) {
+			if(name.equals(names.get(i))) return values.get(i);
+		}
+		return null;
+	}
+
+	public IValues put(String name, Object value) {
+		names.add(name);
+		values.add(value);
+		return this;
+	}
 }
\ No newline at end of file



More information about the jbosstools-commits mailing list