@Override public List<JCStatement> inlineStatements(Inliner inliner) throws CouldNotResolveImportException { return List.of(inline(inliner)); }
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 List<JCStatement> inlineStatements(Inliner inliner) throws CouldNotResolveImportException { return List.<JCStatement>of( inliner .maker() .If( getCondition().inline(inliner), Iterables.getOnlyElement(getThenStatement().inlineStatements(inliner)), (getElseStatement() == null) ? null : Iterables.getOnlyElement(getElseStatement().inlineStatements(inliner)))); } }
@Override public List<JCStatement> inlineStatements(final Inliner inliner) throws CouldNotResolveImportException { try { Optional<List<JCStatement>> binding = inliner.getOptionalBinding(placeholder().blockKey()); // If a placeholder was used as an expression binding in the @BeforeTemplate, // and as a bare statement or as a return in the @AfterTemplate, we may need to convert. Optional<JCExpression> exprBinding = inliner.getOptionalBinding(placeholder().exprKey()); binding = binding.or( exprBinding.transform( (JCExpression expr) -> { switch (implementationFlow()) { case NEVER_EXITS: return List.of((JCStatement) inliner.maker().Exec(expr)); case ALWAYS_RETURNS: return List.of((JCStatement) inliner.maker().Return(expr)); default: throw new AssertionError(); } })); return UPlaceholderExpression.copier(arguments(), inliner).copy(binding.get(), inliner); } catch (UncheckedCouldNotResolveImportException e) { throw e.getCause(); } } }
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; }
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; }
.apply( UnifierWithUnconsumedStatements.create( unifierAfterCond, List.of(ifTree.getThenStatement()))) .thenOption( (UnifierWithUnconsumedStatements stateAfterThen) ->
/** Construct a list consisting of given elements. */ public static <A> List<A> of(A x1, A x2) { return new List<A>(x1, of(x2)); }
/** Append given element at length, forming and returning * a new list. */ public List<A> append(A x) { return of(x).prependList(this); }
List<Comment> addComment(List<Comment> comments, Comment comment) { return comments == null ? List.of(comment) : comments.prepend(comment); }
/** * A convenience wrapper for {@link #makeCompoundType(List)}; the * arguments are converted to a list and passed to the other * method. Note that this might cause a symbol completion. * Hence, this version of makeCompoundType may not be called * during a classfile read. */ public Type makeCompoundType(Type bound1, Type bound2) { return makeCompoundType(List.of(bound1, bound2)); } // </editor-fold>
/** * Gets a localized string from the compiler's default bundle. */ // used to support legacy Log.getLocalizedString static String getDefaultLocalizedString(String key, Object... args) { return getLocalizedString(List.of(getDefaultBundle()), key, args); }
private boolean set(Node node, JCTree value) { if (result != null) throw new IllegalStateException("result is already set"); JCTree actualValue = value; if (node instanceof Expression) { for (int i = 0; i < ((Expression)node).getIntendedParens(); i++) { actualValue = treeMaker.Parens((JCExpression)actualValue); posParen(node, i, ((Expression)node).astParensPositions(), actualValue); } } result = List.of(actualValue); return true; }
public Iterable<? extends File> getLocation(Location location) { nullCheck(location); paths.lazy(); if (location == CLASS_OUTPUT) { return (getClassOutDir() == null ? null : List.of(getClassOutDir())); } else if (location == SOURCE_OUTPUT) { return (getSourceOutDir() == null ? null : List.of(getSourceOutDir())); } else return paths.getPathForLocation(location); }
@Override public List<Type> visitTypeVar(TypeVar t, Void ignored) { if (t.bound.isCompound()) return interfaces(t.bound); if (t.bound.isInterface()) return List.of(t.bound); return List.nil(); } };
/** Generate a base clause for an enum type. * @param pos The position for trees and diagnostics, if any * @param c The class symbol of the enum */ private JCExpression enumBase(int pos, ClassSymbol c) { JCExpression result = make.at(pos). TypeApply(make.QualIdent(syms.enumSym), List.<JCExpression>of(make.Type(c.type))); return result; }
/** Generate a base clause for an enum type. * @param pos The position for trees and diagnostics, if any * @param c The class symbol of the enum */ private JCExpression enumBase(int pos, ClassSymbol c) { JCExpression result = make.at(pos). TypeApply(make.QualIdent(syms.enumSym), List.<JCExpression>of(make.Type(c.type))); return result; }
static Type makeClassType(Types types, Type type) { Type arg = type.isPrimitive() ? types.boxedClass(type).type : types.erasure(type); return new Type.ClassType(types.syms.classType.getEnclosingType(), List.of(arg), types.syms.classType.tsym); } public String toString() {
@Override protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { Scope sc = new Scope(syms.arrayClass); MethodSymbol arrayConstr = new MethodSymbol(PUBLIC, name, null, site.tsym); arrayConstr.type = new MethodType(List.<Type>of(syms.intType), site, List.<Type>nil(), syms.methodClass); sc.enter(arrayConstr); return findMethodInScope(env, site, name, argtypes, typeargtypes, sc, methodNotFound, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false); }
private Symbol.MethodSymbol findReflectUtilConstructor( JCTree.JCNewClass tree ) { Symtab symtab = _tp.getSymtab(); Type.ArrayType classArrayType = new Type.ArrayType( symtab.classType, symtab.arrayClass ); Type.ArrayType objectArrayType = new Type.ArrayType( symtab.objectType, symtab.arrayClass ); List<Type> paramTypes = List.of( symtab.classType, classArrayType, objectArrayType ); Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() ); Names names = Names.instance( _tp.getContext() ); return resolveMethod( tree.pos(), names.fromString( "construct" ), reflectMethodClassSym.type, paramTypes ); }