use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class MethodOverrideTester method getMethodSubstitions.
/*
* Returns the substitutions for a method's type parameters
*/
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException {
if (fMethodSubstitutions == null) {
fMethodSubstitutions = new LRUMap<IMethod, Substitutions>(3);
}
Substitutions s = fMethodSubstitutions.get(method);
if (s == null) {
ITypeParameter[] typeParameters = method.getTypeParameters();
if (typeParameters.length == 0) {
s = Substitutions.EMPTY_SUBST;
} else {
IType instantiatedType = method.getDeclaringType();
s = new Substitutions();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter curr = typeParameters[i];
s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType));
}
}
fMethodSubstitutions.put(method, s);
}
return s;
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class SourceMapper method enterType.
/**
* @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
*/
public void enterType(TypeInfo typeInfo) {
this.typeDepth++;
if (this.typeDepth == this.types.length) {
// need to grow
System.arraycopy(this.types, 0, this.types = new IType[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.typeNameRanges, 0, this.typeNameRanges = new SourceRange[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.typeDeclarationStarts, 0, this.typeDeclarationStarts = new int[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberName, 0, this.memberName = new String[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberDeclarationStart, 0, this.memberDeclarationStart = new int[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberNameRange, 0, this.memberNameRange = new SourceRange[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.methodParameterTypes, 0, this.methodParameterTypes = new char[this.typeDepth * 2][][], 0, this.typeDepth);
System.arraycopy(this.methodParameterNames, 0, this.methodParameterNames = new char[this.typeDepth * 2][][], 0, this.typeDepth);
System.arraycopy(this.typeModifiers, 0, this.typeModifiers = new int[this.typeDepth * 2], 0, this.typeDepth);
}
if (typeInfo.name.length == 0) {
this.anonymousCounter++;
if (this.anonymousCounter == this.anonymousClassName) {
this.types[this.typeDepth] = getType(this.binaryType.getElementName());
} else {
this.types[this.typeDepth] = getType(new String(typeInfo.name));
}
} else {
this.types[this.typeDepth] = getType(new String(typeInfo.name));
}
this.typeNameRanges[this.typeDepth] = new SourceRange(typeInfo.nameSourceStart, typeInfo.nameSourceEnd - typeInfo.nameSourceStart + 1);
this.typeDeclarationStarts[this.typeDepth] = typeInfo.declarationStart;
IType currentType = this.types[this.typeDepth];
// type parameters
if (typeInfo.typeParameters != null) {
for (int i = 0, length = typeInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = typeInfo.typeParameters[i];
ITypeParameter typeParameter = currentType.getTypeParameter(new String(typeParameterInfo.name));
setSourceRange(typeParameter, new SourceRange(typeParameterInfo.declarationStart, typeParameterInfo.declarationEnd - typeParameterInfo.declarationStart + 1), new SourceRange(typeParameterInfo.nameSourceStart, typeParameterInfo.nameSourceEnd - typeParameterInfo.nameSourceStart + 1));
}
}
// type modifiers
this.typeModifiers[this.typeDepth] = typeInfo.modifiers;
// categories
addCategories(currentType, typeInfo.categories);
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class SourceMapper method enterAbstractMethod.
private void enterAbstractMethod(MethodInfo methodInfo) {
if (this.typeDepth >= 0) {
this.memberName[this.typeDepth] = new String(methodInfo.name);
this.memberNameRange[this.typeDepth] = new SourceRange(methodInfo.nameSourceStart, methodInfo.nameSourceEnd - methodInfo.nameSourceStart + 1);
this.memberDeclarationStart[this.typeDepth] = methodInfo.declarationStart;
IType currentType = this.types[this.typeDepth];
int currenTypeModifiers = this.typeModifiers[this.typeDepth];
char[][] parameterTypes = methodInfo.parameterTypes;
if (methodInfo.isConstructor && currentType.getDeclaringType() != null && !Flags.isStatic(currenTypeModifiers)) {
IType declaringType = currentType.getDeclaringType();
String declaringTypeName = declaringType.getElementName();
if (declaringTypeName.length() == 0) {
IClassFile classFile = declaringType.getClassFile();
int length = parameterTypes != null ? parameterTypes.length : 0;
char[][] newParameterTypes = new char[length + 1][];
declaringTypeName = classFile.getElementName();
declaringTypeName = declaringTypeName.substring(0, declaringTypeName.indexOf('.'));
newParameterTypes[0] = declaringTypeName.toCharArray();
if (length != 0) {
System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
}
this.methodParameterTypes[this.typeDepth] = newParameterTypes;
} else {
int length = parameterTypes != null ? parameterTypes.length : 0;
char[][] newParameterTypes = new char[length + 1][];
newParameterTypes[0] = declaringTypeName.toCharArray();
if (length != 0) {
System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
}
this.methodParameterTypes[this.typeDepth] = newParameterTypes;
}
} else {
this.methodParameterTypes[this.typeDepth] = parameterTypes;
}
this.methodParameterNames[this.typeDepth] = methodInfo.parameterNames;
IMethod method = currentType.getMethod(this.memberName[this.typeDepth], convertTypeNamesToSigs(this.methodParameterTypes[this.typeDepth]));
// type parameters
if (methodInfo.typeParameters != null) {
for (int i = 0, length = methodInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = methodInfo.typeParameters[i];
ITypeParameter typeParameter = method.getTypeParameter(new String(typeParameterInfo.name));
setSourceRange(typeParameter, new SourceRange(typeParameterInfo.declarationStart, typeParameterInfo.declarationEnd - typeParameterInfo.declarationStart + 1), new SourceRange(typeParameterInfo.nameSourceStart, typeParameterInfo.nameSourceEnd - typeParameterInfo.nameSourceStart + 1));
}
}
// parameters infos
if (methodInfo.parameterInfos != null) {
for (int i = 0, length = methodInfo.parameterInfos.length; i < length; i++) {
ParameterInfo parameterInfo = methodInfo.parameterInfos[i];
LocalVariableElementKey key = new LocalVariableElementKey(method, new String(parameterInfo.name));
SourceRange[] allRanges = new SourceRange[] { new SourceRange(parameterInfo.declarationStart, parameterInfo.declarationEnd - parameterInfo.declarationStart + 1), new SourceRange(parameterInfo.nameSourceStart, parameterInfo.nameSourceEnd - parameterInfo.nameSourceStart + 1) };
this.parametersRanges.put(key, allRanges);
if (parameterInfo.modifiers != 0) {
if (this.finalParameters == null) {
this.finalParameters = new HashSet();
}
this.finalParameters.add(key);
}
}
}
// categories
addCategories(method, methodInfo.categories);
}
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class LazyGenericTypeProposal method computeTypeArgumentProposals.
/**
* Computes the type argument proposals for this type proposals. If there is
* an expected type binding that is a super type of the proposed type, the
* wildcard type arguments of the proposed type that can be mapped through
* to type the arguments of the expected type binding are bound accordingly.
* <p>
* For type arguments that cannot be mapped to arguments in the expected
* type, or if there is no expected type, the upper bound of the type
* argument is proposed.
* </p>
* <p>
* The argument proposals have their <code>isAmbiguos</code> flag set to
* <code>false</code> if the argument can be mapped to a non-wildcard type
* argument in the expected type, otherwise the proposal is ambiguous.
* </p>
*
* @return the type argument proposals for the proposed type
* @throws org.eclipse.jdt.core.JavaModelException if accessing the java model fails
*/
private TypeArgumentProposal[] computeTypeArgumentProposals() throws JavaModelException {
if (fTypeArgumentProposals == null) {
IType type = (IType) getJavaElement();
if (type == null)
return new TypeArgumentProposal[0];
ITypeParameter[] parameters = type.getTypeParameters();
if (parameters.length == 0)
return new TypeArgumentProposal[0];
TypeArgumentProposal[] arguments = new TypeArgumentProposal[parameters.length];
ITypeBinding expectedTypeBinding = getExpectedType();
if (expectedTypeBinding != null && expectedTypeBinding.isParameterizedType()) {
// in this case, the type arguments we propose need to be compatible
// with the corresponding type parameters to declared type
IType expectedType = (IType) expectedTypeBinding.getJavaElement();
IType[] path = computeInheritancePath(type, expectedType);
if (path == null)
// to instantiate -> do not add any type arguments
return new TypeArgumentProposal[0];
int[] indices = new int[parameters.length];
for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
indices[paramIdx] = mapTypeParameterIndex(path, path.length - 1, paramIdx);
}
// for type arguments that are mapped through to the expected type's
// parameters, take the arguments of the expected type
ITypeBinding[] typeArguments = expectedTypeBinding.getTypeArguments();
for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
if (indices[paramIdx] != -1) {
// type argument is mapped through
ITypeBinding binding = typeArguments[indices[paramIdx]];
arguments[paramIdx] = computeTypeProposal(binding, parameters[paramIdx]);
}
}
}
// take the lower bound of the type parameter
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] == null) {
arguments[i] = computeTypeProposal(parameters[i]);
}
}
fTypeArgumentProposals = arguments;
}
return fTypeArgumentProposals;
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class StubCreator method appendTypeParameters.
protected void appendTypeParameters(final ITypeParameter[] parameters) throws JavaModelException {
final int length = parameters.length;
if (length > 0)
//$NON-NLS-1$
fBuffer.append("<");
for (int index = 0; index < length; index++) {
if (index > 0)
//$NON-NLS-1$
fBuffer.append(",");
final ITypeParameter parameter = parameters[index];
fBuffer.append(parameter.getElementName());
final String[] bounds = parameter.getBounds();
final int size = bounds.length;
if (size > 0)
//$NON-NLS-1$
fBuffer.append(" extends ");
for (int offset = 0; offset < size; offset++) {
if (offset > 0)
//$NON-NLS-1$
fBuffer.append(" & ");
fBuffer.append(bounds[offset]);
}
}
if (length > 0)
//$NON-NLS-1$
fBuffer.append(">");
}
Aggregations