Example usage for org.eclipse.jdt.internal.compiler.lookup BinaryTypeBinding resolveType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup BinaryTypeBinding resolveType

Introduction

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

Prototype

public static TypeBinding resolveType(TypeBinding type, LookupEnvironment environment,
            boolean convertGenericToRawType) 

Source Link

Usage

From source file:com.google.gwt.dev.javac.JdtCompiler.java

License:Open Source License

public static ReferenceBinding resolveType(LookupEnvironment lookupEnvironment, String typeName) {
    ReferenceBinding type = null;/*from w  ww .  jav  a  2s  .  c  om*/

    int p = typeName.indexOf('$');
    if (p > 0) {
        // resolve an outer type before trying to get the cached inner
        String cupName = typeName.substring(0, p);
        char[][] chars = CharOperation.splitOn('.', cupName.toCharArray());
        if (lookupEnvironment.getType(chars) != null) {
            // outer class was found
            chars = CharOperation.splitOn('.', typeName.toCharArray());
            type = lookupEnvironment.getCachedType(chars);
            if (type == null) {
                // no inner type; this is a pure failure
                return null;
            }
        }
    } else {
        // just resolve the type straight out
        char[][] chars = CharOperation.splitOn('.', typeName.toCharArray());
        type = lookupEnvironment.getType(chars);
    }

    if (type != null) {
        if (type instanceof UnresolvedReferenceBinding) {
            type = (ReferenceBinding) BinaryTypeBinding.resolveType(type, lookupEnvironment, true);
        }
        // found it
        return type;
    }

    // Assume that the last '.' should be '$' and try again.
    //
    p = typeName.lastIndexOf('.');
    if (p >= 0) {
        typeName = typeName.substring(0, p) + "$" + typeName.substring(p + 1);
        return resolveType(lookupEnvironment, typeName);
    }

    return null;
}

From source file:org.eclipse.ajdt.core.parserbridge.ITDInserter.java

License:Open Source License

/**
 * Ask the oracle for the type binding with the given name
 * @param child/*  w  w  w. jav a 2  s  .  com*/
 * @return
 */
protected TypeBinding getReturnTypeBinding(char[] typeName, TypeBinding ititBinding) {
    TypeBinding typeBinding = env.getTypeFromTypeSignature(new SignatureWrapper(typeName),
            new TypeVariableBinding[0], (ReferenceBinding) ititBinding, new char[0][][],
            TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER);
    typeBinding = BinaryTypeBinding.resolveType(typeBinding, env, false);
    return typeBinding;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java

License:Open Source License

/** retrieve a class or array binding from the constant pool. */
private TypeBinding decodeClassEntry(int index) {
    int start = getConstantPoolStartPosition(index);
    assert (u1At(start) == ClassTag);
    int name_index = u2At(start + 1);
    char[] name_str = getUtf8(name_index);

    // first check scalar class type:
    int dims = 0;
    while (name_str[dims] == '[')
        dims++;/*from www . j ava2  s  .  co  m*/
    if (dims == 0) {
        // no '[' prefix -> plain class name, must not have 'L' prefix nor ';' suffix:
        if (name_str[0] == 'L' || name_str[name_str.length - 1] == ';')
            throw new IncompatibleBytecodeException(name_str, 0);
        return getClassBinding(index);
    }

    // follows: decoding of array, leaf component type needs 'L' for reference bindings:
    TypeBinding typeBinding = this._environment.getTypeFromSignature(name_str, 0, -1, false,
            this._srcModel.getBinding(), null, TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER);
    if (!typeBinding.leafComponentType().isBaseType()) {
        ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding.leafComponentType();
        if (referenceBinding instanceof UnresolvedReferenceBinding) {
            ReferenceBinding localType = findLocalType(CharOperation.subarray(name_str, dims, -1));
            if (localType != null)
                referenceBinding = localType;
            else
                referenceBinding = (ReferenceBinding) BinaryTypeBinding.resolveType(referenceBinding,
                        this._environment, false);
        }
        // check whether this type is actually an anchored type:
        CPTypeAnchorAttribute typeAnchors = this._srcModel.getTypeAnchors();
        if (typeAnchors != null) {
            char[] anchorPath = typeAnchors.getPath(index);
            if (anchorPath != null) {
                // create a RTB using a dummy field:
                ReferenceBinding teamType = referenceBinding.enclosingType();
                FieldBinding anchor = new FieldBinding(anchorPath, teamType, AccFinal,
                        this._srcModel.getBinding(), Constant.NotAConstant);
                return anchor.getRoleTypeBinding(referenceBinding, dims);
            }
        }
    }
    return typeBinding;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java

License:Open Source License

private ReferenceBinding getClassBinding(int index) {
    int start = getConstantPoolStartPosition(index);
    assert (u1At(start) == ClassTag);
    int name_index = u2At(start + 1);
    char[] name_str = getUtf8(name_index);
    ReferenceBinding referenceBinding = this._environment.getTypeFromConstantPoolName(name_str, 0, -1, false,
            null);/*from  w  w w .  java2  s  .  com*/
    if (referenceBinding instanceof UnresolvedReferenceBinding) {
        ReferenceBinding localType = findLocalType(name_str);
        if (localType != null)
            return localType;
        referenceBinding = (ReferenceBinding) BinaryTypeBinding.resolveType(referenceBinding, this._environment,
                false);
    }
    // check whether this type is actually an anchored type:
    CPTypeAnchorAttribute typeAnchors = this._srcModel.getTypeAnchors();
    if (typeAnchors != null) {
        char[] anchorPath = typeAnchors.getPath(index);
        if (anchorPath != null) {
            // create a RTB using a dummy field:
            ReferenceBinding teamType = referenceBinding.enclosingType();
            FieldBinding anchor = new FieldBinding(anchorPath, teamType, AccFinal, this._srcModel.getBinding(),
                    Constant.NotAConstant);
            referenceBinding = (ReferenceBinding) anchor.getRoleTypeBinding(referenceBinding, 0);
        }
    }
    return referenceBinding;
}