[jbosstools-commits] JBoss Tools SVN: r7037 - in trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core: validation and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 20 08:30:06 EDT 2008


Author: scabanovich
Date: 2008-03-20 08:30:06 -0400 (Thu, 20 Mar 2008)
New Revision: 7037

Modified:
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/TypeInfoCollector.java
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
   trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java
Log:
JBIDE-1750

Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java	2008-03-20 12:16:14 UTC (rev 7036)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java	2008-03-20 12:30:06 UTC (rev 7037)
@@ -84,6 +84,11 @@
 	
 	private static List<ISeamContextVariable> internalResolveVariables(ISeamProject project, String name, boolean onlyEqualNames, Set<ISeamContextVariable> variables) {
 		List<ISeamContextVariable> resolvedVariables = new ArrayList<ISeamContextVariable>();
+		if(onlyEqualNames) {
+			variables = project.getVariablesByName(name);
+			if(variables != null) resolvedVariables.addAll(variables);
+			return resolvedVariables;
+		}
 		for (ISeamContextVariable variable : variables) {
 			String n = variable.getName();
 			if(onlyEqualNames) {
@@ -225,8 +230,6 @@
 	}
 
 	public static TypeInfoCollector collectTypeInfo(TypeInfoCollector.MemberInfo member) {
-		TypeInfoCollector typeInfo = new TypeInfoCollector(member);
-		typeInfo.collectInfo();
-		return typeInfo;
+		return member.getTypeCollector();
 	}
 }
\ No newline at end of file

Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/TypeInfoCollector.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/TypeInfoCollector.java	2008-03-20 12:16:14 UTC (rev 7036)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/TypeInfoCollector.java	2008-03-20 12:30:06 UTC (rev 7037)
@@ -14,6 +14,7 @@
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -172,6 +173,8 @@
 		private IType fMemberType;
 		private boolean isDataModel;
 		private Type fType;
+		
+		TypeInfoCollector typeInfo;
 
 		protected MemberInfo (
 			IType sourceType,
@@ -291,6 +294,14 @@
 		void setDataModel(boolean isDataModel) {
 			this.isDataModel = isDataModel;
 		}
+		
+		public TypeInfoCollector getTypeCollector() {
+			if(typeInfo == null) {
+				typeInfo = new TypeInfoCollector(this);
+				typeInfo.collectInfo();
+			}
+			return typeInfo;
+		}
 
 		abstract public IJavaElement getJavaElement();
 	}
@@ -567,17 +578,50 @@
 			return false;
 		}
 	}
-
+	
+	public static class SuperTypeInfo {
+		IType type;
+		Set<String> names = new HashSet<String>();
+		IType[] superTypes = new IType[0];
+		
+		SuperTypeInfo(IType type) throws JavaModelException {
+			this.type = type;
+			superTypesCache.put(type, this);
+			ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
+			superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
+			if(superTypes != null) for (int i = 0; i < superTypes.length; i++) {
+				names.add(superTypes[i].getFullyQualifiedName());
+			}
+			if(superTypes == null) superTypes = new IType[0];
+		}
+		
+		public Set<String> getNames() {
+			return names;
+		}
+		
+		public IType[] getSuperTypes() {
+			return superTypes;
+		}
+	}
+	
+	static Map<IType, SuperTypeInfo> superTypesCache = new HashMap<IType, SuperTypeInfo>();
+	
+	public static SuperTypeInfo getSuperTypes(IType type) throws JavaModelException {
+		if(type == null) return null;
+		SuperTypeInfo ts = superTypesCache.get(type);
+		if(ts == null) {
+			ts = new SuperTypeInfo(type);
+		}
+		return ts;
+	}
+	
 	public static boolean isInstanceofType(IType type, String qualifiedTypeName) throws JavaModelException {
 		if (qualifiedTypeName == null || type == null) return false;
 		boolean isInstanceofType = qualifiedTypeName.equals(type.getFullyQualifiedName());
 		if (!isInstanceofType) {
-			ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
-			IType[] superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
-			for (int i = 0; !isInstanceofType && superTypes != null && i < superTypes.length; i++) {
-				if (qualifiedTypeName.equals(superTypes[i].getFullyQualifiedName())) {
-					return true;
-				}
+			SuperTypeInfo ts = getSuperTypes(type);
+			if(ts != null && ts.getNames().contains(qualifiedTypeName)) {
+				return true;
 			}
 			return false;
 		}
@@ -823,20 +867,35 @@
 		}	
 		return properties;
 	}
