Example usage for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment getType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment getType

Introduction

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

Prototype

public ReferenceBinding getType(char[][] compoundName) 

Source Link

Usage

From source file:com.android.tools.lint.psi.EcjPsiManager.java

License:Apache License

public PsiClass findClass(@NonNull char[][] compoundName) {
    LookupEnvironment lookupEnvironment = mEcjResult.getLookupEnvironment();
    if (lookupEnvironment != null) {
        ReferenceBinding type = lookupEnvironment.getType(compoundName);
        if (type != null && !(type instanceof ProblemReferenceBinding)) {
            return findClass(type);
        }// www  .  j a  v a2 s.c om
    }

    return null;
}

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;// ww w  .  j  av a 2  s.co  m

    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:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java

License:Open Source License

private static ReferenceBinding toBinding(IType type, LookupEnvironment theLookupEnvironment,
        char[][] compoundName) throws JavaModelException {
    ITypeRoot typeRoot = type.getTypeRoot();

    if (typeRoot instanceof IClassFile) {
        ClassFile classFile = (ClassFile) typeRoot;

        IFile classFileRsrc = (IFile) classFile.getCorrespondingResource();
        if (classFileRsrc != null && !classFileRsrc.exists()) {
            //the .class file has been deleted
            return null;
        }//www  . j a  v  a2 s. co m

        BinaryTypeBinding binaryTypeBinding = null;
        try {
            IBinaryType binaryType = classFile.getBinaryTypeInfo(classFileRsrc, true);
            binaryTypeBinding = theLookupEnvironment.cacheBinaryType(binaryType, null);
        } catch (JavaModelException e) {
            if (!e.isDoesNotExist()) {
                throw e;
            }
        }

        if (binaryTypeBinding == null) {
            ReferenceBinding existingType = theLookupEnvironment.getCachedType(compoundName);
            if (existingType == null || !(existingType instanceof BinaryTypeBinding)) {
                return null;
            }
            binaryTypeBinding = (BinaryTypeBinding) existingType;
        }
        return binaryTypeBinding;
    } else {
        ReferenceBinding referenceBinding = theLookupEnvironment.getType(compoundName);
        if (referenceBinding != null && !(referenceBinding instanceof BinaryTypeBinding)) {

            if (referenceBinding instanceof ProblemReferenceBinding) {
                ProblemReferenceBinding problemReferenceBinding = (ProblemReferenceBinding) referenceBinding;
                if (problemReferenceBinding.problemId() == ProblemReasons.InternalNameProvided) {
                    referenceBinding = problemReferenceBinding.closestReferenceMatch();
                } else {
                    System.out.println(
                            ProblemReferenceBinding.problemReasonString(problemReferenceBinding.problemId()));
                    return null;
                }
            }
            return referenceBinding;
        }
        return null;
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java

License:Open Source License

private ClassMirror buildClassMirror(String name) {
    try {/*  w ww .  ja v a 2 s  . c  o m*/
        IType type = javaProject.findType(name);
        if (type == null) {
            return null;
        }

        LookupEnvironment theLookupEnvironment = getLookupEnvironment();
        if (type.isBinary()) {
            ClassFile classFile = (ClassFile) type.getClassFile();

            if (classFile != null) {
                IPackageFragmentRoot fragmentRoot = classFile.getPackageFragmentRoot();
                if (fragmentRoot != null) {
                    if (isInCeylonClassesOutputFolder(fragmentRoot.getPath())) {
                        return null;
                    }
                }

                IFile classFileRsrc = (IFile) classFile.getCorrespondingResource();
                IBinaryType binaryType = classFile.getBinaryTypeInfo(classFileRsrc, true);
                if (classFileRsrc != null && !classFileRsrc.exists()) {
                    //the .class file has been deleted
                    return null;
                }
                BinaryTypeBinding binaryTypeBinding = theLookupEnvironment.cacheBinaryType(binaryType, null);
                if (binaryTypeBinding == null) {
                    char[][] compoundName = CharOperation.splitOn('/', binaryType.getName());
                    ReferenceBinding existingType = theLookupEnvironment.getCachedType(compoundName);
                    if (existingType == null || !(existingType instanceof BinaryTypeBinding)) {
                        return null;
                    }
                    binaryTypeBinding = (BinaryTypeBinding) existingType;
                }
                return new JDTClass(binaryTypeBinding, theLookupEnvironment);
            }
        } else {
            char[][] compoundName = CharOperation.splitOn('.', type.getFullyQualifiedName().toCharArray());
            ReferenceBinding referenceBinding = theLookupEnvironment.getType(compoundName);
            if (referenceBinding != null) {
                if (referenceBinding instanceof ProblemReferenceBinding) {
                    ProblemReferenceBinding problemReferenceBinding = (ProblemReferenceBinding) referenceBinding;
                    if (problemReferenceBinding.problemId() == ProblemReasons.InternalNameProvided) {
                        referenceBinding = problemReferenceBinding.closestReferenceMatch();
                    } else {
                        System.out.println(ProblemReferenceBinding
                                .problemReasonString(problemReferenceBinding.problemId()));
                        return null;
                    }
                }
                return new JDTClass(referenceBinding, theLookupEnvironment);
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel.java

License:Open Source License

/**
 * Find a type by  its compound name./*from   w  w  w. j  ava 2  s  .  c  o m*/
 * First look in local types (including enclosing roles).
 * Second use the environment for lookup.
 * This method is needed since local types are not stored in the environment.
 *
 * @param environment
 * @param compoundName
 * @return type specified by compoundName
 */
public ReferenceBinding findType(LookupEnvironment environment, char[][] compoundName) {
    char[][] myName = CharOperation.splitOn('/', this._binding.constantPoolName());
    if (this._binding.isLocalType() && CharOperation.equals(compoundName, myName))
        return this._binding;
    Iterator<RoleModel> locals = localTypes();
    while (locals.hasNext()) {
        RoleModel role = locals.next();
        char[][] roleName = CharOperation.splitOn('/', role.getBinding().constantPoolName());
        if (CharOperation.equals(compoundName, roleName))
            return role.getBinding();
    }
    if (this._binding.enclosingType().isRole())
        return this._binding.enclosingType().roleModel.findType(environment, compoundName);
    return environment.getType(compoundName);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TypeModel.java

License:Open Source License

public ReferenceBinding findType(LookupEnvironment environment, char[][] compoundName) {
    char[][] myName = CharOperation.splitOn('/', this._binding.constantPoolName());
    if (this._binding.isLocalType() && CharOperation.equals(compoundName, myName))
        return this._binding;
    if (this._binding.enclosingType() != null && this._binding.enclosingType().isRole())
        return this._binding.enclosingType().roleModel.findType(environment, compoundName);
    return environment.getType(compoundName);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer.java

License:Open Source License

/**
 * Prepare for generic handling of return values: all base types are converted to java.lang.Object.
 * @param orig//from   w  w w  .  jav a 2  s .  c o m
 * @param environment for lookup of java.lang.Object
 * @return either a binding for java.lang.Object or the original type 'orig'
 */
public static TypeBinding getGeneralizedReturnType(TypeBinding orig, LookupEnvironment environment) {
    if (orig.isBaseType())
        return environment.getType(TypeConstants.JAVA_LANG_OBJECT);
    return orig;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleFileHelper.java

License:Open Source License

private static ReferenceBinding myGetType(LookupEnvironment env, TypeDeclaration roleType,
        char[][] firstTypeName, char[] nestedTypeName) {
    ReferenceBinding firstType;/*from   ww  w . j  a v  a 2  s . co  m*/
    if (nestedTypeName == null)
        firstType = env.getTeamForRoFi(firstTypeName, roleType);
    else
        firstType = env.getType(firstTypeName);
    if (firstType == null && firstTypeName.length > 1) {
        char[][] parentTypeName = new char[firstTypeName.length - 1][];
        System.arraycopy(firstTypeName, 0, parentTypeName, 0, parentTypeName.length);
        firstType = myGetType(env, roleType, parentTypeName, firstTypeName[firstTypeName.length - 1]);
    }
    if (firstType == null)
        return null;
    // the case of deeply nested role: env didn't like to fetch it, but by unwrapping we are actually fine:
    if (firstType.problemId() == ProblemReasons.InternalNameProvided)
        firstType = ((ProblemReferenceBinding) firstType).closestReferenceMatch();
    if (nestedTypeName == null)
        return firstType;
    if (firstType.isSynthInterface())
        firstType = firstType.getRealClass();
    return firstType.getMemberType(nestedTypeName);
}