private boolean suppress(JCTree tree) { if (tree instanceof JCBlock) { JCBlock block = (JCBlock) tree; return (Position.NOPOS == block.pos) && block.stats.isEmpty(); } if (tree instanceof JCExpressionStatement) { JCExpression expr = ((JCExpressionStatement)tree).expr; if (expr instanceof JCMethodInvocation) { JCMethodInvocation inv = (JCMethodInvocation) expr; if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false; if (!(inv.meth instanceof JCIdent)) return false; return ((JCIdent) inv.meth).name.toString().equals("super"); } } return false; }
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); }
/** * Verify if all variables were initialized on the constructor. * @param block The lines of the constructor. * @return true if all variables were initialized on the constructor. */ private boolean isAllVariableInitialized(JCBlock block) { for (com.sun.tools.javac.util.List<JCStatement> traversing = block.stats; !traversing.isEmpty(); traversing = traversing.tail){ if(traversing.head instanceof JCExpressionStatement){ if(((JCExpressionStatement) traversing.head).expr instanceof JCAssign && !((JCAssign) ((JCExpressionStatement) traversing.head).expr).rhs.toString().equals("null")){ String toTest = ((JCAssign) ((JCExpressionStatement) traversing.head).expr).lhs.toString(); int i = 0; boolean isNecessaryToRemove = false; for(i = 0; i < this.variables.size(); i++){ if(toTest.equals(this.variables.get(i)) || toTest.equals("this." + this.variables.get(i))){ isNecessaryToRemove = true; break; } } if(isNecessaryToRemove) this.variables.remove(i); } } } return this.variables.isEmpty(); }
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 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"); }
protected int diffExec(JCExpressionStatement oldT, JCExpressionStatement newT, int[] bounds) { int localPointer = bounds[0]; // expr int[] exprBounds = getBounds(oldT.expr); copyTo(localPointer, exprBounds[0]); localPointer = diffTree(oldT.expr, newT.expr, exprBounds); copyTo(localPointer, bounds[1]); return bounds[1]; }
@Override public void visitExec(final JCExpressionStatement node) { if (substitutionInventory.referencesSubstitutableField(node)) { // Visit once per descriptor replacement. replacements.forEach(field -> { substitutionStack.push(field); super.visitExec(node); substitutionStack.pop(); print("\n"); }); } else { super.visitExec(node); } }
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)); }
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."); } } }
public void visitExec(JCExpressionStatement that) { try { print("JCExpressionStatement:"); } catch (Exception e) { } super.visitExec(that); }
private boolean isSuppressed(JCTree tree) { if (isEmptyStat(tree)) { return true; } if (tree instanceof JCExpressionStatement) { return isNoArgsSuperCall(((JCExpressionStatement)tree).expr); } return false; }
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); } }
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)); }
private boolean doesCallSuper (List list, String methodName) { for (Object object : list) { if (object instanceof JCTree.JCExpressionStatement) { JCTree.JCExpressionStatement expr = (JCExpressionStatement) object; String exprString = expr.toString(); if (exprString.startsWith("super." + methodName) && exprString.endsWith(");")) return true; } } return false; }
@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)); }
@Override public boolean visitAlternateConstructorInvocation(AlternateConstructorInvocation node) { int thisStart, thisEnd; Position jcThisPos = getConversionPositionInfo(node, "this"); thisStart = jcThisPos == null ? (!node.astConstructorTypeArguments().isEmpty() ? posOfStructure(node, "<", true) : posOfStructure(node, "this", true)) : jcThisPos.getStart(); thisEnd = jcThisPos == null ? posOfStructure(node, "this", false) : jcThisPos.getEnd(); JCMethodInvocation invoke = treeMaker.Apply( toList(JCExpression.class, node.astConstructorTypeArguments()), setPos(thisStart, thisEnd, treeMaker.Ident(table._this)), toList(JCExpression.class, node.astArguments())); int start, end; if (hasSourceStructures()) { start = posOfStructure(node, "(", true); end = posOfStructure(node, ")", false); } else { start = node.getPosition().getStart(); end = node.getPosition().getEnd(); } JCExpressionStatement exec = treeMaker.Exec(setPos(start, end, invoke)); Position jcExecPos = getConversionPositionInfo(node, "exec"); if (jcExecPos != null) { setPos(jcExecPos.getStart(), jcExecPos.getEnd(), exec); } else { setPos(node, exec); } return set(node, exec); }
@Override public void visitExec(JCExpressionStatement node) { Node expr = toTree(node.getExpression()); if (expr instanceof SuperConstructorInvocation || expr instanceof AlternateConstructorInvocation) { setConversionPositionInfo(expr, "exec", getPosition(node)); set(node, expr); return; } ExpressionStatement exec = new ExpressionStatement(); exec.rawExpression(expr); set(node, exec); }
@Override public void visitForLoop(JCForLoop node) { For f = new For(); f.rawCondition(toTree(node.getCondition())); f.rawStatement(toTree(node.getStatement())); for (JCExpressionStatement upd : node.getUpdate()) { Node updateNode = toTree(upd.getExpression()); setConversionPositionInfo(updateNode, "exec", getPosition(upd)); f.rawUpdates().addToEnd(updateNode); } List<JCStatement> initializers = node.getInitializer(); // Multiple vardefs in a row need to trigger the JCVD version AND be washed through fillList to be turned into 1 VD. if (!initializers.isEmpty() && initializers.get(0) instanceof JCVariableDecl) { Block tmp = new Block(); fillList(initializers, tmp.rawContents(), FlagKey.VARDEF_IS_DEFINITION); Node varDecl = tmp.rawContents().first(); if (varDecl != null) varDecl.unparent(); f.rawVariableDeclaration(varDecl); } else { for (JCStatement init : initializers) { if (init instanceof JCExpressionStatement) { Node initNode = toTree(((JCExpressionStatement) init).getExpression()); setConversionPositionInfo(initNode, "exec", getPosition(init)); f.rawExpressionInits().addToEnd(initNode); } else { f.rawExpressionInits().addToEnd(toTree(init)); } } } set(node, f); }
/** * Verify if some variable from class or parameter from the method are receiving a value * in an attribution. * @param params The parameters from the method. * @param block The code lines from the method. * @return true If the method attribute value to some field. */ private boolean isSomeVarOtAtrGettingAttribution(com.sun.tools.javac.util.List<JCVariableDecl> params, JCBlock block) { for (com.sun.tools.javac.util.List<JCStatement> traversing = block.stats; !traversing.isEmpty(); traversing = traversing.tail){ if(traversing.head instanceof JCExpressionStatement){ if(verifyAttribution(params, ((JCExpressionStatement) traversing.head).expr)) return true; else if(((JCExpressionStatement) traversing.head).expr instanceof JCMethodInvocation) return true; } } return false; }
@Override public Choice<State<JCForLoop>> visitForLoop(final ForLoopTree node, State<?> state) { return chooseSubtrees( state, s -> unifyStatements(node.getInitializer(), s), s -> unifyExpression(node.getCondition(), s), s -> unifyStatements(node.getUpdate(), s), s -> unifyStatement(node.getStatement(), s), (inits, cond, update, stmt) -> maker().ForLoop(inits, cond, List.convert(JCExpressionStatement.class, update), stmt)); }
@Override public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException { return inliner .maker() .ForLoop( UBlock.inlineStatementList(getInitializer(), inliner), (getCondition() == null) ? null : getCondition().inline(inliner), com.sun.tools.javac.util.List.convert( JCExpressionStatement.class, inliner.<JCStatement>inlineList(getUpdate())), getStatement().inline(inliner)); }
/** MoreStatementExpressions = { COMMA StatementExpression } */ <T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos, JCExpression first, T stats) { // This Exec is a "StatementExpression"; it subsumes no terminating token stats.append(toP(F.at(pos).Exec(checkExprStat(first)))); while (S.token() == COMMA) { S.nextToken(); pos = S.pos(); JCExpression t = parseExpression(); // This Exec is a "StatementExpression"; it subsumes no terminating token stats.append(toP(F.at(pos).Exec(checkExprStat(t)))); } return stats; }
public void visitExec(JCExpressionStatement tree) { try { printExpr(tree.expr); if (prec == TreeInfo.notExpression) print(";"); } catch (IOException e) { throw new UncheckedIOException(e); } }
public void visitExec(JCExpressionStatement tree) { //a fresh environment is required for 292 inference to work properly --- //see Infer.instantiatePolymorphicSignatureInstance() Env<AttrContext> localEnv = env.dup(tree); // de.so.ma // check for JCSqlQuery SqlQueryNodeTransformer transformer = SqlQueryNodeTransformer.getInstance(); tree.expr = transformer.transformPotentialSqlQuery( tree.expr, localEnv, null, this, enter, memberEnter); attribExpr(tree.expr, localEnv); result = null; }
/** Check that given application node appears as first statement * in a constructor call. * @param tree The application node * @param env The environment current at the application. */ boolean checkFirstConstructorStat(JCMethodInvocation tree, Env<AttrContext> env) { JCMethodDecl enclMethod = env.enclMethod; if (enclMethod != null && enclMethod.name == names.init) { JCBlock body = enclMethod.body; if (body.stats.head.getTag() == JCTree.EXEC && ((JCExpressionStatement) body.stats.head).expr == tree) return true; } log.error(tree.pos(),"call.must.be.first.stmt.in.ctor", TreeInfo.name(tree.meth)); return false; }
private boolean isConstructorCall(final JCStatement supect) { if (!(supect instanceof JCExpressionStatement)) return false; final JCExpression supectExpression = ((JCExpressionStatement) supect).expr; if (!(supectExpression instanceof JCMethodInvocation)) return false; final String methodName = ((JCMethodInvocation) supectExpression).meth.toString(); return "super".equals(methodName) || "this".equals(methodName); }
private JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) { /* result = result * PRIME + (expr); */ TreeMaker 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)); }
private 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."); } } }
@Override public void visit(ForWrapper w) { result = builder.getTreeMaker().ForLoop( generate(w.getInitStatements(), JCStatement.class), generate(w.getCondition()), generate(w.getUpdateStatements(), JCExpressionStatement.class), generate(w.getStatement())); }
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) { return invoke(ForLoop, init, cond, step, body); }
public JCExpressionStatement Exec(JCExpression expr) { return invoke(Exec, expr); }
@Override public void visitExec(JCExpressionStatement tree) { align(); print(tree.expr); println(";", tree); }
public AJCExpressionStatement(JCExpressionStatement ltree) { super(ltree.expr); }
public AJCExpressionStatement(JCExpressionStatement ltree, String lcomment) { this(ltree); setComment(lcomment); }