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(); }
private JCMethodInvocation createSyntheticShadowAccess(VisitorState state) { TreeMaker treeMaker = state.getTreeMaker(); JCExpression application = treeMaker.Select( treeMaker.Ident(findSymbol(state, "org.robolectric.RuntimeEnvironment")), findSymbol(state, "org.robolectric.RuntimeEnvironment", "application")); JCExpression shadowOfApp = treeMaker.Select( treeMaker.Ident(findSymbol(state, "org.robolectric.Shadows")), findSymbol(state, "org.robolectric.Shadows", "shadowOf(android.app.Application)")); JCMethodInvocation callShadowOf = treeMaker.Apply(null, shadowOfApp, com.sun.tools.javac.util.List.of(application)); callShadowOf.type = callShadowOf.meth.type; return callShadowOf; }
JCTree inlineBody(Inliner inliner) throws CouldNotResolveImportException { if (getBody() instanceof UPlaceholderExpression) { UPlaceholderExpression body = (UPlaceholderExpression) getBody(); Optional<List<JCStatement>> blockBinding = inliner.getOptionalBinding(body.placeholder().blockKey()); if (blockBinding.isPresent()) { // this lambda is of the form args -> blockPlaceholder(); List<JCStatement> blockInlined = UPlaceholderExpression.copier(body.arguments(), inliner) .copy(blockBinding.get(), inliner); if (blockInlined.size() == 1) { if (blockInlined.get(0) instanceof JCReturn) { return ((JCReturn) blockInlined.get(0)).getExpression(); } else if (blockInlined.get(0) instanceof JCExpressionStatement) { return ((JCExpressionStatement) blockInlined.get(0)).getExpression(); } } return inliner.maker().Block(0, blockInlined); } } return getBody().inline(inliner); }
private JCExpression makeSelectExpression( Inliner inliner, List<String> qualifiedPath, int start) { Iterator<String> selects = qualifiedPath.listIterator(start); TreeMaker maker = inliner.maker(); JCExpression select = maker.Ident(inliner.asName(selects.next())); while (selects.hasNext()) { select = maker.Select(select, inliner.asName(selects.next())); } return select; } },
private MethodSymbol addEnumFieldNameMethod(JCClassDecl cdef, VarSymbol nameSymbol) { // Add the accessor methods for name Symbol nameSym = lookupMethod(cdef.pos(), names._name, cdef.type, List.<Type>nil()); assert(nameSym != null); assert(nameSym instanceof MethodSymbol); JCStatement ret = make.Return(make.Ident(nameSymbol)); cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)nameSym, make.Block(0L, List.of(ret)))); return (MethodSymbol)nameSym; }
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); return make.Apply( List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type); }
public JCAnnotation visitCompoundInternal(Attribute.Compound compound) { ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) { Pair<MethodSymbol,Attribute> pair = values.head; JCExpression valueTree = translate(pair.snd); args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type)); } return Annotation(Type(compound.type), args.toList()); } public void visitArray(Attribute.Array array) {
/** * Create a no-arg method invocation from a method tree */ public JCMethodInvocation App(JCExpression meth) { return Apply(null, meth, List.<JCExpression>nil()).setType(meth.type.getReturnType()); }
private JCTree.JCStatement buildBootstrapStaticBlock() { TreeMaker make = _javacJacker.getTreeMaker(); JavacElements javacElems = _javacJacker.getJavacElements(); JCTree.JCMethodInvocation bootstrapInitCall = make.Apply( List.nil(), memberAccess( make, javacElems, Bootstrap.class.getName() + ".init" ), List.nil() ); return make.Block( Modifier.STATIC, List.of( make.Exec( bootstrapInitCall ) ) ); }
final PlaceholderUnificationVisitor visitor = PlaceholderUnificationVisitor.create( TreeMaker.instance(initState.unifier().getContext()), arguments()); State.create(List.<UVariableDecl>nil(), initState.unifier(), ConsumptionState.empty())); UnifierWithUnconsumedStatements.create(resultUnifier, remainingStatements); List<JCStatement> impl = consumptionState.result().placeholderImplInReverseOrder().reverse(); ControlFlowVisitor.Result implFlow = ControlFlowVisitor.INSTANCE.visitStatements(impl); if (implFlow == implementationFlow()) { List<JCStatement> prevBinding = resultUnifier.getBinding(placeholder().blockKey()); if (prevBinding != null && prevBinding.toString().equals(impl.toString())) { return Optional.of(result); } else if (prevBinding == null) {
private static JCMethodInvocation createSyntheticShadowAccess( MethodInvocationTree shadowOfCall, String newFieldName, Symbol originalSymbol, VisitorState state) { TreeMaker treeMaker = state.getTreeMaker(); Symbol newSymbol = createSymbol(originalSymbol, state.getName(newFieldName), ((JCExpression) shadowOfCall.getArguments().get(0)).type); JCExpression methodSelect = (JCExpression) shadowOfCall.getMethodSelect(); if (methodSelect instanceof JCIdent) { // clone so start pos can be changed... methodSelect = treeMaker.Ident(((JCIdent) shadowOfCall.getMethodSelect()).sym); } JCMethodInvocation callShadowOf = treeMaker.Apply( null, methodSelect, com.sun.tools.javac.util.List.of(createIdent(treeMaker, newSymbol))); callShadowOf.type = ((JCMethodInvocation) shadowOfCall).type; return callShadowOf; }
@Override public JCLiteral inline(Inliner inliner) { Object value = this.getValue(); switch (getKind()) { case CHAR_LITERAL: // Why do they do it like this? I wish I knew. value = (int) ((Character) value).charValue(); break; case BOOLEAN_LITERAL: value = ((Boolean) value) ? 1 : 0; break; default: // do nothing } return inliner.maker().Literal(LIT_KIND_TAG.get(getKind()), value); }
public JCAnnotation visitTypeCompoundInternal(Attribute.TypeCompound compound) { ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) { Pair<MethodSymbol,Attribute> pair = values.head; JCExpression valueTree = translate(pair.snd); args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type)); } return TypeAnnotation(Type(compound.type), args.toList()); } public void visitArray(Attribute.Array array) {
/** * Create a method invocation from a method tree and a list of * argument trees. */ public JCMethodInvocation App(JCExpression meth, List<JCExpression> args) { return Apply(null, meth, args).setType(meth.type.getReturnType()); }