List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding clone
public TypeBinding clone(TypeBinding enclosingType)
From source file:spoon.support.compiler.jdt.ReferenceBuilder.java
License:Open Source License
/** * Builds a type reference from a qualified name when a type specified in the name isn't available. * * @param tokens Qualified name.//from w w w.j av a 2 s . co m * @param receiverType Last type in the qualified name. * @param enclosingType Enclosing type of the type name. * @param listener Listener to know if we must build the type reference. * @return a type reference. */ <T> CtTypeReference<T> getQualifiedTypeReference(char[][] tokens, TypeBinding receiverType, ReferenceBinding enclosingType, JDTTreeBuilder.OnAccessListener listener) { final List<CtExtendedModifier> listPublicProtected = Arrays.asList( new CtExtendedModifier(ModifierKind.PUBLIC), new CtExtendedModifier(ModifierKind.PROTECTED)); if (enclosingType != null && Collections.disjoint(listPublicProtected, JDTTreeBuilderQuery.getModifiers(enclosingType.modifiers, false, false))) { String access = ""; int i = 0; final CompilationUnitDeclaration[] units = ((TreeBuilderCompiler) this.jdtTreeBuilder .getContextBuilder().compilationunitdeclaration.scope.environment.typeRequestor).unitsToProcess; for (; i < tokens.length; i++) { final char[][] qualified = Arrays.copyOfRange(tokens, 0, i + 1); if (searchPackage(qualified, units) == null) { access = CharOperation.toString(qualified); break; } } if (!access.contains(CtPackage.PACKAGE_SEPARATOR)) { access = searchType(access, this.jdtTreeBuilder.getContextBuilder().compilationunitdeclaration.imports); } final TypeBinding accessBinding = searchTypeBinding(access, units); if (accessBinding != null && listener.onAccess(tokens, i)) { final TypeBinding superClassBinding = searchTypeBinding(accessBinding.superclass(), CharOperation.charToString(tokens[i + 1])); if (superClassBinding != null) { return this.getTypeReference(superClassBinding.clone(accessBinding)); } else { return this.getTypeReference(receiverType); } } else { return this.getTypeReference(receiverType); } } return null; }