Example usage for org.eclipse.jdt.internal.compiler.lookup ProblemReferenceBinding problemId

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ProblemReferenceBinding problemId

Introduction

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

Prototype

@Override
    public int problemId() 

Source Link

Usage

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

License:Open Source License

static String unknownProblem(String className, ProblemReferenceBinding problem) {
    return "Unknown problem: " + ProblemReferenceBinding.problemReasonString(problem.problemId()) + " "
            + className;/*from www  .  j  a  v  a  2s  .c  om*/
}

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;
        }//from   w  ww  . j  ava 2  s  . c o 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  .  jav 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.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java

License:Open Source License

/**
 * Look in the local cache, if we don't find it then ask JDT. If JDT responds with a SourceTypeBinding then it has been found.
 * If JDT responds with some other kind of binding, we consider that 'not found as source' and return null.
 * //from   w w  w .  j  av a2 s  .  c o  m
 * Not quite the right name for this method, because on an incremental build it will find BinaryTypeBindings for types that were
 * SourceTypeBindings during the full build
 * 
 */
// FIXASC (optimization) cache any non SourceTypeBinding found and use that information in the lookupClassNodeForBinary
public ClassNode lookupClassNodeForSource(String typename, JDTResolver jdtResolver) {
    ClassNode node = typenameToClassNodeCache.get(typename);
    if (node != null) {
        return node;
    }

    char[][] compoundName = CharOperation.splitOn('.', typename.toCharArray());

    TypeBinding jdtBinding = null;
    try {
        jdtBinding = getType(compoundName, compoundName.length);
    } catch (AbortCompilation t) {
        if (t.silentException instanceof AbortIncrementalBuildException) {
            jdtBinding = null;
        } else {
            throw t;
        }
    }

    if (jdtBinding != null) {
        if (jdtBinding instanceof SourceTypeBinding) {
            ClassNode classNode = jdtResolver.convertToClassNode(jdtBinding);
            if (classNode != null) {
                typenameToClassNodeCache.put(typename, classNode);
            }
            return classNode;
        } else if (jdtBinding instanceof BinaryTypeBinding) {
            ClassNode newNode = jdtResolver.convertToClassNode(jdtBinding);
            if (newNode != null) {
                typenameToClassNodeCache.put(typename, newNode);
            }
            return newNode;
        }
    }

    // FIXASC better to look it up properly as a member type rather than catch the problem and unwrap!
    if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) {
        ProblemReferenceBinding prBinding = (ProblemReferenceBinding) jdtBinding;
        if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
            jdtBinding = prBinding.closestMatch();
            // FIXASC caching for this too?
            if (jdtBinding != null && (jdtBinding instanceof SourceTypeBinding)) {
                return jdtResolver.convertToClassNode(jdtBinding);
            }
            if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
                return jdtResolver.convertToClassNode(jdtBinding);
            }
        }
    }
    return null;
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java

License:Open Source License

public ClassNode lookupClassNodeForBinary(String typename, JDTResolver jdtResolver) {
    char[][] compoundName = CharOperation.splitOn('.', typename.toCharArray());
    TypeBinding jdtBinding = getType(compoundName, compoundName.length);

    if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
        // log("GCUScope.lookupClassNodeForBinary(): JDTBinding for '" + typename + "' found to be "
        // + jdtBinding.getClass().getSimpleName());
        ClassNode classNode = jdtResolver.convertToClassNode(jdtBinding);
        return classNode;
    }//  ww  w.  j  a v a2s .  c o  m

    if (jdtBinding != null && (jdtBinding instanceof ProblemReferenceBinding)) {
        ProblemReferenceBinding prBinding = (ProblemReferenceBinding) jdtBinding;
        if (prBinding.problemId() == ProblemReasons.InternalNameProvided) {
            jdtBinding = prBinding.closestMatch();
            if (jdtBinding != null && (jdtBinding instanceof BinaryTypeBinding)) {
                return jdtResolver.convertToClassNode(jdtBinding);
            }
        }
    }
    return null;
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java

License:Open Source License

@Override
public boolean reportInvalidType(TypeReference typeReference, TypeBinding resolvedType) {
    if (resolvedType instanceof ProblemReferenceBinding) {
        ProblemReferenceBinding problemRefBinding = (ProblemReferenceBinding) resolvedType;
        if (problemRefBinding.problemId() == ProblemReasons.Ambiguous) {
            return true;
        }//from  w  w w  .  j av a 2  s  .co m
    }
    return false;
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitScope.java

License:Open Source License

@Override
protected void reportImportProblem(ImportReference importReference, Binding importBinding) {
    // GRE-680//  w ww  .  j a va 2s .  co  m
    if (importBinding instanceof ProblemReferenceBinding) {
        ProblemReferenceBinding problemRefBinding = (ProblemReferenceBinding) importBinding;
        if (problemRefBinding.problemId() == ProblemReasons.NotFound) {
            return;
        }
    }
    problemReporter().importProblem(importReference, importBinding);
}