Java Code Examples for com.sun.tools.javac.code.Kinds.Kind#TYP

The following examples show how to use com.sun.tools.javac.code.Kinds.Kind#TYP . 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: SymbolMetadata.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setAttributes(SymbolMetadata other) {
    if (other == null) {
        throw new NullPointerException();
    }
    setDeclarationAttributes(other.getDeclarationAttributes());
    if ((sym.flags() & Flags.BRIDGE) != 0) {
        Assert.check(other.sym.kind == Kind.MTH);
        ListBuffer<TypeCompound> typeAttributes = new ListBuffer<>();
        for (TypeCompound tc : other.getTypeAttributes()) {
            // Carry over only contractual type annotations: i.e nothing interior to method body.
            if (!tc.position.type.isLocal())
                typeAttributes.append(tc);
        }
        setTypeAttributes(typeAttributes.toList());
    } else {
        setTypeAttributes(other.getTypeAttributes());
    }
    if (sym.kind == Kind.TYP) {
        setInitTypeAttributes(other.getInitTypeAttributes());
        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
    }
}
 
Example 2
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void doAnalysis(RewritingContext rewriting) {
    DiagnosticSource prevSource = log.currentSource();
    LocalCacheContext localCacheContext = argumentAttr.withLocalCacheContext();
    try {
        log.useSource(rewriting.env.toplevel.getSourceFile());

        JCStatement treeToAnalyze = (JCStatement)rewriting.originalTree;
        if (rewriting.env.info.scope.owner.kind == Kind.TYP) {
            //add a block to hoist potential dangling variable declarations
            treeToAnalyze = make.Block(Flags.SYNTHETIC, List.of((JCStatement)rewriting.originalTree));
        }

        //TODO: to further refine the analysis, try all rewriting combinations
        deferredAttr.attribSpeculative(treeToAnalyze, rewriting.env, attr.statInfo, new TreeRewriter(rewriting),
                t -> rewriting.diagHandler(), argumentAttr.withLocalCacheContext());
        rewriting.analyzer.process(rewriting.oldTree, rewriting.replacement, rewriting.erroneous);
    } catch (Throwable ex) {
        Assert.error("Analyzer error when processing: " + rewriting.originalTree);
    } finally {
        log.useSource(prevSource.getFile());
        localCacheContext.leave();
    }
}
 
Example 3
Source File: ElementUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static TypeElement getTypeElementByBinaryName(JavacTask task, ModuleElement mod, String name) {
    Context ctx = ((JavacTaskImpl) task).getContext();
    Names names = Names.instance(ctx);
    Symtab syms = Symtab.instance(ctx);
    Check chk = Check.instance(ctx);
    final Name wrappedName = names.fromString(name);
    ClassSymbol clazz = chk.getCompiled((ModuleSymbol) mod, wrappedName);
    if (clazz != null) {
        return clazz;
    }
    clazz = syms.enterClass((ModuleSymbol) mod, wrappedName);
    
    try {
        clazz.complete();
        
        if (clazz.kind == Kind.TYP &&
            clazz.flatName() == wrappedName) {
            return clazz;
        }
    } catch (CompletionFailure cf) {
    }

    return null;
}
 
Example 4
Source File: SymbolMetadata.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setAttributes(SymbolMetadata other) {
    if (other == null) {
        throw new NullPointerException();
    }
    setDeclarationAttributes(other.getDeclarationAttributes());
    if ((sym.flags() & Flags.BRIDGE) != 0) {
        Assert.check(other.sym.kind == Kind.MTH);
        ListBuffer<TypeCompound> typeAttributes = new ListBuffer<>();
        for (TypeCompound tc : other.getTypeAttributes()) {
            // Carry over only contractual type annotations: i.e nothing interior to method body.
            if (!tc.position.type.isLocal())
                typeAttributes.append(tc);
        }
        setTypeAttributes(typeAttributes.toList());
    } else {
        setTypeAttributes(other.getTypeAttributes());
    }
    if (sym.kind == Kind.TYP) {
        setInitTypeAttributes(other.getInitTypeAttributes());
        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
    }
}
 
Example 5
Source File: ElementsTable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds all inner classes of this class, and their inner classes recursively, to the list
 */
private void addAllClasses(Collection<TypeElement> list, TypeElement typeElement, boolean filtered) {
    ClassSymbol klass = (ClassSymbol)typeElement;
    try {
        // eliminate needless checking, do this first.
        if (list.contains(klass)) return;
        // ignore classes with invalid Java class names
        if (!JavadocTool.isValidClassName(klass.name.toString())) return;
        if (filtered && !isTypeElementSelected(klass)) return;
        list.add(klass);
        for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
            if (sym != null && sym.kind == Kind.TYP) {
                ClassSymbol s = (ClassSymbol)sym;
                addAllClasses(list, s, filtered);
            }
        }
    } catch (CompletionFailure e) {
        if (e.getMessage() != null)
            messager.printWarning(e.getMessage());
        else
            messager.printWarningUsingKey("main.unexpected.exception", e);
    }
}