private void addPrivateConstructor(JavacNode singletonClass, JavacTreeMaker singletonTM) { JCTree.JCModifiers modifiers = singletonTM.Modifiers(Flags.PRIVATE); JCTree.JCBlock block = singletonTM.Block(0L, List.nil()); JCTree.JCMethodDecl constructor = singletonTM.MethodDef(modifiers, singletonClass.toName("<init>"), null, List.nil(), List.nil(), List.nil(), block, null); JavacHandlerUtil.injectMethod(singletonClass, constructor); }
static ConsumptionState empty() { return new AutoValue_UPlaceholderStatement_ConsumptionState(0, List.<JCStatement>nil()); }
private JavacNode addInnerClass(JavacNode singletonClass, JavacTreeMaker singletonTM) { JCTree.JCModifiers modifiers = singletonTM.Modifiers(Flags.PRIVATE | Flags.STATIC); String innerClassName = singletonClass.getName() + "Holder"; JCTree.JCClassDecl innerClassDecl = singletonTM.ClassDef(modifiers, singletonClass.toName(innerClassName), List.nil(), null, List.nil(), List.nil()); return JavacHandlerUtil.injectType(singletonClass, innerClassDecl); }
private void addFactoryMethod(JavacNode singletonClass, JavacTreeMaker singletonClassTreeMaker, JavacNode holderInnerClass) { JCTree.JCModifiers modifiers = singletonClassTreeMaker.Modifiers(Flags.PUBLIC | Flags.STATIC); JCTree.JCClassDecl singletonClassDecl = (JCTree.JCClassDecl) singletonClass.get(); JCTree.JCIdent singletonClassType = singletonClassTreeMaker.Ident(singletonClassDecl.name); JCTree.JCBlock block = addReturnBlock(singletonClassTreeMaker, holderInnerClass); JCTree.JCMethodDecl factoryMethod = singletonClassTreeMaker.MethodDef(modifiers, singletonClass.toName("getInstance"), singletonClassType, List.nil(), List.nil(), List.nil(), block, null); JavacHandlerUtil.injectMethod(singletonClass, factoryMethod); }
/** * If the tree is a {@link JCBlock}, returns a list of disjoint matches corresponding to the exact * list of template statements found consecutively; otherwise, returns an empty list. */ @Override public Iterable<BlockTemplateMatch> match(JCTree tree, Context context) { // TODO(lowasser): consider nonconsecutive matches? if (tree instanceof JCBlock) { JCBlock block = (JCBlock) tree; ImmutableList<JCStatement> targetStatements = ImmutableList.copyOf(block.getStatements()); return matchesStartingAnywhere(block, 0, targetStatements, context) .first() .or(List.<BlockTemplateMatch>nil()); } return ImmutableList.of(); }
private void addInstanceVar(JavacNode singletonClass, JavacTreeMaker singletonClassTM, JavacNode holderClass) { JCTree.JCModifiers fieldMod = singletonClassTM.Modifiers(Flags.PRIVATE | Flags.STATIC | Flags.FINAL); JCTree.JCClassDecl singletonClassDecl = (JCTree.JCClassDecl) singletonClass.get(); JCTree.JCIdent singletonClassType = singletonClassTM.Ident(singletonClassDecl.name); JCTree.JCNewClass newKeyword = singletonClassTM.NewClass(null, List.nil(), singletonClassType, List.nil(), null); JCTree.JCVariableDecl instanceVar = singletonClassTM.VarDef(fieldMod, singletonClass.toName("INSTANCE"), singletonClassType, newKeyword); JavacHandlerUtil.injectField(holderClass, instanceVar); }
private boolean shouldWorkaroundBug() { Boolean result = HAS_BUG.get(); if (result != null) { return result; } Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext(); TreeMaker make = TreeMaker.instance(ctx); final JCLiteral val = make.Literal(""); JCMethodDecl method = make.MethodDef(null, null, null, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, val); final boolean[] noBug = new boolean[] {false}; new TreeScanner() { @Override public void scan(JCTree tree) { noBug[0] |= (tree == val); super.scan(tree); } }.scan(method); HAS_BUG.compareAndSet(null, Boolean.valueOf(!noBug[0])); return HAS_BUG.get(); }
resultInfo, actualArgTypes, /*freeTypeVariables=*/ List.<Type>nil(), warner); } catch (InvocationTargetException e) {
private Choice<List<BlockTemplateMatch>> matchesStartingAnywhere( JCBlock block, int offset, final ImmutableList<? extends StatementTree> statements, final Context context) { Choice<List<BlockTemplateMatch>> choice = Choice.none(); for (int i = 0; i < statements.size(); i++) { choice = choice.or( matchesStartingAtBeginning( block, offset + i, statements.subList(i, statements.size()), context)); } return choice.or(Choice.of(List.<BlockTemplateMatch>nil())); }
private static Function<Unifier, Choice<Unifier>> unifyUStatementWithSingleStatement( @Nullable final UStatement toUnify, @Nullable final StatementTree target) { return (Unifier unifier) -> { if (toUnify == null) { return (target == null) ? Choice.of(unifier) : Choice.<Unifier>none(); } List<StatementTree> list = (target == null) ? List.<StatementTree>nil() : List.of(target); return toUnify .apply(UnifierWithUnconsumedStatements.create(unifier, list)) .condition(s -> s.unconsumedStatements().isEmpty()) .transform(UnifierWithUnconsumedStatements::unifier); }; }
@Override public MethodType inline(Inliner inliner) throws CouldNotResolveImportException { return new MethodType( inliner.<Type>inlineList(getParameterTypes()), getReturnType().inline(inliner), com.sun.tools.javac.util.List.<Type>nil(), inliner.symtab().methodClass); } }
@Override public JCMethodInvocation inline(Inliner inliner) throws CouldNotResolveImportException { return inliner .maker() .Apply( com.sun.tools.javac.util.List.<JCExpression>nil(), getMethodSelect().inline(inliner), inliner.<JCExpression>inlineList(getArguments())); } }
public Choice<State<List<JCTree>>> unify( @Nullable Iterable<? extends Tree> nodes, State<?> state) { if (nodes == null) { return Choice.of(state.<List<JCTree>>withResult(null)); } Choice<State<List<JCTree>>> choice = Choice.of(state.withResult(List.<JCTree>nil())); for (final Tree node : nodes) { choice = choice.thenChoose( (State<List<JCTree>> s) -> unify(node, s) .transform( treeState -> treeState.withResult(s.result().prepend(treeState.result())))); } return choice.transform(s -> s.withResult(s.result().reverse())); }
expr, PlaceholderUnificationVisitor.State.create( List.<UVariableDecl>nil(), unifier, null)); return states.thenOption( (PlaceholderUnificationVisitor.State<? extends JCExpression> state) -> {
@Override public JCMethodDecl inline(Inliner inliner) throws CouldNotResolveImportException { return inliner .maker() .MethodDef( getModifiers().inline(inliner), getName().inline(inliner), getReturnType().inline(inliner), List.<JCTypeParameter>nil(), List.convert(JCVariableDecl.class, inliner.inlineList(getParameters())), inliner.<JCExpression>inlineList(getThrows()), getBody().inline(inliner), null); }
State.create(List.<UVariableDecl>nil(), initState.unifier(), ConsumptionState.empty()));
/** * Transforms a list of source files to Java file objects (used by javac). */ public static com.sun.tools.javac.util.List<JavaFileObject> toJavaFileObjects(JavaFileManager fileManager, Collection<File> sourceFiles) throws IOException { com.sun.tools.javac.util.List<JavaFileObject> fileObjects = com.sun.tools.javac.util.List.nil(); JavacFileManager javacFileManager = (JavacFileManager) fileManager; for (JavaFileObject fo : javacFileManager.getJavaFileObjectsFromFiles(sourceFiles)) { fileObjects = fileObjects.append(fo); } if (fileObjects.length() != sourceFiles.size()) { throw new IOException("invalid file list"); } return fileObjects; }
public java.util.List<Symbol> getEnclosedElements() { List<Symbol> list = List.nil(); for (Scope.Entry e = members().elems; e != null; e = e.sibling) { if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) list = list.prepend(e.sym); } return list; }
private PostFlowAnalysis(Context ctx) { log = Log.instance(ctx); types = Types.instance(ctx); enter = Enter.instance(ctx); names = Names.instance(ctx); syms = Symtab.instance(ctx); outerThisStack = List.nil(); }