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);
}
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);
}
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);
}
}
}
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;
}
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());
}
Aggregations