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

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jun 17 06:47:06 EDT 2010


Author: scabanovich
Date: 2010-06-17 06:47:06 -0400 (Thu, 17 Jun 2010)
New Revision: 22850

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/ParametedType.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
Log:
https://jira.jboss.org/browse/JBIDE-6474


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	2010-06-17 09:19:25 UTC (rev 22849)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2010-06-17 10:47:06 UTC (rev 22850)
@@ -322,8 +322,19 @@
 	}
 
 	public static boolean containsType(Set<IParametedType> types, IParametedType type) {
+		if(type == null) {
+			return false;
+		}
+		IType jType = type.getType();
+		if(jType == null) return false;
 		for (IParametedType t: types) {
-			if(t.equals(type)) return true;
+			IType jType1 = t.getType();
+			if(!jType.equals(jType1)) continue;
+			if(!((ParametedType)t).getArrayPrefix().equals(((ParametedType)type).getArrayPrefix())) continue;
+			if(((ParametedType)t).isAssignableTo((ParametedType)type, false)) {
+				return true;
+			}
+			
 		}
 		return false;
 	}

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java	2010-06-17 09:19:25 UTC (rev 22849)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java	2010-06-17 10:47:06 UTC (rev 22850)
@@ -20,6 +20,7 @@
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.ITypeParameter;
 import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
 import org.jboss.tools.cdi.core.CDICorePlugin;
 import org.jboss.tools.cdi.core.IParametedType;
 import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
@@ -37,6 +38,10 @@
 	protected List<ParametedType> parameterTypes = new ArrayList<ParametedType>();
 	protected boolean primitive;
 
+	protected boolean isUpper = false;
+	protected boolean isLower = false;
+	protected boolean isVariable = false;
+
 	boolean inheritanceIsBuilt = false;
 	protected ParametedType superType = null;
 	protected Set<IParametedType> inheritedTypes = new HashSet<IParametedType>();
@@ -62,6 +67,30 @@
 		this.primitive = primitive;
 	}
 
+	public boolean isUpper() {
+		return isUpper;
+	}
+
+	public void setUpper(boolean b) {
+		isUpper = b;
+	}
+
+	public boolean isLower() {
+		return isLower;
+	}
+
+	public void setLower(boolean b) {
+		isLower = b;
+	}
+
+	public boolean isVariable() {
+		return isVariable;
+	}
+
+	public void setVariable(boolean b) {
+		isVariable = b;
+	}
+
 	public ParametedTypeFactory getFactory() {
 		return typeFactory;
 	}
