com.sun.tools.javac.tree.JCTree.JCExpressionStatement Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCExpressionStatement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreePruner.java From bazel with Apache License 2.0 | 6 votes |
private static boolean delegatingConstructor(List<JCStatement> stats) { if (stats.isEmpty()) { return false; } JCStatement stat = stats.get(0); if (stat.getKind() != Kind.EXPRESSION_STATEMENT) { return false; } JCExpression expr = ((JCExpressionStatement) stat).getExpression(); if (expr.getKind() != Kind.METHOD_INVOCATION) { return false; } JCExpression method = ((JCMethodInvocation) expr).getMethodSelect(); Name name; switch (method.getKind()) { case IDENTIFIER: name = ((JCIdent) method).getName(); break; case MEMBER_SELECT: name = ((JCFieldAccess) method).getIdentifier(); break; default: return false; } return name.contentEquals("this") || name.contentEquals("super"); }
Example #2
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
private ForStatement convertForLoop(JCForLoop statement) { return ForStatement.newBuilder() // The order here is important since initializers can define new variables // These can be used in the expression, updaters or the body // This is why we need to process initializers first .setInitializers(convertInitializers(statement.getInitializer())) .setConditionExpression(convertExpressionOrNull(statement.getCondition())) .setBody(convertStatement(statement.getStatement())) .setUpdates( convertExpressions( statement.getUpdate().stream() .map(JCExpressionStatement::getExpression) .collect(toImmutableList()))) .setSourcePosition(getSourcePosition(statement)) .build(); }
Example #3
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 6 votes |
public static boolean isConstructorCall(final JCStatement statement) { if (!(statement instanceof JCExpressionStatement)) return false; JCExpression expr = ((JCExpressionStatement) statement).expr; if (!(expr instanceof JCMethodInvocation)) return false; JCExpression invocation = ((JCMethodInvocation) expr).meth; String name; if (invocation instanceof JCFieldAccess) { name = ((JCFieldAccess) invocation).name.toString(); } else if (invocation instanceof JCIdent) { name = ((JCIdent) invocation).name.toString(); } else { name = ""; } return "super".equals(name) || "this".equals(name); }
Example #4
Source File: UForLoop.java From Refaster with Apache License 2.0 | 5 votes |
@Override public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().ForLoop( inliner.inlineList(getInitializer()), (getCondition() == null) ? null : getCondition().inline(inliner), com.sun.tools.javac.util.List.convert( JCExpressionStatement.class, inliner.inlineList(getUpdate())), getStatement().inline(inliner)); }
Example #5
Source File: HandleCleanup.java From EasyMPermission with MIT License | 5 votes |
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) { if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name); if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node, ((JCExpressionStatement)statement).expr, name); if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name); if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name); if (statement instanceof JCIdent) { if (((JCIdent)statement).name.contentEquals(name)) { JavacNode problemNode = node.getNodeFor(statement); if (problemNode != null) problemNode.addWarning( "You're assigning an auto-cleanup variable to something else. This is a bad idea."); } } }
Example #6
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 5 votes |
private Expression convertInitializer(JCStatement statement) { switch (statement.getKind()) { case EXPRESSION_STATEMENT: return convertExpression(((JCExpressionStatement) statement).expr); default: throw new AssertionError(); } }
Example #7
Source File: HandleEqualsAndHashCode.java From EasyMPermission with MIT License | 5 votes |
public JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) { /* result = result * PRIME + (expr); */ JavacTreeMaker maker = typeNode.getTreeMaker(); Name resultName = typeNode.toName(RESULT_NAME); JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME))); JCExpression add = maker.Binary(CTC_PLUS, mult, expr); return maker.Exec(maker.Assign(maker.Ident(resultName), add)); }
Example #8
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 5 votes |
public void visitExec(JCExpressionStatement tree) { if (isNoArgsSuperCall(tree.expr)) return; try { printExpr(tree.expr); if (prec == TreeInfo.notExpression) print(";"); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #9
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 5 votes |
private boolean isSuppressed(JCTree tree) { if (isEmptyStat(tree)) { return true; } if (tree instanceof JCExpressionStatement) { return isNoArgsSuperCall(((JCExpressionStatement)tree).expr); } return false; }
Example #10
Source File: JavacTreeMaker.java From EasyMPermission with MIT License | 4 votes |
public JCExpressionStatement Exec(JCExpression expr) { return invoke(Exec, expr); }
Example #11
Source File: UExpressionStatement.java From Refaster with Apache License 2.0 | 4 votes |
@Override public JCExpressionStatement inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().Exec(getExpression().inline(inliner)); }
Example #12
Source File: CRTable.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitExec(JCExpressionStatement tree) { SourceRange sr = new SourceRange(startPos(tree), endPos(tree)); sr.mergeWith(csp(tree.expr)); result = sr; }
Example #13
Source File: JavacTreeMaker.java From EasyMPermission with MIT License | 4 votes |
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) { return invoke(ForLoop, init, cond, step, body); }
Example #14
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 4 votes |
private Statement convertStatement(JCStatement jcStatement) { switch (jcStatement.getKind()) { case ASSERT: return convertAssert((JCAssert) jcStatement); case BLOCK: return convertBlock((JCBlock) jcStatement); case BREAK: return convertBreak((JCBreak) jcStatement); case CLASS: convertClassDeclaration((JCClassDecl) jcStatement); return null; case CONTINUE: return convertContinue((JCContinue) jcStatement); case DO_WHILE_LOOP: return convertDoWhileLoop((JCDoWhileLoop) jcStatement); case EMPTY_STATEMENT: return new EmptyStatement(getSourcePosition(jcStatement)); case ENHANCED_FOR_LOOP: return convertEnhancedForLoop((JCEnhancedForLoop) jcStatement); case EXPRESSION_STATEMENT: return convertExpressionStatement((JCExpressionStatement) jcStatement); case FOR_LOOP: return convertForLoop((JCForLoop) jcStatement); case IF: return convertIf((JCIf) jcStatement); case LABELED_STATEMENT: return convertLabeledStatement((JCLabeledStatement) jcStatement); case RETURN: return convertReturn((JCReturn) jcStatement); case SWITCH: return convertSwitch((JCSwitch) jcStatement); case THROW: return convertThrow((JCThrow) jcStatement); case TRY: return convertTry((JCTry) jcStatement); case VARIABLE: return convertVariableDeclaration((JCVariableDecl) jcStatement); case WHILE_LOOP: return convertWhileLoop((JCWhileLoop) jcStatement); case SYNCHRONIZED: return convertSynchronized((JCSynchronized) jcStatement); default: throw new AssertionError("Unknown statement node type: " + jcStatement.getKind()); } }
Example #15
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 4 votes |
private Statement convertExpressionStatement(JCExpressionStatement statement) { return convertExpression(statement.getExpression()).makeStatement(getSourcePosition(statement)); }
Example #16
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * A statement of the form * * <pre> * for ( T v : arrayexpr ) stmt; * </pre> * * (where arrayexpr is of an array type) gets translated to * * <pre>{@code * for ( { arraytype #arr = arrayexpr; * int #len = array.length; * int #i = 0; }; * #i < #len; i$++ ) { * T v = arr$[#i]; * stmt; * } * }</pre> * * where #arr, #len, and #i are freshly named synthetic local variables. */ private void visitArrayForeachLoop(JCEnhancedForLoop tree) { make_at(tree.expr.pos()); VarSymbol arraycache = new VarSymbol(SYNTHETIC, names.fromString("arr" + target.syntheticNameChar()), tree.expr.type, currentMethodSym); JCStatement arraycachedef = make.VarDef(arraycache, tree.expr); VarSymbol lencache = new VarSymbol(SYNTHETIC, names.fromString("len" + target.syntheticNameChar()), syms.intType, currentMethodSym); JCStatement lencachedef = make. VarDef(lencache, make.Select(make.Ident(arraycache), syms.lengthVar)); VarSymbol index = new VarSymbol(SYNTHETIC, names.fromString("i" + target.syntheticNameChar()), syms.intType, currentMethodSym); JCVariableDecl indexdef = make.VarDef(index, make.Literal(INT, 0)); indexdef.init.type = indexdef.type = syms.intType.constType(0); List<JCStatement> loopinit = List.of(arraycachedef, lencachedef, indexdef); JCBinary cond = makeBinary(LT, make.Ident(index), make.Ident(lencache)); JCExpressionStatement step = make.Exec(makeUnary(PREINC, make.Ident(index))); Type elemtype = types.elemtype(tree.expr.type); JCExpression loopvarinit = make.Indexed(make.Ident(arraycache), make.Ident(index)).setType(elemtype); JCVariableDecl loopvardef = (JCVariableDecl)make.VarDef(tree.var.mods, tree.var.name, tree.var.vartype, loopvarinit).setType(tree.var.type); loopvardef.sym = tree.var.sym; JCBlock body = make. Block(0, List.of(loopvardef, tree.body)); result = translate(make. ForLoop(loopinit, cond, List.of(step), body)); patchTargets(body, tree, result); }
Example #17
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void visitExec(JCExpressionStatement tree) { tree.expr = translate(tree.expr, null); result = tree; }
Example #18
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** Generate call to superclass constructor. This is: * * super(id_0, ..., id_n) * * or, if based == true * * id_0.super(id_1,...,id_n) * * where id_0, ..., id_n are the names of the given parameters. * * @param make The tree factory * @param params The parameters that need to be passed to super * @param typarams The type parameters that need to be passed to super * @param based Is first parameter a this$n? */ JCExpressionStatement SuperCall(TreeMaker make, List<Type> typarams, List<JCVariableDecl> params, boolean based) { JCExpression meth; if (based) { meth = make.Select(make.Ident(params.head), names._super); params = params.tail; } else { meth = make.Ident(names._super); } List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); }