Search in sources :

Example 1 with Symtab

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

the class JavacResolution method ifTypeIsIterableToComponent.

public static Type ifTypeIsIterableToComponent(Type type, JavacAST ast) {
    Types types = Types.instance(ast.getContext());
    Symtab syms = Symtab.instance(ast.getContext());
    Type boundType = ReflectiveAccess.Types_upperBound(types, type);
    //		Type boundType = types.upperBound(type);
    Type elemTypeIfArray = types.elemtype(boundType);
    if (elemTypeIfArray != null)
        return elemTypeIfArray;
    Type base = types.asSuper(boundType, syms.iterableType.tsym);
    if (base == null)
        return syms.objectType;
    List<Type> iterableParams = base.allparams();
    return iterableParams.isEmpty() ? syms.objectType : ReflectiveAccess.Types_upperBound(types, iterableParams.head);
}
Also used : Symtab(com.sun.tools.javac.code.Symtab) Types(com.sun.tools.javac.code.Types) ClassType(com.sun.tools.javac.code.Type.ClassType) CapturedType(com.sun.tools.javac.code.Type.CapturedType) ArrayType(com.sun.tools.javac.code.Type.ArrayType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type)

Example 2 with Symtab

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

the class JavacJavaUtilListSetSingularizer method generateMethods.

@Override
public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaListSetSingularizer.generateMethods(data, builderType, source, fluent, chain);
        return;
    }
    JavacTreeMaker maker = builderType.getTreeMaker();
    Symtab symbolTable = builderType.getSymbolTable();
    Name thisName = builderType.toName("this");
    JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
    JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
Also used : Symtab(com.sun.tools.javac.code.Symtab) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) Name(com.sun.tools.javac.util.Name)

Example 3 with Symtab

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

the class ImplicitDependencyExtractor method accumulate.

/**
   * Collects the implicit dependencies of the given set of ClassSymbol roots. As we're interested
   * in differentiating between symbols that were just resolved vs. symbols that were fully
   * completed by the compiler, we start the analysis by finding all the implicit dependencies
   * reachable from the given set of roots. For completeness, we then walk the symbol table
   * associated with the given context and collect the jar files of the remaining class symbols
   * found there.
   *
   * @param context compilation context
   * @param roots root classes in the implicit dependency collection
   */
public void accumulate(Context context, Set<ClassSymbol> roots) {
    Symtab symtab = Symtab.instance(context);
    if (symtab.classes == null) {
        return;
    }
    // Collect transitive references for root types
    for (ClassSymbol root : roots) {
        root.type.accept(typeVisitor, null);
    }
    Set<String> platformJars = getPlatformJars(fileManager);
    // Collect all other partially resolved types
    for (ClassSymbol cs : symtab.classes.values()) {
        // When recording we want to differentiate between jar references through completed symbols
        // and incomplete symbols
        boolean completed = cs.isCompleted();
        if (cs.classfile != null) {
            collectJarOf(cs.classfile, platformJars, completed);
        } else if (cs.sourcefile != null) {
            collectJarOf(cs.sourcefile, platformJars, completed);
        }
    }
}
Also used : Symtab(com.sun.tools.javac.code.Symtab) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol)

Example 4 with Symtab

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

the class IndexOfChar method matchMethodInvocation.

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    if (!MATCHER.matches(tree, state)) {
        return NO_MATCH;
    }
    List<? extends ExpressionTree> arguments = tree.getArguments();
    Symtab syms = state.getSymtab();
    Types types = state.getTypes();
    if (types.isSameType(types.unboxedTypeOrType(getType(arguments.get(0))), syms.intType) && types.isSameType(types.unboxedTypeOrType(getType(arguments.get(1))), syms.charType)) {
        return describeMatch(tree, SuggestedFix.builder().replace(arguments.get(0), state.getSourceForNode(arguments.get(1))).replace(arguments.get(1), state.getSourceForNode(arguments.get(0))).build());
    }
    return NO_MATCH;
}
Also used : Symtab(com.sun.tools.javac.code.Symtab) Types(com.sun.tools.javac.code.Types)

Example 5 with Symtab

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

the class UTypeVarIdentTest method inline.

@Test
public void inline() {
    ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL);
    Symtab symtab = Symtab.instance(context);
    Type listType = symtab.listType;
    bind(new UTypeVar.Key("E"), TypeWithExpression.create(new ClassType(listType, List.<Type>of(symtab.stringType), listType.tsym)));
    assertInlines("List<String>", UTypeVarIdent.create("E"));
    assertEquals(ImmutableSet.of("java.util.List"), inliner.getImportsToAdd());
}
Also used : Symtab(com.sun.tools.javac.code.Symtab) ClassType(com.sun.tools.javac.code.Type.ClassType) Type(com.sun.tools.javac.code.Type) ClassType(com.sun.tools.javac.code.Type.ClassType) Test(org.junit.Test)

Aggregations

Symtab (com.sun.tools.javac.code.Symtab)16 Type (com.sun.tools.javac.code.Type)6 Types (com.sun.tools.javac.code.Types)5 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)3 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)3 Context (com.sun.tools.javac.util.Context)3 JavacTreeMaker (lombok.javac.JavacTreeMaker)3 ExpressionTree (com.sun.source.tree.ExpressionTree)2 MethodTree (com.sun.source.tree.MethodTree)2 Tree (com.sun.source.tree.Tree)2 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)2 ClassType (com.sun.tools.javac.code.Type.ClassType)2 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)2 JCTree (com.sun.tools.javac.tree.JCTree)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 VisitorState (com.google.errorprone.VisitorState)1 Builder (com.google.errorprone.fixes.SuggestedFix.Builder)1 Matchers.toType (com.google.errorprone.matchers.Matchers.toType)1 ASTHelpers.getType (com.google.errorprone.util.ASTHelpers.getType)1