[jbosstools-commits] JBoss Tools SVN: r43659 - in trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common: util and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Sep 13 13:32:33 EDT 2012


Author: scabanovich
Date: 2012-09-13 13:32:33 -0400 (Thu, 13 Sep 2012)
New Revision: 43659

Modified:
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java
Log:
JBIDE-12446
https://issues.jboss.org/browse/JBIDE-12446


Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java	2012-09-13 17:18:52 UTC (rev 43658)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java	2012-09-13 17:32:33 UTC (rev 43659)
@@ -24,19 +24,12 @@
 
 public class JavaAnnotation implements IJavaAnnotation {
 	IAnnotation annotation;
-
 	String annotationTypeName;
-	IType type;
 
 	public JavaAnnotation(IAnnotation annotation, IType declaringType) {
 		this.annotation = annotation;
-		try {
-			String name = annotation.getElementName();
-			annotationTypeName = EclipseJavaUtil.resolveType(declaringType, name);
-			type = EclipseJavaUtil.findType(annotation.getJavaProject(), annotationTypeName);
-		} catch (JavaModelException e) {
-			CommonCorePlugin.getDefault().logError(e);
-		}
+		String name = annotation.getElementName();
+		annotationTypeName = EclipseJavaUtil.resolveType(declaringType, name);
 	}
 
 	public IResource getResource() {
@@ -48,7 +41,12 @@
 	}
 
 	public IType getType() {
-		return type;
+		try {
+			return EclipseJavaUtil.findType(annotation.getJavaProject(), annotationTypeName);
+		} catch (JavaModelException e) {
+			CommonCorePlugin.getDefault().logError(e);
+		}
+		return null;
 	}
 
 	public int getLength() {

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java	2012-09-13 17:18:52 UTC (rev 43658)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java	2012-09-13 17:32:33 UTC (rev 43659)
@@ -13,7 +13,9 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.core.runtime.CoreException;
@@ -74,11 +76,21 @@
 	public static String resolveType(IType type, String typeName) {
 		return TypeResolutionCache.getInstance().resolveType(type, typeName);
 	}
+
+	static Map<String, Map<String, IType>> typeCache = new Hashtable<String, Map<String,IType>>();
 	
 	public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
 		if(qualifiedName == null || qualifiedName.length() == 0) return null;
+		Map<String, IType> cache = typeCache.get(javaProject.getElementName());
+		if(cache == null) {
+			cache = new Hashtable<String, IType>();
+			typeCache.put(javaProject.getElementName(), cache);
+		} else {
+			IType type = cache.get(qualifiedName);
+			if(type != null) return type;
+		}
 		IType type = javaProject.findType(qualifiedName);
-		if(type != null) return type;
+		if(type != null) return register(cache, qualifiedName, type);
 		int dot = qualifiedName.lastIndexOf('.');
 		String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot); //$NON-NLS-1$
 		String shortName = qualifiedName.substring(dot + 1);
@@ -89,11 +101,16 @@
 			ICompilationUnit[] us = f.getCompilationUnits();
 			for (int j = 0; j < us.length; j++) {
 				IType t = us[j].getType(shortName);
-				if(t != null && t.exists()) return t;
+				if(t != null && t.exists()) return register(cache, qualifiedName, t);;
 			}
 		}
 		return null;
 	}
+
+	private static IType register(Map<String, IType> cache, String qualifiedName, IType type) {
+		cache.put(qualifiedName, type);
+		return type;
+	}
 	
 	public static List<IType> getSupperTypes(IType type) throws JavaModelException {
 		ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java	2012-09-13 17:18:52 UTC (rev 43658)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java	2012-09-13 17:32:33 UTC (rev 43659)
@@ -205,6 +205,7 @@
 	
 	public void clean() {
 		resolved = new Hashtable<String, Resolved>();
+		EclipseJavaUtil.typeCache = new Hashtable<String, Map<String,IType>>();
 	}
 
 	private String __resolveType(IType type, String typeName) {



More information about the jbosstools-commits mailing list