Java Code Examples for com.sun.tools.javac.code.Symbol#exists()

The following examples show how to use com.sun.tools.javac.code.Symbol#exists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a symbol given the type's or package's canonical name,
 * or null if the name isn't found.
 */
private <S extends Symbol> S nameToSymbol(ModuleSymbol module, String nameStr, Class<S> clazz) {
    Name name = names.fromString(nameStr);
    // First check cache.
    Symbol sym = (clazz == ClassSymbol.class)
                ? syms.getClass(module, name)
                : syms.lookupPackage(module, name);

    try {
        if (sym == null)
            sym = javaCompiler.resolveIdent(module, nameStr);

        sym.complete();

        return (sym.kind != ERR &&
                sym.exists() &&
                clazz.isInstance(sym) &&
                name.equals(sym.getQualifiedName()))
            ? clazz.cast(sym)
            : null;
    } catch (CompletionFailure e) {
        return null;
    }
}