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; } },
@Override public JCExpression staticReference( Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz, CharSequence member) { return inliner .maker() .Select( classReference(inliner, topLevelClazz, fullyQualifiedClazz), inliner.asName(member)); }
@Override public JCExpression staticReference( Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz, CharSequence member) { if (Refaster.class.getName().contentEquals(topLevelClazz)) { // Special handling to ensure that the pretty-printer always recognizes Refaster references return inliner .maker() .Select(inliner.maker().Ident(inliner.asName("Refaster")), inliner.asName(member)); } return inliner .maker() .Select( classReference(inliner, topLevelClazz, fullyQualifiedClazz), inliner.asName(member)); } },
@Override public Choice<State<JCFieldAccess>> visitMemberSelect( final MemberSelectTree node, State<?> state) { return chooseSubtrees( state, s -> unifyExpression(node.getExpression(), s), expr -> maker().Select(expr, (Name) node.getIdentifier())); }
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; }
@Override public JCExpression staticReference( Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz, CharSequence member) { if (Refaster.class.getName().contentEquals(topLevelClazz)) { // Special handling to ensure that the pretty-printer always recognizes Refaster references return inliner .maker() .Select(inliner.maker().Ident(inliner.asName("Refaster")), inliner.asName(member)); } inliner.addStaticImport(fullyQualifiedClazz + "." + member); return inliner.maker().Ident(inliner.asName(member)); } };
@Override public JCExpression inline(Inliner inliner) throws CouldNotResolveImportException { JCExpression expression = getExpression().inline(inliner); if (expression.toString().equals(CONVERT_TO_IDENT)) { return inliner.maker().Ident(getIdentifier().inline(inliner)); } // TODO(lowasser): consider inlining this.foo() as foo() return inliner.maker().Select(getExpression().inline(inliner), getIdentifier().inline(inliner)); } }
/** Create a tree representing a class literal. */ public JCExpression ClassLiteral(Type t) { VarSymbol lit = new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, t.tsym); return Select(Type(t), lit); }
/** Create a tree representing a class literal. */ public JCExpression ClassLiteral(Type t) { VarSymbol lit = new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, t.tsym); return Select(Type(t), lit); }
@Override public JCExpression staticReference( Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz, CharSequence member) { return inliner .maker() .Select( classReference(inliner, topLevelClazz, fullyQualifiedClazz), inliner.asName(member)); }
/** Create an attributed tree of the form left.name(). */ private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) { assert left.type != null; Symbol funcsym = lookupMethod(make_pos, name, left.type, TreeInfo.types(args)); return make.App(make.Select(left, funcsym), args); }
/** Create a qualified identifier from a symbol, adding enough qualifications * to make the reference unique. */ public JCExpression QualIdent(Symbol sym) { return isUnqualifiable(sym) ? Ident(sym) : Select(QualIdent(sym.owner), sym); }
/** Create an attributed tree of the form left.name(). */ private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) { Assert.checkNonNull(left.type); Symbol funcsym = lookupMethod(make_pos, name, left.type, TreeInfo.types(args)); return make.App(make.Select(left, funcsym), args); }
@Override public boolean visitSelect(Select node) { int start = posOfStructure(node.astIdentifier(), ".", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Select(toExpression(node.astOperand()), toName(node.astIdentifier())))); }
@Override public boolean visitImportDeclaration(ImportDeclaration node) { JCExpression name = chain(node.astParts()); if (node.astStarImport()) { int start, end; Position jcDotStarPos = getConversionPositionInfo(node, ".*"); start = jcDotStarPos == null ? posOfStructure(node, ".", true) : jcDotStarPos.getStart(); end = jcDotStarPos == null ? posOfStructure(node, "*", false) : jcDotStarPos.getEnd(); name = setPos(start, end, treeMaker.Select(name, table.asterisk)); } return posSet(node, treeMaker.Import(name, node.astStaticImport())); }
private JCExpression chain(Iterable<Identifier> parts) { JCExpression previous = null; for (Identifier part : parts) { Name next = toName(part); if (previous == null) { previous = setPos(part, treeMaker.Ident(next)); } else { previous = setPos(posOfStructure(part, ".", true), part.getPosition().getEnd(), treeMaker.Select(previous, next)); } } return previous; }
/** Unbox an object to a primitive value. */ JCExpression unbox(JCExpression tree, Type primitive) { Type unboxedType = types.unboxedType(tree.type); // note: the "primitive" parameter is not used. There muse be // a conversion from unboxedType to primitive. make_at(tree.pos()); Symbol valueSym = lookupMethod(tree.pos(), unboxedType.tsym.name.append(names.Value), // x.intValue() tree.type, List.<Type>nil()); return make.App(make.Select(tree, valueSym)); }
@Override public JCExpression inline(Inliner inliner) throws CouldNotResolveImportException { JCExpression expression = getExpression().inline(inliner); if (expression.toString().equals(CONVERT_TO_IDENT)) { return inliner.maker().Ident(getIdentifier().inline(inliner)); } // TODO(lowasser): consider inlining this.foo() as foo() return inliner.maker().Select(getExpression().inline(inliner), getIdentifier().inline(inliner)); } }
/** * Qualident = Ident { DOT Ident } */ public JCExpression qualident() { JCExpression t = toP(F.at(S.pos()).Ident(ident())); while (S.token() == DOT) { int pos = S.pos(); S.nextToken(); t = toP(F.at(pos).Select(t, ident())); } return t; }
/** * Qualident = Ident { DOT Ident } */ public JCExpression qualident() { JCExpression t = toP(F.at(S.pos()).Ident(ident())); while (S.token() == DOT) { int pos = S.pos(); S.nextToken(); t = toP(F.at(pos).Select(t, ident())); } return t; }