use of com.helger.jcodemodel.JTypeWildcard in project adt4j by sviperll.
the class Source method substitute.
public static AbstractJType substitute(AbstractJType type, JTypeVar typeVariable, AbstractJType variableValue) {
if (type == typeVariable)
return variableValue;
else if (!(type instanceof AbstractJClass)) {
return type;
} else {
if (type.isArray())
return substitute(type.elementType(), typeVariable, variableValue).array();
else if (type instanceof JTypeWildcard) {
JTypeWildcard wildcard = (JTypeWildcard) type;
AbstractJClass bound = (AbstractJClass) substitute(wildcard.bound(), typeVariable, variableValue);
return bound.wildcard(wildcard.boundMode());
} else {
/*
* When we get type with type-parameters we should substitute
* type-parameters.
*/
AbstractJClass genericType = (AbstractJClass) type;
if (genericType.getTypeParameters().isEmpty()) {
return genericType;
} else {
AbstractJClass result = genericType.erasure();
for (AbstractJClass typeArgument : genericType.getTypeParameters()) {
result = result.narrow(substitute(typeArgument, typeVariable, variableValue));
}
return result;
}
}
}
}
Aggregations