+	
+	static Map<IMember, MemberInfo> memberInfoCacheFalse = new HashMap<IMember, MemberInfo>();
+	static Map<IMember, MemberInfo> memberInfoCacheTrue = new HashMap<IMember, MemberInfo>();
+	
+	public static void cleanCache() {
+		memberInfoCacheFalse.clear();
+		memberInfoCacheTrue.clear();
+		superTypesCache.clear();
+	}
 
 	public static MemberInfo createMemberInfo(IMember member, boolean dataModel) {
+		Map<IMember, MemberInfo> cache = dataModel ? memberInfoCacheTrue : memberInfoCacheFalse;
+		MemberInfo result = cache.get(member);
+		if(result != null) return result;
 		try {
 			if (member instanceof IType)
-				return new TypeInfo((IType)member, null, dataModel);
+				result = new TypeInfo((IType)member, null, dataModel);
 			else if (member instanceof IField)
-				return new FieldInfo((IField)member, null, dataModel);
+				result = new FieldInfo((IField)member, null, dataModel);
 			else if (member instanceof IMethod)
-				return new MethodInfo((IMethod)member, null, dataModel);
+				result = new MethodInfo((IMethod)member, null, dataModel);
 		} catch (JavaModelException e) {
 			SeamCorePlugin.getPluginLog().logError(e);
 		}
+		if(result != null) {
+			cache.put(member, result);
+		}
 
-		return null;
+		return result;
 	}
 
 	public static MemberInfo createMemberInfo(IMember member) {

Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java	2008-03-20 12:16:14 UTC (rev 7036)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java	2008-03-20 12:30:06 UTC (rev 7037)
@@ -60,6 +60,7 @@
 import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
 import org.jboss.tools.seam.internal.core.SeamProject;
 import org.jboss.tools.seam.internal.core.SeamTextSourceReference;
+import org.jboss.tools.seam.internal.core.el.TypeInfoCollector;
 
 /**
  * Validator for Java and XML files.
@@ -365,8 +366,7 @@
 						validationContext.addLinkedCoreResource(componentName, declaration.getSourcePath());
 						// Save link between component name and all supers of java declaration.
 						try {
-							ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
-							IType[] superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
+							IType[] superTypes = TypeInfoCollector.getSuperTypes(type).getSuperTypes();
 							for (int i = 0; superTypes != null && i < superTypes.length; i++) {
 								if(!superTypes[i].isBinary()) {
 									IPath path = superTypes[i].getResource().getFullPath();

Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java	2008-03-20 12:16:14 UTC (rev 7036)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java	2008-03-20 12:30:06 UTC (rev 7037)
@@ -21,6 +21,7 @@
 import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
 import org.jboss.tools.seam.core.ISeamProject;
 import org.jboss.tools.seam.internal.core.SeamProject;
+import org.jboss.tools.seam.internal.core.el.TypeInfoCollector;
 
 /**
  * This Manager invokes all dependent seam validators that should be invoked in one job.
@@ -46,6 +47,8 @@
 	 * @see org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext, org.eclipse.wst.validation.internal.provisional.core.IReporter)
 	 */
 	public IStatus validateInJob(IValidationContext helper, IReporter reporter)	throws ValidationException {
+		TypeInfoCollector.cleanCache();
+
 		SeamValidationHelper coreHelper = (SeamValidationHelper)helper;
 		ISeamProject project = coreHelper.getSeamProject();
 		if(project==null) {




More information about the jbosstools-commits mailing list