@@ -136,7 +165,11 @@
 				String sc = type.getSuperclassTypeSignature();
 				boolean objectArray = false;
 				if(sc != null) {
-					sc = resolveParameters(sc);
+					try {
+						sc = resolveParameters(sc);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
 				} else if(!"java.lang.Object".equals(type.getFullyQualifiedName())) {
 					sc = "QObject;";
 				} else if("java.lang.Object".equals(type.getFullyQualifiedName()) && arrayPrefix.length() > 0) {
@@ -213,15 +246,12 @@
 		if(j < i) {
 			return typeSignature;
 		}
-		String params = typeSignature.substring(i + 1, j);
 		boolean replaced = false;
 		StringBuffer newParams = new StringBuffer();
-		StringTokenizer st = new StringTokenizer(params);
-		while(st.hasMoreTokens()) {
-			String param = st.nextToken();
+		String[] ps = Signature.getTypeArguments(typeSignature);
+		for (String param: ps) {
 			String newParam = resolveParameters( param);
 			if(!param.equals(newParam)) replaced = true;
-			if(newParam.length() == 0) newParams.append(',');
 			newParams.append(newParam);
 		}
 		if(replaced) {
@@ -276,4 +306,50 @@
 		return signature + ":" + super.toString();
 	}
 
+	public boolean isAssignableTo(ParametedType other, boolean checkInheritance) {
+		if(equals(other)) return true;
+		if(this.type == null) return false;
+		if(other.isVariable && other.type == null) return true;
+		if(this.type.equals(other.type)) {
+			if(areTypeParametersAssignableTo(other)) return true;
+		}
+		if(checkInheritance) {
+			for (IParametedType t: getInheritedTypes()) {
+				if(((ParametedType)t).isAssignableTo(other, false)) return true;
+			}
+		}
+		return false;
+	}
+	
+	boolean areTypeParametersAssignableTo(ParametedType other) {
+		if(other.parameterTypes.size() == 0) return true;
+		if(this.parameterTypes.size() != other.parameterTypes.size()) return false;
+		for (int i = 0; i < parameterTypes.size(); i++) {
+			ParametedType p1 = parameterTypes.get(i);
+			ParametedType p2 = other.parameterTypes.get(i);
+			if(p1.isLower() || p1.isUpper()) return false;
+			if(p1.isVariable()) {
+				if(p2.isVariable()) {
+					if(p2.isAssignableTo(p1, true)) continue;
+				} else if(p2.isLower()) {
+					if(p2.isAssignableTo(p1, true)) continue;
+				} else if(p2.isUpper()) {
+					if(p2.isAssignableTo(p1, true)) continue;
+					if(p1.isAssignableTo(p2, true)) continue;
+				} else {
+					if(p2.isAssignableTo(p1, true)) continue;
+				}
+			} else {
+				if(p2.isLower()) {
+					if(p2.isAssignableTo(p1, true)) continue;
+				} else {
+					if(p1.isAssignableTo(p2, true)) continue;
+				}
+			}
+			
+			return false;
+		}
+		return true;
+	}
+
 }

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java	2010-06-17 09:19:25 UTC (rev 22849)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/TypeDeclaration.java	2010-06-17 10:47:06 UTC (rev 22850)
@@ -36,6 +36,10 @@
 		inheritedTypes = type.inheritedTypes;
 		superType = type.superType;
 		primitive = type.primitive;
+		
+		isLower = type.isLower;
+		isUpper = type.isUpper;
+		isVariable = type.isVariable;
 	}
 
 	public int getLength() {

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java	2010-06-17 09:19:25 UTC (rev 22849)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java	2010-06-17 10:47:06 UTC (rev 22850)
@@ -20,6 +20,7 @@
 import org.eclipse.jdt.core.ISourceRange;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
 import org.jboss.tools.cdi.core.CDICorePlugin;
 import org.jboss.tools.cdi.internal.core.impl.ParametedType;
 import org.jboss.tools.cdi.internal.core.impl.TypeDeclaration;
@@ -55,6 +56,25 @@
 		parametedType.setFactory(this);
 		parametedType.setType(type);
 		if(type != null) parametedType.setSignature("Q" + type.getFullyQualifiedName() + ";");
+		String[] ps = null;
+		try {
+			ps = type.getTypeParameterSignatures();
+		} catch (JavaModelException e) {
+			//ignore
+		}
+		if(ps != null && ps.length > 0) {
+			for (int i = 0; i < ps.length; i++) {
+				try {
+					ParametedType p = getParametedTypeForParameter(type, ps[i], null);
+					if(p != null) parametedType.addParameter(p);
+				} catch (JavaModelException e) {
+					e.printStackTrace();
+				} catch (Exception ee) {
+					ee.printStackTrace();
+				}
+				
+			}
+		}
 		return parametedType;
 	}
 
@@ -75,14 +95,25 @@
 			typeSignature = primitives.get(typeSignature);
 			result.setSignature(result.getArrayPrefix() + typeSignature);
 			result.setPrimitive(true);
-		}
+		} else if(typeSignature.startsWith("+")) {
+			typeSignature = typeSignature.substring(1);
+			result.setUpper(true);
+		} else if(typeSignature.startsWith("-")) {
+			typeSignature = typeSignature.substring(1);
+			result.setLower(true);
+		} 
 
 		int startToken = typeSignature.indexOf('<');
 		if(startToken < 0) {
 			String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeSignature);
 			if(resovedTypeName == null) return null;
 			if(!context.isBinary()) {
-				result.setSignature(result.getArrayPrefix() + "Q" + resovedTypeName + ";");
+				StringBuffer ns = new StringBuffer();
+				ns.append(result.getArrayPrefix());
+				if(result.isLower()) ns.append('-');
+				if(result.isUpper()) ns.append('+');
+				ns.append('Q').append(resovedTypeName).append(";");
+				result.setSignature(ns.toString());
 			}
 			IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
 			if(type != null) {
@@ -93,51 +124,52 @@
 			if(context instanceof IMethod) {
 				String[] ps = ((IMethod)context).getTypeParameterSignatures();
 				for (int i = 0; i < ps.length; i++) {
-					String t = ps[i];
-					int cp = t.indexOf(":");
-					if(cp > 0) t = t.substring(0, cp);
-					t = "Q" + t + ";";
-					if(t.equals(result.getSignature())) {
-						cache.put(key, result);
-						return result;
+					ParametedType st = getParametedTypeForParameter(context, ps[i], result);
+					if(st != null) {
+						if(st.getSignature().indexOf(':') >= 0) {
+							CDICorePlugin.getDefault().logWarning("Wrong signature=" + st.getSignature());
+						}
+						return st;
 					}
 				}
 			}
 			String[] ps = contextType.getTypeParameterSignatures();
 			for (int i = 0; i < ps.length; i++) {
-				String t = ps[i];
-				if(t.endsWith(":")) t = t.substring(0, t.length() - 1);
-				t = "Q" + t + ";";
-				if(t.equals(result.getSignature())) {
-					cache.put(key, result);
-					return result;
-				}
+				ParametedType st = getParametedTypeForParameter(contextType, ps[i], result);
+				if(st != null) return st;
 			}
 		} else {
 			int endToken = typeSignature.lastIndexOf('>');
 			if(endToken < startToken) return null;
 			String typeName = typeSignature.substring(0, startToken) + typeSignature.substring(endToken + 1);
-			String params = typeSignature.substring(startToken + 1, endToken);
 			String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeName);
 			if(resovedTypeName == null) return null;
 			IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
 			if(type != null) {
 				result.setType(type);
 				StringBuffer newParams = new StringBuffer();
-				StringTokenizer st = new StringTokenizer(params, ",");
-				while(st.hasMoreTokens()) {
-					String paramSignature = st.nextToken();
+				String[] paramSignatures = null;
+				try {
+				paramSignatures = Signature.getTypeArguments(typeSignature);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				if(paramSignatures != null) for (String paramSignature: paramSignatures) {
 					ParametedType param = getParametedType(context, paramSignature);
 					if(param == null) {
 						param = new ParametedType();
 						param.setSignature(paramSignature);
 					}
 					result.addParameter(param);
-					if(newParams.length() > 0) newParams.append(',');
 					newParams.append(param.getSignature());
 				}
 				if(!context.isBinary()) {
-					result.setSignature(result.getArrayPrefix() + "Q" + resovedTypeName + '<' + newParams + '>' + ';');
+					StringBuffer ns = new StringBuffer();
+					ns.append(result.getArrayPrefix());
+					if(result.isLower()) ns.append('-');
+					if(result.isUpper()) ns.append('+');
+					ns.append('Q').append(resovedTypeName).append('<').append(newParams).append(">;");
+					result.setSignature(ns.toString());
 				}
 				cache.put(key, result);
 				return result;
@@ -146,6 +178,40 @@
 		return null;
 	}
 
+	public ParametedType getParametedTypeForParameter(IMember context, String typeParameterSignature, ParametedType result) throws JavaModelException {
+		IType contextType = context instanceof IType ? (IType)context : context.getDeclaringType();
+		String key = context == null ? typeParameterSignature : contextType.getFullyQualifiedName() + "+" + typeParameterSignature;
+
+		String t = typeParameterSignature;
+		int q = t.indexOf(":");
+		if(q >= 0) {
+			t = t.substring(0, q);
+		}
+		t = "Q" + t + ";";
+		if(result == null || t.equals(result.getSignature())) {
+			if(q >= 0) {
+				String sts = typeParameterSignature.substring(q + 1);
+				if(sts.length() > 0) {
+					ParametedType st = getParametedType(contextType, sts);
+					if(st != null) {
+						result = new TypeDeclaration(st, 0, 0);
+					}
+				} else if(result != null) {
+					result.setSignature(t);
+				}
+			}
+			if(result == null) {
+				result = new ParametedType();
+				result.setFactory(this);
+				result.setSignature(t);
+			}
+			result.setVariable(true);
+			cache.put(key, result);
+			return result;
+		}
+		return null;
+	}
+
 	public void clean() {
 		cache.clear();
 	}



More information about the jbosstools-commits mailing list