Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding clone

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding clone

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding clone.

Prototype

public TypeBinding clone(TypeBinding enclosingType) 

Source Link

Document

Virtual copy constructor: a copy is made of the receiver's entire instance state and then suitably parameterized by the arguments to the clone operation as seen fit by each type.

Usage

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;
}