private static List<? extends TypeMirror> computeParenthesis(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { ParenthesizedTree pt = (ParenthesizedTree) parent.getLeaf(); if (pt.getExpression() != error) { return null; } TreePath parentParent = parent.getParentPath(); List<? extends TypeMirror> upperTypes = resolveType(types, info, parentParent, pt, offset, null, null); if (upperTypes == null) { return null; } return upperTypes; }
@Override protected void performRewrite(TransformationContext ctx) { WorkingCopy wc = ctx.getWorkingCopy(); TreePath path = ctx.getPath(); TypeCastTree tct = (TypeCastTree) path.getLeaf(); ExpressionTree expression = tct.getExpression(); while (expression.getKind() == Kind.PARENTHESIZED && !JavaFixUtilities.requiresParenthesis(((ParenthesizedTree) expression).getExpression(), tct, path.getParentPath().getLeaf())) { expression = ((ParenthesizedTree) expression).getExpression(); } while (path.getParentPath().getLeaf().getKind() == Kind.PARENTHESIZED && !JavaFixUtilities.requiresParenthesis(expression, path.getLeaf(), path.getParentPath().getParentPath().getLeaf())) { path = path.getParentPath(); } wc.rewrite(path.getLeaf(), expression); }
@Override protected void performRewrite(final TransformationContext ctx) throws Exception { IfTree toRewrite = (IfTree) ctx.getPath().getLeaf(); StatementTree elseStatement = toRewrite.getElseStatement(); if (toRewrite.getCondition() == null || toRewrite.getCondition().getKind() != Tree.Kind.PARENTHESIZED) { return; } ParenthesizedTree ptt = (ParenthesizedTree)toRewrite.getCondition(); if (ptt.getExpression() == null) { return; } if (elseStatement == null) elseStatement = ctx.getWorkingCopy().getTreeMaker().Block(Collections.<StatementTree>emptyList(), false); ctx.getWorkingCopy().rewrite(toRewrite, ctx.getWorkingCopy().getTreeMaker().If(toRewrite.getCondition(), elseStatement, toRewrite.getThenStatement())); ExpressionTree negated = Utilities.negate( ctx.getWorkingCopy().getTreeMaker(), ptt.getExpression(), ptt); ctx.getWorkingCopy().rewrite(ptt.getExpression(), negated); }
/** * strip out enclosing parentheses and type casts. * * @param expr * @return */ private static ExpressionTree stripParensAndCasts(ExpressionTree expr) { boolean someChange = true; while (someChange) { someChange = false; if (expr.getKind().equals(PARENTHESIZED)) { expr = ((ParenthesizedTree) expr).getExpression(); someChange = true; } if (expr.getKind().equals(TYPE_CAST)) { expr = ((TypeCastTree) expr).getExpression(); someChange = true; } } return expr; }
@Override public Tree visitParenthesized(ParenthesizedTree tree, Void p) { ParenthesizedTree n = make.Parenthesized(tree.getExpression()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
public Boolean visitParenthesized(ParenthesizedTree node, TreePath p) { if (p == null) return super.visitParenthesized(node, p); ParenthesizedTree t = (ParenthesizedTree) p.getLeaf(); return scan(node.getExpression(), t.getExpression(), p); }
@Override public Void visitParenthesized(ParenthesizedTree tree, EnumSet<UseTypes> d) { ExpressionTree expr = tree.getExpression(); if (expr instanceof IdentifierTree) { handlePossibleIdentifier(new TreePath(getCurrentPath(), expr), EnumSet.of(UseTypes.READ)); } super.visitParenthesized(tree, d); return null; }
@Override public Object visitParenthesized(ParenthesizedTree node, Object p) { boolean b = isCorrectType(node); currentMatches = b; Object o = super.visitParenthesized(node, p); increment(node, b); return o; }
@Override public Void visitParenthesized(ParenthesizedTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitParenthesized(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
@TriggerPattern(value="$v=$this") // NOI18N public static ErrorDescription hintOnAssignment(HintContext ctx) { Map<String,TreePath> variables = ctx.getVariables (); TreePath thisPath = variables.get ("$this"); // NOI18N if ( thisPath.getLeaf().getKind() != Kind.IDENTIFIER || !((IdentifierTree) thisPath.getLeaf()).getName().contentEquals(THIS_KEYWORD)) { return null; } if (!Utilities.isInConstructor(ctx)) { return null; } TreePath storePath = variables.get("$v"); Tree t = storePath.getLeaf(); if (t.getKind() == Tree.Kind.MEMBER_SELECT) { t = ((MemberSelectTree)t).getExpression(); while (t != null && t.getKind() == Tree.Kind.PARENTHESIZED) { t = ((ParenthesizedTree)t).getExpression(); } if (t == null) { return null; } else if (t.getKind() == Tree.Kind.IDENTIFIER) { IdentifierTree it = (IdentifierTree)t; if (it.getName().contentEquals(THIS_KEYWORD) || it.getName().contentEquals(SUPER_KEYWORD)) { return null; } } } else { return null; } return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), NbBundle.getMessage( LeakingThisInConstructor.class, "MSG_org.netbeans.modules.java.hints.LeakingThisInConstructor")); }
private Type getSubExpressionType(Tree t) { Type type = subExpressionTypes.get(t); if (type != null) { return type; } else { if (t.getKind() == Tree.Kind.PARENTHESIZED) { return getSubExpressionType(((ParenthesizedTree) t).getExpression()); } return null; } }
private Element getElement(Tree tree) { TreePath expPath = TreePath.getPath(cut, tree); Element e = trees.getElement(expPath); if (e == null) { if (tree instanceof ParenthesizedTree) { e = getElement(((ParenthesizedTree) tree).getExpression()); //if (e == null) { // System.err.println("Have null element for "+tree); //} //System.err.println("\nHAVE "+e.asType().toString()+" for ParenthesizedTree "+tree); } else if (tree instanceof TypeCastTree) { e = getElement(((TypeCastTree) tree).getType()); //if (e == null) { // System.err.println("Have null element for "+tree); //} //System.err.println("\nHAVE "+e.asType().toString()+" for TypeCastTree "+tree); } else if (tree instanceof AssignmentTree) { e = getElement(((AssignmentTree) tree).getVariable()); } else if (tree instanceof ArrayAccessTree) { e = getElement(((ArrayAccessTree) tree).getExpression()); if (e != null) { TypeMirror tm = e.asType(); if (tm.getKind() == TypeKind.ARRAY) { tm = ((ArrayType) tm).getComponentType(); e = types.asElement(tm); } } //System.err.println("ArrayAccessTree = "+((ArrayAccessTree) tree).getExpression()+", element = "+getElement(((ArrayAccessTree) tree).getExpression())+", type = "+getElement(((ArrayAccessTree) tree).getExpression()).asType()); } } return e; }
@Override public Void visitParenthesized(ParenthesizedTree node, Void unused) { token("("); scan(node.getExpression(), null); token(")"); return null; }
/** Removes any enclosing parentheses from the tree. */ public static Tree stripParentheses(Tree tree) { while (tree instanceof ParenthesizedTree) { tree = ((ParenthesizedTree) tree).getExpression(); } return tree; }
/** Given an ExpressionTree, removes any enclosing parentheses. */ public static ExpressionTree stripParentheses(ExpressionTree tree) { while (tree instanceof ParenthesizedTree) { tree = ((ParenthesizedTree) tree).getExpression(); } return tree; }
@Override public Void visitParenthesized(ParenthesizedTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ParenthesizedTreeMatcher matcher : parenthesizedMatchers) { if (!isSuppressed(matcher, state)) { try { reportMatch(matcher.matchParenthesized(tree, state), tree, state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitParenthesized(tree, state); }
@Override public boolean matches(AnnotationTree annotationTree, VisitorState state) { for (ExpressionTree argumentTree : annotationTree.getArguments()) { if (argumentTree.getKind() == Tree.Kind.ASSIGNMENT) { AssignmentTree assignmentTree = (AssignmentTree) argumentTree; if (assignmentTree.getVariable().toString().equals(element)) { ExpressionTree expressionTree = assignmentTree.getExpression(); while (expressionTree instanceof ParenthesizedTree) { expressionTree = ((ParenthesizedTree) expressionTree).getExpression(); } if (expressionTree instanceof NewArrayTree) { NewArrayTree arrayTree = (NewArrayTree) expressionTree; for (ExpressionTree elementTree : arrayTree.getInitializers()) { if (valueMatcher.matches(elementTree, state)) { return true; } } return false; } return valueMatcher.matches(expressionTree, state); } } } return false; }
@Override public AnnotatedTypeMirror visitParenthesized(ParenthesizedTree node, AnnotatedTypeFactory f) { // Recurse on the expression inside the parens. return visit(node.getExpression(), f); }
/** * If the given tree is a parenthesized tree, it returns the enclosed non-parenthesized tree. * Otherwise, it returns the same tree. * * @param tree an expression tree * @return the outermost non-parenthesized tree enclosed by the given tree */ public static ExpressionTree skipParens(final ExpressionTree tree) { ExpressionTree t = tree; while (t.getKind() == Tree.Kind.PARENTHESIZED) { t = ((ParenthesizedTree) t).getExpression(); } return t; }
@Override public Void visitParenthesized(ParenthesizedTree expected, Tree actual) { Optional<ParenthesizedTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getExpression(), other.get().getExpression()); return null; }
public void testReplaceCondition() throws Exception { testFile = new File(getWorkDir(), "IfTest.java"); TestUtilities.copyStringToFile(testFile, "package foo.bar;\n" + "\n" + "public class IfTest {\n" + " public void test(boolean b) {\n" + " if (prec == treeinfo.notExpression)\n" + " print(';');\n" + " }\n" + "}\n" ); String golden = "package foo.bar;\n" + "\n" + "public class IfTest {\n" + " public void test(boolean b) {\n" + " if (prec == TreeInfo.notExpression)\n" + " print(';');\n" + " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); Task<WorkingCopy> task = new Task<WorkingCopy>() { public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(1); IfTree oldIf = (IfTree) method.getBody().getStatements().get(0); BinaryTree zatvorka = (BinaryTree) ((ParenthesizedTree) oldIf.getCondition()).getExpression(); MemberSelectTree mst = (MemberSelectTree) zatvorka.getRightOperand(); workingCopy.rewrite(mst.getExpression(), make.Identifier("TreeInfo")); } public void cancel() { } }; src.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); }
public void testDuplicateIfContent() throws Exception { String test = "class Test {\n" + " private static void t(int i) {\n" + " i^f (i == 0 || i == 1) {\n" + " System.err.println();\n" + " }\n" + " }\n" + "}"; String golden = "class Test {\n" + " private static void t(int i) {\n" + " if (i == 0) {\n" + " System.err.println();\n" + " } else if (i == 1) {\n" + " System.err.println();\n" + " }\n" + " }\n" + "}"; testFile = new File(getWorkDir(), "Test.java"); final int indexA = test.indexOf("^"); assertTrue(indexA != -1); TestUtilities.copyStringToFile(testFile, test.replace("^", "")); JavaSource src = getJavaSource(testFile); Task<WorkingCopy> task = new Task<WorkingCopy>() { public void run(WorkingCopy copy) throws Exception { if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { return; } Tree node = copy.getTreeUtilities().pathFor(indexA).getLeaf(); assertEquals(Kind.IF, node.getKind()); TreeMaker make = copy.getTreeMaker(); IfTree it = (IfTree) node; BinaryTree cond = (BinaryTree) ((ParenthesizedTree) it.getCondition()).getExpression(); IfTree newIf = make.If(make.Parenthesized(cond.getLeftOperand()), it.getThenStatement(), make.If(make.Parenthesized(cond.getRightOperand()), it.getThenStatement(), null)); copy.rewrite(it, newIf); } }; src.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); assertEquals(golden, res); }
public void test187616() throws Exception { testFile = new File(getWorkDir(), "Test.java"); TestUtilities.copyStringToFile(testFile, "package hierbas.del.litoral;\n\n" + "public class Test {\n" + " public void taragui(String str) {\n" + " //blabla\n" + "\twhile(path.getLeaf().getKind() != Kind.CLASS) {\n" + " }\n" + " }\n" + "}\n" ); String golden = "package hierbas.del.litoral;\n\n" + "public class Test {\n" + " public void taragui(String str) {\n" + " //blabla\n" + "\twhile(!TreeUtilities.SET.contains(path.getLeaf().getKind())) {\n" + " }\n" + " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); Task<WorkingCopy> task = new Task<WorkingCopy>() { public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.PARSED); TreeMaker make = workingCopy.getTreeMaker(); CompilationUnitTree cut = workingCopy.getCompilationUnit(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(0); BlockTree body = method.getBody(); WhileLoopTree loop = (WhileLoopTree)body.getStatements().get(0); BinaryTree origCond = (BinaryTree) ((ParenthesizedTree) loop.getCondition()).getExpression(); ExpressionTree nueCondition = make.Unary(Tree.Kind.LOGICAL_COMPLEMENT, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(make.MemberSelect(make.Identifier("TreeUtilities"), "SET"), "contains"), Collections.singletonList(origCond.getLeftOperand()))); workingCopy.rewrite(origCond, nueCondition); } }; src.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); System.err.println(res); assertEquals(golden, res); }
private ExpressionTree negate(ExpressionTree original, Tree parent, boolean nullOnPlainNeg) { ExpressionTree newTree; switch (original.getKind()) { case PARENTHESIZED: ExpressionTree expr = ((ParenthesizedTree) original).getExpression(); ExpressionTree negatedOrNull = negate(expr, original, nullOnPlainNeg); if (negatedOrNull != null) { if (negatedOrNull.getKind() != Kind.PARENTHESIZED) { negatedOrNull = make.Parenthesized(negatedOrNull); } } return negatedOrNull; /** if (nullOnPlainNeg) { return null; } else { return make.Unary(Kind.LOGICAL_COMPLEMENT, original); } */ case INSTANCE_OF: return make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(original)); case LOGICAL_COMPLEMENT: newTree = ((UnaryTree) original).getExpression(); while (newTree.getKind() == Kind.PARENTHESIZED && !JavaFixUtilities.requiresParenthesis(((ParenthesizedTree) newTree).getExpression(), original, parent)) { newTree = ((ParenthesizedTree) newTree).getExpression(); } break; case NOT_EQUAL_TO: newTree = negateBinaryOperator(original, Kind.EQUAL_TO, false); break; case EQUAL_TO: newTree = negateBinaryOperator(original, Kind.NOT_EQUAL_TO, false); break; case BOOLEAN_LITERAL: newTree = make.Literal(!(Boolean) ((LiteralTree) original).getValue()); break; case CONDITIONAL_AND: newTree = negateBinaryOperator(original, Kind.CONDITIONAL_OR, true); break; case CONDITIONAL_OR: newTree = negateBinaryOperator(original, Kind.CONDITIONAL_AND, true); break; case LESS_THAN: newTree = negateBinaryOperator(original, Kind.GREATER_THAN_EQUAL, false); break; case LESS_THAN_EQUAL: newTree = negateBinaryOperator(original, Kind.GREATER_THAN, false); break; case GREATER_THAN: newTree = negateBinaryOperator(original, Kind.LESS_THAN_EQUAL, false); break; case GREATER_THAN_EQUAL: newTree = negateBinaryOperator(original, Kind.LESS_THAN, false); break; default: if (nullOnPlainNeg) return null; newTree = make.Unary(Kind.LOGICAL_COMPLEMENT, original); } if (JavaFixUtilities.requiresParenthesis(newTree, original, parent)) { newTree = make.Parenthesized(newTree); } return newTree; }
public Boolean visitParenthesized(ParenthesizedTree node, ConstructorData p) { return super.visitParenthesized(node, p); }
private String simpleName(Tree t) { if (t == null) { return Bundle.DisplayName_Unknown(); } if (t.getKind() == Kind.IDENTIFIER) { return ((IdentifierTree) t).getName().toString(); } if (t.getKind() == Kind.MEMBER_SELECT) { return ((MemberSelectTree) t).getIdentifier().toString(); } if (t.getKind() == Kind.METHOD_INVOCATION) { return scan(t, null); } if (t.getKind() == Kind.PARAMETERIZED_TYPE) { return simpleName(((ParameterizedTypeTree) t).getType()) + "<...>"; // NOI18N } if (t.getKind() == Kind.ARRAY_ACCESS) { return simpleName(((ArrayAccessTree) t).getExpression()) + "[]"; //NOI18N } if (t.getKind() == Kind.PARENTHESIZED) { return "(" + simpleName(((ParenthesizedTree)t).getExpression()) + ")"; //NOI18N } if (t.getKind() == Kind.TYPE_CAST) { return simpleName(((TypeCastTree)t).getType()); } if (t.getKind() == Kind.ARRAY_TYPE) { return simpleName(((ArrayTypeTree)t).getType()); } if (t.getKind() == Kind.PRIMITIVE_TYPE) { return ((PrimitiveTypeTree) t).getPrimitiveTypeKind().name().toLowerCase(); } throw new IllegalStateException("Currently unsupported kind of tree: " + t.getKind()); // NOI18N }
/** * Negates an expression, returns negated Tree. The `original` should be a direct child * of `parent' or parent must be {@code null}. With a non-null parent, surrounding parenthesis * will be added if the language syntax requires it. * * @param make factory for Trees, obtain from WorkingCopy * @param original the tree to be negated * @param parent the parent of the negated tree. * @return negated expression, possibly parenthesized */ public static ExpressionTree negate(TreeMaker make, ExpressionTree original, Tree parent) { ExpressionTree newTree; switch (original.getKind()) { case PARENTHESIZED: ExpressionTree expr = ((ParenthesizedTree) original).getExpression(); newTree = negate(make, expr, original); break; case LOGICAL_COMPLEMENT: newTree = ((UnaryTree) original).getExpression(); while (newTree.getKind() == Kind.PARENTHESIZED && !JavaFixUtilities.requiresParenthesis(((ParenthesizedTree) newTree).getExpression(), original, parent)) { newTree = ((ParenthesizedTree) newTree).getExpression(); } break; case NOT_EQUAL_TO: newTree = negateBinaryOperator(make, original, Kind.EQUAL_TO, false); break; case EQUAL_TO: newTree = negateBinaryOperator(make, original, Kind.NOT_EQUAL_TO, false); break; case BOOLEAN_LITERAL: newTree = make.Literal(!(Boolean) ((LiteralTree) original).getValue()); break; case CONDITIONAL_AND: newTree = negateBinaryOperator(make, original, Kind.CONDITIONAL_OR, true); break; case CONDITIONAL_OR: newTree = negateBinaryOperator(make, original, Kind.CONDITIONAL_AND, true); break; case LESS_THAN: newTree = negateBinaryOperator(make, original, Kind.GREATER_THAN_EQUAL, false); break; case LESS_THAN_EQUAL: newTree = negateBinaryOperator(make, original, Kind.GREATER_THAN, false); break; case GREATER_THAN: newTree = negateBinaryOperator(make, original, Kind.LESS_THAN_EQUAL, false); break; case GREATER_THAN_EQUAL: newTree = negateBinaryOperator(make, original, Kind.LESS_THAN, false); break; default: newTree = make.Unary(Kind.LOGICAL_COMPLEMENT, original); if (JavaFixUtilities.requiresParenthesis(original, original, newTree)) { newTree = make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(original)); } break; } if (JavaFixUtilities.requiresParenthesis(newTree, original, parent)) { newTree = make.Parenthesized(newTree); } return newTree; }
private void negate(WorkingCopy copy, ExpressionTree original, Tree parent) { TreeMaker make = copy.getTreeMaker(); ExpressionTree newTree; switch (original.getKind()) { case PARENTHESIZED: ExpressionTree expr = ((ParenthesizedTree) original).getExpression(); negate(copy, expr, original); return ; case LOGICAL_COMPLEMENT: newTree = ((UnaryTree) original).getExpression(); while (newTree.getKind() == Kind.PARENTHESIZED && !JavaFixUtilities.requiresParenthesis(((ParenthesizedTree) newTree).getExpression(), original, parent)) { newTree = ((ParenthesizedTree) newTree).getExpression(); } break; case NOT_EQUAL_TO: newTree = negateBinaryOperator(copy, original, Kind.EQUAL_TO, false); break; case EQUAL_TO: newTree = negateBinaryOperator(copy, original, Kind.NOT_EQUAL_TO, false); break; case BOOLEAN_LITERAL: newTree = make.Literal(!(Boolean) ((LiteralTree) original).getValue()); break; case CONDITIONAL_AND: newTree = negateBinaryOperator(copy, original, Kind.CONDITIONAL_OR, true); break; case CONDITIONAL_OR: newTree = negateBinaryOperator(copy, original, Kind.CONDITIONAL_AND, true); break; case LESS_THAN: newTree = negateBinaryOperator(copy, original, Kind.GREATER_THAN_EQUAL, false); break; case LESS_THAN_EQUAL: newTree = negateBinaryOperator(copy, original, Kind.GREATER_THAN, false); break; case GREATER_THAN: newTree = negateBinaryOperator(copy, original, Kind.LESS_THAN_EQUAL, false); break; case GREATER_THAN_EQUAL: newTree = negateBinaryOperator(copy, original, Kind.LESS_THAN, false); break; default: newTree = make.Unary(Kind.LOGICAL_COMPLEMENT, original); if (JavaFixUtilities.requiresParenthesis(original, original, newTree)) { newTree = make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(original)); } break; } if (JavaFixUtilities.requiresParenthesis(newTree, original, parent)) { newTree = make.Parenthesized(newTree); } copy.rewrite(original, newTree); }
@Override public List<? extends TypeMirror> visitParenthesized(ParenthesizedTree node, Object p) { // ignore parenthesis and go up: return scanParent(); }
@Override protected void performRewrite(final TransformationContext ctx) { WorkingCopy wc = ctx.getWorkingCopy(); final TreeMaker make = wc.getTreeMaker(); final TreePath tp = ctx.getPath(); SwitchTree st = (SwitchTree) tp.getLeaf(); int insertIndex = 0; boolean hadDefault = false; for (CaseTree ct : st.getCases()) { if (ct.getExpression() == null) { hadDefault = true; break; } insertIndex++; } for (String name : names) { st = make.insertSwitchCase(st, insertIndex++, make.Case(make.Identifier(name), Collections.singletonList(make.Break(null)))); } if (!hadDefault && defaultTemplate != null) { StatementTree stmt = ctx.getWorkingCopy().getTreeUtilities().parseStatement(defaultTemplate, new SourcePositions[1]); Scope s = ctx.getWorkingCopy().getTrees().getScope(tp); ctx.getWorkingCopy().getTreeUtilities().attributeTree(stmt, s); st = GeneratorUtilities.get(ctx.getWorkingCopy()).importFQNs(make.addSwitchCase(st, make.Case(null, Collections.singletonList(stmt)))); new ErrorAwareTreePathScanner<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree node, Void p) { if (node.getName().contentEquals("$expression")) { ExpressionTree expression = ((SwitchTree) tp.getLeaf()).getExpression(); if (expression.getKind() == Tree.Kind.PARENTHESIZED) { expression = ((ParenthesizedTree) expression).getExpression(); } if (JavaFixUtilities.requiresParenthesis(expression, node, getCurrentPath().getParentPath().getLeaf())) { expression = make.Parenthesized(expression); } ctx.getWorkingCopy().rewrite(node, expression); } return super.visitIdentifier(node, p); } }.scan(new TreePath(ctx.getPath(), st), null); } wc.rewrite(tp.getLeaf(), st); }
@Override public Mirror visitParenthesized(ParenthesizedTree arg0, EvaluationContext evaluationContext) { return arg0.getExpression().accept(this, evaluationContext); }
/** * Skips a single parenthesized tree. */ static ExpressionTree skipParen(ExpressionTree node) { return ((ParenthesizedTree) node).getExpression(); }
@Override public R visitParenthesized(ParenthesizedTree pt, P p) { return null; }
@Override public List<T> visitParenthesized(ParenthesizedTree node, T p) { return checkForCriteria(node); }
@Override public ParenthesizedTree createParenthesized(ExpressionTree exp) { return new ParenthesizedTreeImpl(exp); }
@Override public Object visitParenthesized(ParenthesizedTree t, Trees p) { info("ParenthesizedTree" + CL + t.getKind() + SP + t); return super.visitParenthesized(t, p); }
@Override public UParens visitParenthesized(ParenthesizedTree tree, Void v) { return UParens.create(template(tree.getExpression())); }
@Override public Tree visitParenthesized(ParenthesizedTree node, Void v) { return node.getExpression().accept(this, null); }