Search in sources :

Example 1 with Symbol

use of com.sun.tools.javac.code.Symbol in project lombok by rzwitserloot.

the class HandleExtensionMethod method getExtension.

public Extension getExtension(final JavacNode typeNode, final ClassType extensionMethodProviderType) {
    List<MethodSymbol> extensionMethods = new ArrayList<MethodSymbol>();
    TypeSymbol tsym = extensionMethodProviderType.asElement();
    if (tsym != null)
        for (Symbol member : tsym.getEnclosedElements()) {
            if (member.getKind() != ElementKind.METHOD)
                continue;
            MethodSymbol method = (MethodSymbol) member;
            if ((method.flags() & (STATIC | PUBLIC)) == 0)
                continue;
            if (method.params().isEmpty())
                continue;
            extensionMethods.add(method);
        }
    return new Extension(extensionMethods, tsym);
}
Also used : MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) ArrayList(java.util.ArrayList) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Example 2 with Symbol

use of com.sun.tools.javac.code.Symbol in project bazel by bazelbuild.

the class StrictJavaDepsPlugin method isAnnotationProcessorExempt.

/**
   * Returns true if the compilation unit contains a single top-level class generated by an exempt
   * annotation processor (according to its {@link @Generated} annotation).
   *
   * <p>Annotation processors are expected to never generate more than one top level class, as
   * required by the style guide.
   */
public ProcessorDependencyMode isAnnotationProcessorExempt(JCTree.JCCompilationUnit unit) {
    if (unit.getTypeDecls().size() != 1) {
        return ProcessorDependencyMode.DEFAULT;
    }
    Symbol sym = TreeInfo.symbolFor(getOnlyElement(unit.getTypeDecls()));
    if (sym == null) {
        return ProcessorDependencyMode.DEFAULT;
    }
    Generated generated = sym.getAnnotation(Generated.class);
    if (generated == null) {
        return ProcessorDependencyMode.DEFAULT;
    }
    for (String value : generated.value()) {
        // Relax strict deps for dagger-generated code (b/17979436).
        if (value.startsWith(DAGGER_PROCESSOR_PREFIX)) {
            return ProcessorDependencyMode.EXEMPT_NORECORD;
        }
        if (dependencyModule.getExemptGenerators().contains(value)) {
            return ProcessorDependencyMode.EXEMPT_RECORD;
        }
    }
    return ProcessorDependencyMode.DEFAULT;
}
Also used : Generated(javax.annotation.Generated) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol)

Example 3 with Symbol

use of com.sun.tools.javac.code.Symbol in project error-prone by google.

the class FilesLinesLeak method inTWR.

private boolean inTWR(VisitorState state) {
    TreePath path = state.getPath().getParentPath();
    while (path.getLeaf().getKind() == Tree.Kind.CONDITIONAL_EXPRESSION) {
        path = path.getParentPath();
    }
    Symbol sym = ASTHelpers.getSymbol(path.getLeaf());
    return sym != null && sym.getKind() == ElementKind.RESOURCE_VARIABLE;
}
Also used : TreePath(com.sun.source.util.TreePath) Symbol(com.sun.tools.javac.code.Symbol)

Example 4 with Symbol

use of com.sun.tools.javac.code.Symbol in project error-prone by google.

the class CompileTimeConstantChecker method handleMatch.

/**
   * If the non-constant variable is annotated with @CompileTimeConstant, it must have been
   * non-final. Suggest making it final in the error message.
   */
private Description handleMatch(ExpressionTree actualParam, VisitorState state) {
    Symbol sym = ASTHelpers.getSymbol(actualParam);
    if (!(sym instanceof VarSymbol)) {
        return describeMatch(actualParam);
    }
    VarSymbol var = (VarSymbol) sym;
    if (!hasCompileTimeConstantAnnotation(state, var)) {
        return describeMatch(actualParam);
    }
    return buildDescription(actualParam).setMessage(this.message() + String.format(DID_YOU_MEAN_FINAL_FMT_MESSAGE, var.getSimpleName())).build();
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Example 5 with Symbol

use of com.sun.tools.javac.code.Symbol in project error-prone by google.

the class DefaultCharset method variableTypeFix.

private void variableTypeFix(SuggestedFix.Builder fix, VisitorState state, Class<?> original, Class<?> replacement) {
    Tree parent = state.getPath().getParentPath().getLeaf();
    Symbol sym;
    switch(parent.getKind()) {
        case VARIABLE:
            sym = ASTHelpers.getSymbol((VariableTree) parent);
            break;
        case ASSIGNMENT:
            sym = ASTHelpers.getSymbol(((AssignmentTree) parent).getVariable());
            break;
        default:
            return;
    }
    if (!ASTHelpers.isSameType(sym.type, state.getTypeFromString(original.getCanonicalName()), state)) {
        return;
    }
    state.getPath().getCompilationUnit().accept(new TreeScanner<Void, Void>() {

        @Override
        public Void visitVariable(VariableTree node, Void aVoid) {
            if (sym.equals(ASTHelpers.getSymbol(node))) {
                fix.replace(node.getType(), replacement.getSimpleName()).addImport(replacement.getCanonicalName());
            }
            return null;
        }
    }, null);
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) VariableTree(com.sun.source.tree.VariableTree) VariableTree(com.sun.source.tree.VariableTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) NewClassTree(com.sun.source.tree.NewClassTree) ImportTree(com.sun.source.tree.ImportTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) JCTree(com.sun.tools.javac.tree.JCTree) AssignmentTree(com.sun.source.tree.AssignmentTree)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)195 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)56 Type (com.sun.tools.javac.code.Type)54 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)53 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)45 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)36 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)29 JCTree (com.sun.tools.javac.tree.JCTree)28 ClassType (com.sun.tools.javac.code.Type.ClassType)18 Tree (com.sun.source.tree.Tree)17 ExpressionTree (com.sun.source.tree.ExpressionTree)15 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)15 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)15 ClassTree (com.sun.source.tree.ClassTree)14 MethodTree (com.sun.source.tree.MethodTree)14 Name (com.sun.tools.javac.util.Name)14 IdentifierTree (com.sun.source.tree.IdentifierTree)13 ArrayType (com.sun.tools.javac.code.Type.ArrayType)12 MethodType (com.sun.tools.javac.code.Type.MethodType)12 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)12