// recursive method that finds the end position of a type reference with type parameters, e.g.,
// Foo<T>.List<Bar<T>>
private int findSourceEndTypeReference(TypeReference type, TypeReference[] typeParameters) {
int end = type.sourceEnd();
if (isNotEmpty(typeParameters)) {
TypeReference lastNode = typeParameters[typeParameters.length - 1];
if (lastNode instanceof ParameterizedQualifiedTypeReference) {
TypeReference[][] typeArguments = ((ParameterizedQualifiedTypeReference) lastNode).typeArguments;
end = findSourceEndTypeReference(lastNode, typeArguments[typeArguments.length - 1]);
} else if (lastNode instanceof ParameterizedSingleTypeReference) {
TypeReference[] typeArguments = ((ParameterizedSingleTypeReference) lastNode).typeArguments;
end = findSourceEndTypeReference(lastNode, typeArguments);
} else {
end = typeParameters[typeParameters.length - 1].sourceEnd();
}
if (end == -1) {
end = lastNode.sourceEnd();
}
end++; // increment end position to the the last '>'
}
return end;
}