Author: scabanovich
Date: 2010-01-28 10:36:07 -0500 (Thu, 28 Jan 2010)
New Revision: 19990
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
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/ParametedType.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.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/impl/definition/ParametedTypeFactory.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3125
Improved getLegalTypes and building super types for types with parameters
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -37,8 +37,11 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeParameter;
import org.jboss.tools.cdi.internal.core.impl.CDIAnnotationElement;
+import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationHelper;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
import org.jboss.tools.cdi.internal.core.scanner.CDIBuilderDelegate;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
import org.jboss.tools.common.EclipseUtil;
@@ -99,6 +102,22 @@
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException {
+
+
+ IType t = EclipseJavaUtil.findType(EclipseResourceUtil.getJavaProject(getProject()),
"pack.model.A2");
+ ParametedType p = new ParametedType();
+ p.setType(t);
+ p.setSignature("Q" + t.getFullyQualifiedName() + ";");
+
+ for (IParametedType c: p.getInheritedTypes()) {
+ Set<IParametedType> s = ((ParametedType)c).getInheritedTypes();
+ for (IParametedType d: s) {
+ ((ParametedType)d).getInheritedTypes();
+ };
+ };
+
+
+
resourceVisitor = null;
findDelegate();
if(getDelegate() == null) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -123,6 +123,7 @@
Object[] os = (Object[])value;
for (int i = 0; i < os.length; i++) {
String typeName = os[i].toString();
+ if(!typeName.endsWith(";")) typeName = "Q" + typeName +
";";
ParametedType p =
ParametedTypeFactory.getParametedType(((IMember)definition.getMember()).getDeclaringType(),
typeName);
if(p != null) {
result.add(new TypeDeclaration(p, -1, 0));
@@ -130,6 +131,7 @@
}
} else if(value != null) {
String typeName = value.toString();
+ if(!typeName.endsWith(";")) typeName = "Q" + typeName +
";";
ParametedType p =
ParametedTypeFactory.getParametedType(((IMember)definition.getMember()).getDeclaringType(),
typeName);
if(p != null) {
result.add(new TypeDeclaration(p, -1, 0));
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 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -229,6 +229,11 @@
public Set<IParametedType> getLegalTypes() {
Set<IParametedType> result = new HashSet<IParametedType>();
AnnotationDeclaration d = getDefinition().getTypedAnnotation();
+ if(d != null) {
+ Set<ITypeDeclaration> ts = getRestrictedTypeDeclaratios();
+ result.addAll(ts);
+ return result;
+ }
IType type = getDefinition().getType();
if(type != null) {
ParametedType p = new ParametedType();
@@ -236,7 +241,7 @@
String[] ps = null;
try {
ps = type.getTypeParameterSignatures();
- p.setSignature(type.getFullyQualifiedName());
+ p.setSignature("Q" + type.getFullyQualifiedName() + ',');
} catch (CoreException e) {
//TODO
}
@@ -247,29 +252,6 @@
}
Set<IParametedType> inh = getDefinition().getAllInheritedTypes();
if(inh != null) result.addAll(inh);
- if(d != null) {
- try {
- Set<IParametedType> reducedResult = new HashSet<IParametedType>();
- IMemberValuePair[] ps = d.getDeclaration().getMemberValuePairs();
- if(ps != null) for (IMemberValuePair p: ps) {
- Object o = p.getValue();
- if(o instanceof Object[]) {
- Object[] os = (Object[])o;
- for (int i = 0; i < os.length; i++) {
- String s = os[i].toString();
- if(!s.endsWith(";")) s = "Q" + s + ";";
- IParametedType t =
ParametedTypeFactory.getParametedType(getDefinition().getType(), s);
- if(CDIProject.containsType(result, t)) {
- reducedResult.add(t);
- }
- }
- }
- }
- result = reducedResult;
- } catch (CoreException e) {
- //TODO
- }
- }
return result;
}
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-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ParametedType.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -11,10 +11,17 @@
package org.jboss.tools.cdi.internal.core.impl;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeParameter;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IParametedType;
+import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
/**
*
@@ -26,6 +33,10 @@
protected String signature;
protected List<ParametedType> parameterTypes = new
ArrayList<ParametedType>();
+ boolean inheritanceIsBuilt = false;
+ protected ParametedType superType = null;
+ protected Set<IParametedType> inheritedTypes = new
HashSet<IParametedType>();
+
public ParametedType() {}
public IType getType() {
@@ -58,4 +69,100 @@
return false;
}
+ void buildInheritance() {
+ inheritanceIsBuilt = true;
+ if(type == null) return;
+ try {
+ if(!type.isInterface() && !type.isAnnotation()) {
+ String sc = type.getSuperclassTypeSignature();
+ if(sc != null) {
+ sc = resolveParameters(sc);
+ }
+ superType = ParametedTypeFactory.getParametedType(type, sc);
+ if(superType != null) {
+ inheritedTypes.add(superType);
+ }
+ }
+ String[] is = type.getSuperInterfaceTypeSignatures();
+ if(is != null) for (int i = 0; i < is.length; i++) {
+ String p = resolveParameters(is[i]);
+ ParametedType t = ParametedTypeFactory.getParametedType(type, p);
+ if(t != null) {
+ inheritedTypes.add(t);
+ }
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+
+ public ParametedType getSuperType() {
+ if(!inheritanceIsBuilt) {
+ buildInheritance();
+ }
+ return superType;
+ }
+
+ public Set<IParametedType> getInheritedTypes() {
+ if(!inheritanceIsBuilt) {
+ buildInheritance();
+ }
+ return inheritedTypes;
+ }
+
+ public String resolveParameters(String typeSignature) {
+ if(typeSignature == null) {
+ return typeSignature;
+ }
+ int i = typeSignature.indexOf('<');
+ if(i < 0) {
+ if(( typeSignature.startsWith("T") ||
typeSignature.startsWith("Q")) && typeSignature.endsWith(";"))
{
+ String param = typeSignature.substring(1, typeSignature.length() - 1);
+ String s = findParameterSignature(param);
+ return s == null ? typeSignature : s;
+ }
+ return typeSignature;
+ }
+ int j = typeSignature.lastIndexOf('>');
+ 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 newParam = resolveParameters( param);
+ if(!param.equals(newParam)) replaced = true;
+ if(newParam.length() == 0) newParams.append(',');
+ newParams.append(newParam);
+ }
+ if(replaced) {
+ typeSignature = typeSignature.substring(0, i) + '<' + newParams.toString()
+ '>' + ';';
+ }
+ return typeSignature;
+ }
+
+ public String findParameterSignature(String paramName) {
+ if(type == null) {
+ return null;
+ }
+ ITypeParameter[] ps = null;
+ try {
+ ps = type.getTypeParameters();
+ } catch (JavaModelException e) {
+ return null;
+ }
+ if(ps != null) for (int i = 0; i < ps.length; i++) {
+ if(ps[i].getElementName().equals(paramName)) {
+ if(parameterTypes.size() > i) {
+ ParametedType p = parameterTypes.get(i);
+ return p.getSignature();
+ }
+ }
+ }
+ return null;
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -66,7 +66,16 @@
public Set<IParametedType> getLegalTypes() {
Set<IParametedType> result = new HashSet<IParametedType>();
- if(typeDeclaration != null) result.add(typeDeclaration);
+ AnnotationDeclaration d = getDefinition().getTypedAnnotation();
+ if(d != null) {
+ Set<ITypeDeclaration> ts = getRestrictedTypeDeclaratios();
+ result.addAll(ts);
+ return result;
+ }
+ if(typeDeclaration != null) {
+ result.add(typeDeclaration);
+ //TODO add all inherited types
+ }
return result;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -76,7 +76,16 @@
public Set<IParametedType> getLegalTypes() {
Set<IParametedType> result = new HashSet<IParametedType>();
- if(typeDeclaration != null) result.add(typeDeclaration);
+ AnnotationDeclaration d = getDefinition().getTypedAnnotation();
+ if(d != null) {
+ Set<ITypeDeclaration> ts = getRestrictedTypeDeclaratios();
+ result.addAll(ts);
+ return result;
+ }
+ if(typeDeclaration != null) {
+ result.add(typeDeclaration);
+ //TODO add all inherited types
+ }
return result;
}
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 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractTypeDefinition.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -17,8 +17,6 @@
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
-import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
/**
*
@@ -28,10 +26,10 @@
public class AbstractTypeDefinition extends AbstractMemberDefinition {
protected String qualifiedName;
protected IType type;
- protected ParametedType superType = null;
- protected Set<IParametedType> inheritedTypes = new
HashSet<IParametedType>();
- protected Set<IParametedType> allInheritedTypes = new
HashSet<IParametedType>();
+ protected ParametedType parametedType = null;
+ Set<IParametedType> allInheritedTypes = null;
+
public AbstractTypeDefinition() {}
public String getQualifiedName() {
@@ -51,45 +49,32 @@
this.type = contextType;
super.init(contextType, context);
qualifiedName = getType().getFullyQualifiedName();
- if(!type.isInterface() && !type.isAnnotation()) {
- String sc = type.getSuperclassTypeSignature();
- superType = ParametedTypeFactory.getParametedType(type, sc);
- if(superType != null) inheritedTypes.add(superType);
- }
- String[] is = type.getSuperInterfaceTypeSignatures();
- if(is != null) for (int i = 0; i < is.length; i++) {
- ParametedType t = ParametedTypeFactory.getParametedType(type, is[i]);
- if(t != null) inheritedTypes.add(t);
- }
- buildAllInheritedTypes(new HashSet<String>(), inheritedTypes);
+ parametedType = new ParametedType();
+ parametedType.setType(this.type);
+ parametedType.setSignature("Q" + qualifiedName + ";");
}
- void buildAllInheritedTypes(Set<String> processed, Set<IParametedType>
addition) throws CoreException {
- for (IParametedType p: addition) {
- IType t = p.getType();
- if(t == null) continue;
- if(processed.contains(t.getFullyQualifiedName())) continue;
- allInheritedTypes.add(p);
- Set<IParametedType> add = new HashSet<IParametedType>();
- if(!t.isInterface() && !t.isAnnotation()) {
- String sc = t.getSuperclassTypeSignature();
- IParametedType st = ParametedTypeFactory.getParametedType(t, sc);
- if(st != null) add.add(st);
- }
- String[] is = t.getSuperInterfaceTypeSignatures();
- if(is != null) for (int i = 0; i < is.length; i++) {
- ParametedType t1 = ParametedTypeFactory.getParametedType(t, is[i]);
- if(t1 != null) add.add(t1);
- }
- buildAllInheritedTypes(processed, add);
+ void buildAllInheritedTypes(Set<String> processed, ParametedType p) {
+ IType t = p.getType();
+ if(t == null) return;
+ if(processed.contains(t.getFullyQualifiedName())) return;
+ processed.add(t.getFullyQualifiedName());
+ allInheritedTypes.add(p);
+ Set<IParametedType> ts = p.getInheritedTypes();
+ if(ts != null) for (IParametedType pp: ts) {
+ buildAllInheritedTypes(processed, (ParametedType)pp);
}
}
public Set<IParametedType> getInheritedTypes() {
- return inheritedTypes;
+ return parametedType == null ? new HashSet<IParametedType>() :
parametedType.getInheritedTypes();
}
public Set<IParametedType> getAllInheritedTypes() {
+ if(allInheritedTypes == null) {
+ Set<String> processed = new HashSet<String>();
+ buildAllInheritedTypes(processed, parametedType);
+ }
return allInheritedTypes;
}
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-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -17,7 +17,7 @@
if(startToken < 0) {
String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(context, typeSignature);
if(resovedTypeName == null) return null;
- result.setSignature(resovedTypeName);
+ result.setSignature("Q" + resovedTypeName + ";");
IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
if(type != null) {
result.setType(type);
@@ -33,7 +33,7 @@
IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
if(type != null) {
result.setType(type);
- result.setSignature(resovedTypeName + '<' + params + '>');
+ StringBuffer newParams = new StringBuffer();
StringTokenizer st = new StringTokenizer(params, ",");
while(st.hasMoreTokens()) {
String paramSignature = st.nextToken();
@@ -43,10 +43,14 @@
param.setSignature(paramSignature);
}
result.addParameter(param);
+ if(newParams.length() > 0) newParams.append(',');
+ newParams.append(param.getSignature());
}
+ result.setSignature("Q" + resovedTypeName + '<' + newParams +
'>' + ';');
return result;
}
}
return null;
}
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java 2010-01-28
14:42:51 UTC (rev 19989)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java 2010-01-28
15:36:07 UTC (rev 19990)
@@ -62,7 +62,7 @@
}
public ParametedType getSuperType() {
- return superType;
+ return parametedType == null ? null : parametedType.getSuperType();
}
public List<FieldDefinition> getFields() {