List of usage examples for org.eclipse.jdt.internal.compiler.ast TypeReference getTypeArguments
public TypeReference[][] getTypeArguments()
From source file:com.android.tools.lint.psi.EcjPsiJavaCodeReferenceElement.java
License:Apache License
@NonNull @Override/*from www . j a v a 2 s . c om*/ public PsiType[] getTypeParameters() { if (!(mNativeNode instanceof TypeReference)) { // No type parameters for import statements return PsiType.EMPTY_ARRAY; } TypeReference typeReference = (TypeReference) mNativeNode; TypeReference[][] typeArguments = typeReference.getTypeArguments(); if (typeArguments == null || typeArguments.length == 0) { return PsiType.EMPTY_ARRAY; } for (int i = typeArguments.length - 1; i >= 0; i--) { TypeReference[] refs = typeArguments[i]; if (refs != null && refs.length > 0) { List<PsiType> types = Lists.newArrayListWithCapacity(refs.length); for (TypeReference ref : refs) { PsiType type = mManager.findType(ref); if (type != null) { types.add(type); } } return types.toArray(PsiType.EMPTY_ARRAY); } } return PsiType.EMPTY_ARRAY; }
From source file:spoon.support.compiler.jdt.PositionBuilder.java
License:Open Source License
private int getSourceEndOfTypeReference(char[] contents, TypeReference node, int sourceEnd) { //e.g. SomeType<String,T> TypeReference[][] typeArgs = node.getTypeArguments(); if (typeArgs != null && typeArgs.length > 0) { TypeReference[] trs = typeArgs[typeArgs.length - 1]; if (trs != null && trs.length > 0) { TypeReference tr = trs[trs.length - 1]; if (sourceEnd < tr.sourceEnd) { //the sourceEnd of reference is smaller then source of type argument of this reference //move sourceEnd so that type argument is included in sources //TODO handle comments correctly here. E.g. List<T /*ccc*/ > sourceEnd = findNextNonWhitespace(contents, contents.length - 1, getSourceEndOfTypeReference(contents, tr, tr.sourceEnd) + 1); }/*from www . j a va 2 s . c o m*/ } else { //SomeType<> int startIdx = findNextNonWhitespace(contents, contents.length - 1, sourceEnd + 1); if (startIdx != -1 && contents[startIdx] == '<') { int endIdx = findNextNonWhitespace(contents, contents.length - 1, startIdx + 1); if (endIdx != -1 && contents[endIdx] == '>') { sourceEnd = endIdx; } } } } if (node instanceof Wildcard) { Wildcard wildcard = (Wildcard) node; if (wildcard.bound != null) { sourceEnd = getSourceEndOfTypeReference(contents, wildcard.bound, sourceEnd); } } return sourceEnd; }
From source file:spoon.support.compiler.jdt.ReferenceBuilder.java
License:Open Source License
private <T> CtTypeReference<T> buildTypeReferenceInternal(CtTypeReference<T> typeReference, TypeReference type, Scope scope, boolean isTypeCast) { if (type == null) { return null; }//from w w w . j a va 2 s . c o m CtTypeReference<?> currentReference = typeReference; for (int position = type.getTypeName().length - 1; position >= 0; position--) { if (currentReference == null) { break; } this.jdtTreeBuilder.getContextBuilder().isBuildTypeCast = isTypeCast; this.jdtTreeBuilder.getContextBuilder().enter(currentReference, type); this.jdtTreeBuilder.getContextBuilder().isBuildTypeCast = false; if (type.annotations != null && type.annotations.length - 1 <= position && type.annotations[position] != null && type.annotations[position].length > 0) { for (Annotation annotation : type.annotations[position]) { if (scope instanceof ClassScope) { annotation.traverse(this.jdtTreeBuilder, (ClassScope) scope); } else if (scope instanceof BlockScope) { annotation.traverse(this.jdtTreeBuilder, (BlockScope) scope); } else { annotation.traverse(this.jdtTreeBuilder, (BlockScope) null); } } } if (type.getTypeArguments() != null && type.getTypeArguments().length - 1 <= position && type.getTypeArguments()[position] != null && type.getTypeArguments()[position].length > 0) { CtTypeReference<?> componentReference = getTypeReferenceOfArrayComponent(currentReference); componentReference.getActualTypeArguments().clear(); for (TypeReference typeArgument : type.getTypeArguments()[position]) { if (typeArgument instanceof Wildcard || typeArgument.resolvedType instanceof WildcardBinding || typeArgument.resolvedType instanceof TypeVariableBinding) { componentReference.addActualTypeArgument(buildTypeParameterReference(typeArgument, scope)); } else { componentReference.addActualTypeArgument(buildTypeReference(typeArgument, scope)); } } } else if ((type instanceof ParameterizedSingleTypeReference || type instanceof ParameterizedQualifiedTypeReference) && !isTypeArgumentExplicit(type.getTypeArguments())) { for (CtTypeReference<?> actualTypeArgument : currentReference.getActualTypeArguments()) { actualTypeArgument.setImplicit(true); if (actualTypeArgument instanceof CtArrayTypeReference) { ((CtArrayTypeReference) actualTypeArgument).getComponentType().setImplicit(true); } } } if (type instanceof Wildcard && typeReference instanceof CtWildcardReference) { ((CtWildcardReference) typeReference) .setBoundingType(buildTypeReference(((Wildcard) type).bound, scope)); } this.jdtTreeBuilder.getContextBuilder().exit(type); currentReference = currentReference.getDeclaringType(); } //detect whether something is implicit if (type instanceof SingleTypeReference) { typeReference.setImplicitParent(true); } else if (type instanceof QualifiedTypeReference) { jdtTreeBuilder.getHelper().handleImplicit((QualifiedTypeReference) type, typeReference); } return typeReference; }
From source file:spoon.support.compiler.jdt.ReferenceBuilder.java
License:Open Source License
private <T> void insertGenericTypesInNoClasspathFromJDTInSpoon(TypeReference original, CtTypeReference<T> type) { if (original.resolvedType instanceof ProblemReferenceBinding && original.getTypeArguments() != null) { for (TypeReference[] typeReferences : original.getTypeArguments()) { if (typeReferences != null) { for (TypeReference typeReference : typeReferences) { type.addActualTypeArgument(this.getTypeReference(typeReference.resolvedType)); }//w ww. j a v a 2 s . c o m } } } }