@Override public void visitDoLoop(JCDoWhileLoop tree) { aPrint("do "); if (tree.body instanceof JCBlock) { println("{"); indent++; print(((JCBlock) tree.body).stats, ""); indent--; aPrint("}"); } else print(tree.body); print(" while "); if (tree.cond instanceof JCParens) { print(tree.cond); } else { print("("); print(tree.cond); print(")"); } println(";", tree); }
/** * This function walks into a tree with nodes of type JCBinary to search for * a string as one of the elements of the tree. * @param toTest The String searched as Element in the tree. * @param expression The bifurcation tree searched. * @return True if the string was found, or False. */ private boolean isThereInMiniTree(String toTest, JCTree expression) { if(expression instanceof JCParens){ if(isThereInMiniTree(toTest, ((JCParens) expression).expr)) return true; } else if(expression instanceof JCIdent){ if(((JCIdent) expression).name.toString().equals(toTest)) return true; } else if(expression instanceof JCBinary){ if(isThereInMiniTree(toTest, ((JCBinary) expression).rhs)) return true; if(isThereInMiniTree(toTest, ((JCBinary) expression).lhs)) return true; } return false; }
/** * Verify if the boolean expression have a true value despite of any variable values. * @param expression The boolean expression examined. * @return 1 When the expression is always true. */ private int hasTrueValue(JCTree expression) { if(expression instanceof JCParens){ if(hasTrueValue(((JCParens)expression).expr) != 0) return 1; }else if(expression instanceof JCLiteral){ if(((JCLiteral) expression).value == null) return VAR_FALSE_VALUE; return (int) ((JCLiteral) expression).value; }else if(expression instanceof JmlSingleton){ return 1; }else if(expression instanceof JCBinary){ return resolveBooleanOperations(expression); } return VAR_FALSE_VALUE; }
@Override public Description matchWhileLoop(WhileLoopTree tree, VisitorState state) { JCWhileLoop whileLoop = (JCWhileLoop) tree; JCExpression whileExpression = ((JCParens) whileLoop.getCondition()).getExpression(); if (whileExpression instanceof MethodInvocationTree) { MethodInvocationTree methodInvocation = (MethodInvocationTree) whileExpression; if (methodSelect(isDescendantOfMethod("java.util.Iterator", "hasNext()")).matches( methodInvocation, state)) { IdentifierTree identifier = getIncrementedIdentifer(extractSingleStatement(whileLoop.body)); if (identifier != null) { return describeMatch(tree, new SuggestedFix()); } } } return Description.NO_MATCH; }
protected int diffParens(JCParens oldT, JCParens newT, int[] bounds) { int localPointer = bounds[0]; copyTo(localPointer, getCommentCorrectedOldPos(oldT.expr)); localPointer = diffTree(oldT.expr, newT.expr, getBounds(oldT.expr)); copyTo(localPointer, bounds[1]); return bounds[1]; }
@Override public void visitWhileLoop(JCWhileLoop tree) { aPrint("while "); if (tree.cond instanceof JCParens) { print(tree.cond); } else { print("("); print(tree.cond); print(")"); } print(" "); print(tree.body); // make sure to test while (true) ; and while(true){} and while(true) x = 5; }
@Override public void visitIf(JCIf tree) { aPrint("if "); if (tree.cond instanceof JCParens) { print(tree.cond); } else { print("("); print(tree.cond); print(")"); } print(" "); if (tree.thenpart instanceof JCBlock) { println("{"); indent++; print(((JCBlock) tree.thenpart).stats, ""); indent--; if (tree.elsepart == null) { aPrintln("}", tree); } else { aPrint("}"); } } else { print(tree.thenpart); } if (tree.elsepart != null) { aPrint(" else "); print(tree.elsepart); } }
@Override public void visitSynchronized(JCSynchronized tree) { aPrint("synchronized "); if (tree.lock instanceof JCParens) { print(tree.lock); } else { print("("); print(tree.lock); print(")"); } print(" "); print(tree.body); }
@Override public void visitSwitch(JCSwitch tree) { aPrint("switch "); if (tree.selector instanceof JCParens) { print(tree.selector); } else { print("("); print(tree.selector); print(")"); } println(" {"); print(tree.cases, "\n"); aPrintln("}", tree); }
/** * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;}, * where the block braces are optional. If it is of this form, returns "x". * If it is not of this form, returns null. */ public String returnVarNameIfNullCheck(JCStatement stat) { if (!(stat instanceof JCIf)) return null; /* Check that the if's statement is a throw statement, possibly in a block. */ { JCStatement then = ((JCIf) stat).thenpart; if (then instanceof JCBlock) { List<JCStatement> stats = ((JCBlock) then).stats; if (stats.length() == 0) return null; then = stats.get(0); } if (!(then instanceof JCThrow)) return null; } /* Check that the if's conditional is like 'x == null'. Return from this method (don't generate a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ { JCExpression cond = ((JCIf) stat).cond; while (cond instanceof JCParens) cond = ((JCParens) cond).expr; if (!(cond instanceof JCBinary)) return null; JCBinary bin = (JCBinary) cond; if (!CTC_EQUAL.equals(treeTag(bin))) return null; if (!(bin.lhs instanceof JCIdent)) return null; if (!(bin.rhs instanceof JCLiteral)) return null; if (!CTC_BOT.equals(typeTag(bin.rhs))) return null; return ((JCIdent) bin.lhs).name.toString(); } }
public void visitParens(JCParens that) { try { print("JCParens:"); } catch (Exception e) { } super.visitParens(that); }
public void visitParens(JCParens tree) { try { print("("); printExpr(tree.expr); print(")"); } catch (IOException e) { throw new UncheckedIOException(e); } }
public void visitParens(JCParens tree) { Type owntype = attribTree(tree.expr, env, pkind, pt); result = check(tree, owntype, pkind, pkind, pt); Symbol sym = TreeInfo.symbol(tree); if (sym != null && (sym.kind&(TYP|PCK)) != 0) log.error(tree.pos(), "illegal.start.of.type"); }
@Override public void visitParens(JCParens that) { processArg(that, speculativeTree -> new ParensType(that, env, speculativeTree)); }
ParensType(JCExpression tree, Env<AttrContext> env, JCParens speculativeParens) { this(tree, env, speculativeParens, new HashMap<>()); }
ParensType(JCExpression tree, Env<AttrContext> env, JCParens speculativeParens, Map<ResultInfo, Type> speculativeTypes) { super(tree, env, speculativeParens, speculativeTypes); }
@Override ArgumentType<JCParens> dup(JCParens tree, Env<AttrContext> env) { return new ParensType(tree, env, speculativeTree, speculativeTypes); }
public JCParens Parens(JCExpression expr) { return invoke(Parens, expr); }
@Override public void visitParens(JCParens tree) { print("("); print(tree.expr); print(")"); }
public AJCParens(JCParens ltree) { super(ltree.expr); }
public AJCParens(JCParens ltree, String lcomment) { this(ltree); setComment(lcomment); }
@Override public JCParens inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().Parens(getExpression().inline(inliner)); }
@Override public void visitParens(JCParens tree) { printNode(tree); child("expr", tree.expr); indent--; }
private static JCTree removeParens(JCTree node) { if (!(node instanceof JCParens)) return node; return ((JCParens) node).getExpression(); }
@Override public void visitParens(JCParens node) { Expression expr = (Expression) toTree(node.getExpression()); expr.astParensPositions().add(getPosition(node)); set(node, expr); }
@Override public Choice<State<JCParens>> visitParenthesized(ParenthesizedTree node, State<?> state) { return chooseSubtrees(state, s -> unifyExpression(node.getExpression(), s), maker()::Parens); }