Author: scabanovich
Date: 2011-06-29 17:10:24 -0400 (Wed, 29 Jun 2011)
New Revision: 32463
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/IParametedType.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ITypeDeclaration.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/TypeDeclaration.java
Log:
JBIDE-5046
https://issues.jboss.org/browse/JBIDE-5046
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/IParametedType.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/IParametedType.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/IParametedType.java 2011-06-29
21:10:24 UTC (rev 32463)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.java;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.IType;
+
+/**
+ * Represents a wrapper for IType object which could be parameted.
+ * For example if we have some method
+ * List<String> getList() {...}
+ * then IParametedType for return type of this method will wrap List<> and its
signature.
+ */
+public interface IParametedType {
+
+ /**
+ * Returns the corresponding IType of the declaration. May be null.
+ *
+ * @return the corresponding IType of the declaration.
+ */
+ IType getType();
+
+ /**
+ * Returns signature of the declaration.
+ *
+ * @return signature of the declaration
+ */
+ public String getSignature();
+
+ /**
+ * Returns true if the type is a primitive type.
+ *
+ * @return true if the type is a primitive type
+ */
+ boolean isPrimitive();
+
+ /**
+ * Returns the simple name of the type. In case of IType this method will return the
short name of the type.
+ * If this type is primitive then the method will return the name of the primitive
type.
+ *
+ * @return the simple name of the type.
+ */
+ String getSimpleName();
+
+ /**
+ * Returns type parameters
+ *
+ * @return type parameters
+ */
+ List<? extends IParametedType> getParameters();
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/IParametedType.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ITypeDeclaration.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ITypeDeclaration.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ITypeDeclaration.java 2011-06-29
21:10:24 UTC (rev 32463)
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.java;
+
+import org.jboss.tools.common.text.ITextSourceReference;
+
+/**
+ * @author Alexey Kazakov
+ */
+public interface ITypeDeclaration extends IParametedType, ITextSourceReference {
+
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ITypeDeclaration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java 2011-06-29
21:10:24 UTC (rev 32463)
@@ -0,0 +1,383 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.java;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jdt.core.ISourceRange;
+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.common.CommonPlugin;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class ParametedType implements IParametedType {
+ protected ParametedTypeFactory typeFactory = null;
+ protected IType type;
+ protected String arrayPrefix = "";
+ protected String signature;
+ 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>();
+ Set<IParametedType> allInheritedTypes = null;
+
+ public static interface PositionProvider {
+ ISourceRange getRange(String superTypeName);
+ }
+
+ PositionProvider provider = null;
+
+ public ParametedType() {}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IParametedType#isPrimitive()
+ */
+ public boolean isPrimitive() {
+ return primitive;
+ }
+
+ public void setPrimitive(boolean primitive) {
+ 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;
+ }
+
+ public void setFactory(ParametedTypeFactory typefactory) {
+ this.typeFactory = typefactory;
+ }
+
+ public IType getType() {
+ return type;
+ }
+
+ public String getArrayPrefix() {
+ return arrayPrefix;
+ }
+
+ public String getSignature() {
+ return signature;
+ }
+
+ public void setType(IType type) {
+ this.type = type;
+ }
+
+ public void setSignature(String signature) {
+ this.signature = signature;
+ arrayPrefix = "";
+ if(signature != null) {
+ for (int i = 0; i < signature.length(); i++) {
+ if(signature.charAt(i) == '[') arrayPrefix += "["; else break;
+ }
+ }
+ }
+
+ public void addParameter(ParametedType p) {
+ parameterTypes.add(p);
+ }
+
+ public List<? extends IParametedType> getParameters() {
+ return parameterTypes;
+ }
+
+ public void setPositionProvider(PositionProvider p) {
+ provider = p;
+ }
+
+ public boolean equals(Object object) {
+ if(!(object instanceof ParametedType)) return false;
+ ParametedType other = (ParametedType)object;
+ if(signature != null && signature.equals(other.signature)) {
+ return true;
+ }
+ if(type == null || other.type == null ||
!type.getFullyQualifiedName().equals(other.type.getFullyQualifiedName())) {
+ return false;
+ }
+ if(parameterTypes.size() != other.parameterTypes.size()) {
+ return false;
+ }
+ for (int i = 0; i < parameterTypes.size(); i++) {
+ if(!parameterTypes.get(i).equals(other.parameterTypes.get(i))) {
+ return false;
+ }
+ }
+ if(!arrayPrefix.equals(other.arrayPrefix)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ void buildInheritance() {
+ if(type == null) return;
+ Set<IParametedType> inheritedTypes = new HashSet<IParametedType>();
+ try {
+ if(!type.isInterface() && !type.isAnnotation()) {
+ String sc = type.getSuperclassTypeSignature();
+ boolean objectArray = false;
+ if(sc != null) {
+ try {
+ sc = resolveParameters(sc);
+ } catch (Exception e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ } else if(!"java.lang.Object".equals(type.getFullyQualifiedName())) {
+ sc = ParametedTypeFactory.OBJECT;
+ } else if("java.lang.Object".equals(type.getFullyQualifiedName())
&& arrayPrefix.length() > 0) {
+ objectArray = true;
+ sc = ParametedTypeFactory.OBJECT;
+ }
+ if(!objectArray && arrayPrefix.length() > 0) {
+ sc = arrayPrefix + sc;
+ }
+
+ superType = getFactory().getParametedType(type, sc);
+ if(superType != null) {
+ if(provider != null) {
+ String scn = type.getSuperclassName();
+ if(scn != null && provider.getRange(scn) != null) {
+ ISourceRange r = provider.getRange(scn);
+ superType = new TypeDeclaration(superType, type.getResource(), r.getOffset(),
r.getLength());
+ }
+
+ }
+ inheritedTypes.add(superType);
+ }
+ }
+ String[] is = type.getSuperInterfaceTypeSignatures();
+ if(is != null) for (int i = 0; i < is.length; i++) {
+ String p = resolveParameters(is[i]);
+ if(arrayPrefix.length() > 0) p = arrayPrefix + p;
+ ParametedType t = getFactory().getParametedType(type, p);
+ if(t != null) {
+ if(provider != null) {
+ String scn = type.getSuperInterfaceNames()[i];
+ if(scn != null && provider.getRange(scn) != null) {
+ ISourceRange r = provider.getRange(scn);
+ t = new TypeDeclaration(t, type.getResource(), r.getOffset(), r.getLength());
+ }
+
+ }
+ inheritedTypes.add(t);
+ }
+ }
+ } catch (JavaModelException e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ this.inheritedTypes = inheritedTypes;
+ inheritanceIsBuilt = true;
+ }
+
+ 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.startsWith("L"))
&& 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;
+ }
+ boolean replaced = false;
+ StringBuffer newParams = new StringBuffer();
+ String[] ps = Signature.getTypeArguments(typeSignature);
+ for (String param: ps) {
+ String newParam = resolveParameters( param);
+ if(!param.equals(newParam)) replaced = true;
+ 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;
+ }
+
+ public Set<IParametedType> getAllTypes() {
+ if(allInheritedTypes == null) {
+ allInheritedTypes = buildAllTypes(new HashSet<String>(), this, new
HashSet<IParametedType>());
+ }
+ return allInheritedTypes;
+ }
+
+ Set<IParametedType> buildAllTypes(Set<String> processed, ParametedType p,
Set<IParametedType> types) {
+ IType t = p.getType();
+ if(t != null) {
+ String key = p.getArrayPrefix() + t.getFullyQualifiedName();
+ if(!processed.contains(key)) {
+ processed.add(key);
+ types.add(p);
+ Set<IParametedType> ts = p.getInheritedTypes();
+ if(ts != null) for (IParametedType pp: ts) {
+ buildAllTypes(processed, (ParametedType)pp, types);
+ }
+ }
+ }
+ return types;
+ }
+
+ public String toString() {
+ 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;
+ }
+
+ static Map<String, String> primitives = new HashMap<String, String>();
+ static {
+ primitives.put("Integer", "int");
+ primitives.put("Short", "short");
+ primitives.put("Long", "long");
+ primitives.put("Character", "char");
+ primitives.put("Float", "float");
+ primitives.put("Double", "double");
+ primitives.put("Boolean", "boolean");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IParametedType#getSimpleName()
+ */
+ public String getSimpleName() {
+ if(getSignature()!=null) {
+ return
isPrimitive()?primitives.get(Signature.getSignatureSimpleName(getSignature())):Signature.getSignatureSimpleName(getSignature());
+ }
+ return "";
+ }
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java 2011-06-29
21:10:24 UTC (rev 32463)
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.java;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+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.common.CommonPlugin;
+import org.jboss.tools.common.util.EclipseJavaUtil;
+
+public class ParametedTypeFactory {
+ // I S J C F D Z
+ static HashMap<String,String> primitives = new HashMap<String, String>();
+ static {
+ primitives.put("I", "Ljava.lang.Integer;");
+ primitives.put("S", "Ljava.lang.Short;");
+ primitives.put("J", "Ljava.lang.Long;");
+ primitives.put("C", "Ljava.lang.Character;");
+ primitives.put("F", "Ljava.lang.Float;");
+ primitives.put("D", "Ljava.lang.Double;");
+ primitives.put("Z", "Ljava.lang.Boolean;");
+ }
+ //unresolved Object signature
+ public static String OBJECT = "QObject;";
+ Map<String, ParametedType> cache = new HashMap<String, ParametedType>();
+
+ public ParametedType newParametedType(IType type) {
+ ParametedType parametedType = new ParametedType();
+ if(type != null && !type.isBinary()) {
+ ISourceRange r = null;
+ try {
+ r = type.getNameRange();
+ } catch (CoreException e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ if(r != null) {
+ parametedType = new TypeDeclaration(parametedType, type.getResource(), r.getOffset(),
r.getLength());
+ }
+ }
+ parametedType.setFactory(this);
+ parametedType.setType(type);
+ if(type != null) parametedType.setSignature("L" +
type.getFullyQualifiedName() + ";");
+ String[] ps = null;
+ try {
+ ps = type.getTypeParameterSignatures();
+ } catch (JavaModelException e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ 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) {
+ CommonPlugin.getDefault().logError(e);
+ } catch (Exception ee) {
+ CommonPlugin.getDefault().logError(ee);
+ }
+
+ }
+ }
+ return parametedType;
+ }
+
+ public ParametedType getParametedType(IMember context, String typeSignature) throws
JavaModelException {
+ if(typeSignature == null) return null;
+
+ IType contextType = context instanceof IType ? (IType)context :
context.getDeclaringType();
+
+ String key = context == null || context.isBinary() || OBJECT.equals(typeSignature) ?
typeSignature : contextType.getFullyQualifiedName() + "+" + typeSignature;
+ if(cache.containsKey(key)) return cache.get(key);
+ ParametedType result = new ParametedType();
+ result.setFactory(this);
+ result.setSignature(typeSignature);
+
+ typeSignature = typeSignature.substring(result.getArrayPrefix().length());
+
+ if(primitives.containsKey(typeSignature)) {
+ 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()) {
+ StringBuffer ns = new StringBuffer();
+ ns.append(result.getArrayPrefix());
+ if(result.isLower()) ns.append('-');
+ if(result.isUpper()) ns.append('+');
+ ns.append('L').append(resovedTypeName).append(";");
+ result.setSignature(ns.toString());
+ }
+ IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
+ if(type != null) {
+ result.setType(type);
+ cache.put(key, result);
+ return result;
+ }
+ if(context instanceof IMethod) {
+ String[] ps = ((IMethod)context).getTypeParameterSignatures();
+ for (int i = 0; i < ps.length; i++) {
+ ParametedType st = getParametedTypeForParameter(context, ps[i], result);
+ if(st != null) {
+ if(st.getSignature().indexOf(':') >= 0) {
+ CommonPlugin.getDefault().logWarning("Wrong signature=" +
st.getSignature());
+ }
+ return st;
+ }
+ }
+ }
+ String[] ps = contextType.getTypeParameterSignatures();
+ for (int i = 0; i < ps.length; i++) {
+ 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 resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeName);
+ if(resovedTypeName == null) return null;
+ IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
+ if(type != null) {
+ result.setType(type);
+ cache.put(key, result);
+ StringBuffer newParams = new StringBuffer();
+ String[] paramSignatures = null;
+ try {
+ paramSignatures = Signature.getTypeArguments(typeSignature);
+ } catch (Exception e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ if(paramSignatures != null) for (String paramSignature: paramSignatures) {
+ ParametedType param = getParametedType(context, paramSignature);
+ if(param == null) {
+ param = new ParametedType();
+ param.setSignature(paramSignature);
+ }
+ result.addParameter(param);
+ newParams.append(param.getSignature());
+ }
+ if(!context.isBinary()) {
+ StringBuffer ns = new StringBuffer();
+ ns.append(result.getArrayPrefix());
+ if(result.isLower()) ns.append('-');
+ if(result.isUpper()) ns.append('+');
+ ns.append('L').append(resovedTypeName).append('<').append(newParams).append(">;");
+ result.setSignature(ns.toString());
+ }
+ return result;
+ }
+ }
+ 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 = Signature.getTypeVariable(typeParameterSignature);
+ String[] bounds = Signature.getTypeParameterBounds(typeParameterSignature);
+
+ t = "L" + t + ";";
+ if(result == null || t.equals(result.getSignature())) {
+ String sts = bounds.length > 0 ? bounds[0] : "";
+ if(sts.length() > 0) {
+ ParametedType st = getParametedType(contextType, sts);
+ if(st != null) {
+ result = new TypeDeclaration(st, context.getResource(), 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();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/TypeDeclaration.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/TypeDeclaration.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/TypeDeclaration.java 2011-06-29
21:10:24 UTC (rev 32463)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.java;
+
+import org.eclipse.core.resources.IResource;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class TypeDeclaration extends ParametedType implements ITypeDeclaration {
+ IResource resource;
+ int length;
+ int startPosition;
+
+ public TypeDeclaration(ParametedType type, IResource resource, int startPosition, int
length) {
+ this.setFactory(type.getFactory());
+ this.type = type.getType();
+ arrayPrefix = type.arrayPrefix;
+ this.resource = resource;
+ this.length = length;
+ this.startPosition = startPosition;
+
+ signature = type.signature;
+ parameterTypes = type.parameterTypes;
+
+ allInheritedTypes = type.allInheritedTypes;
+ inheritanceIsBuilt = type.inheritanceIsBuilt;
+ inheritedTypes = type.inheritedTypes;
+ superType = type.superType;
+ primitive = type.primitive;
+
+ isLower = type.isLower;
+ isUpper = type.isUpper;
+ isVariable = type.isVariable;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public int getStartPosition() {
+ return startPosition;
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/TypeDeclaration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain