Java 类com.sun.source.tree.ParenthesizedTree 实例源码

项目:incubator-netbeans    文件:CreateElementUtilities.java   
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;
}
项目:incubator-netbeans    文件:RemoveUselessCast.java   
@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);
}
项目:incubator-netbeans    文件:CreateElementUtilities.java   
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;
}
项目:incubator-netbeans    文件:Ifs.java   
@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);
}
项目:NullAway    文件:NullAway.java   
/**
 * 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;
}
项目:incubator-netbeans    文件:TreeDuplicator.java   
@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;
}
项目:incubator-netbeans    文件:CopyFinder.java   
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);
}
项目:incubator-netbeans    文件:SemanticHighlighterBase.java   
@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;
}
项目:incubator-netbeans    文件:ExpressionVisitor.java   
@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;
}
项目:incubator-netbeans    文件:TreeNode.java   
@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;
}
项目:incubator-netbeans    文件:LeakingThisInConstructor.java   
@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"));
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
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;
    }
}
项目:incubator-netbeans    文件:JDIWrappersTest.java   
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;
}
项目:javaide    文件:JavaInputAstVisitor.java   
@Override
public Void visitParenthesized(ParenthesizedTree node, Void unused) {
    token("(");
    scan(node.getExpression(), null);
    token(")");
    return null;
}
项目:error-prone    文件:ASTHelpers.java   
/** Removes any enclosing parentheses from the tree. */
public static Tree stripParentheses(Tree tree) {
  while (tree instanceof ParenthesizedTree) {
    tree = ((ParenthesizedTree) tree).getExpression();
  }
  return tree;
}
项目:error-prone    文件:ASTHelpers.java   
/** Given an ExpressionTree, removes any enclosing parentheses. */
public static ExpressionTree stripParentheses(ExpressionTree tree) {
  while (tree instanceof ParenthesizedTree) {
    tree = ((ParenthesizedTree) tree).getExpression();
  }
  return tree;
}
项目:error-prone    文件:ErrorProneScanner.java   
@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);
}
项目:error-prone-aspirator    文件:AnnotationHasArgumentWithValue.java   
@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;
}
项目:checker-framework    文件:TypeFromTree.java   
@Override
public AnnotatedTypeMirror visitParenthesized(ParenthesizedTree node,
        AnnotatedTypeFactory f) {

    // Recurse on the expression inside the parens.
    return visit(node.getExpression(), f);
}
项目:bazel    文件:TreeUtils.java   
/**
 * 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;
}
项目:compile-testing    文件:TreeDiffer.java   
@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;
}
项目:incubator-netbeans    文件:IfTest.java   
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);
}
项目:incubator-netbeans    文件:IfTest.java   
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);
}
项目:incubator-netbeans    文件:MoveTreeTest.java   
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);
}
项目:incubator-netbeans    文件:JavaFixUtilities.java   
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;
}
项目:incubator-netbeans    文件:Flow.java   
public Boolean visitParenthesized(ParenthesizedTree node, ConstructorData p) {
    return super.visitParenthesized(node, p);
}
项目:incubator-netbeans    文件:Utilities.java   
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
}
项目:incubator-netbeans    文件:Utilities.java   
/**
 * 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;
}
项目:incubator-netbeans    文件:Ifs.java   
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);
    }
项目:incubator-netbeans    文件:ExpectedTypeResolver.java   
@Override
public List<? extends TypeMirror> visitParenthesized(ParenthesizedTree node, Object p) {
    // ignore parenthesis and go up:
    return scanParent();
}
项目:incubator-netbeans    文件:Tiny.java   
@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);
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public Mirror visitParenthesized(ParenthesizedTree arg0, EvaluationContext evaluationContext) {
    return arg0.getExpression().accept(this, evaluationContext);
}
项目:javaide    文件:Trees.java   
/**
 * Skips a single parenthesized tree.
 */
static ExpressionTree skipParen(ExpressionTree node) {
    return ((ParenthesizedTree) node).getExpression();
}
项目:oblivion-netbeans-plugin    文件:ApexTreeVisitorAdapter.java   
@Override
public R visitParenthesized(ParenthesizedTree pt, P p) {
    return null;
}
项目:oblivion-netbeans-plugin    文件:TreeFinder.java   
@Override
public List<T> visitParenthesized(ParenthesizedTree node, T p) {
    return checkForCriteria(node);
}
项目:oblivion-netbeans-plugin    文件:ApexTreeFactory.java   
@Override
public ParenthesizedTree createParenthesized(ExpressionTree exp) {
    return new ParenthesizedTreeImpl(exp);
}
项目:adalid    文件:CodeAnalyzerTreeVisitor.java   
@Override
public Object visitParenthesized(ParenthesizedTree t, Trees p) {
    info("ParenthesizedTree" + CL + t.getKind() + SP + t);
    return super.visitParenthesized(t, p);
}
项目:refactor-faster    文件:UTemplater.java   
@Override
public UParens visitParenthesized(ParenthesizedTree tree, Void v) {
  return UParens.create(template(tree.getExpression()));
}
项目:refactor-faster    文件:RefasterScanner.java   
@Override
public Tree visitParenthesized(ParenthesizedTree node, Void v) {
  return node.getExpression().accept(this, null);
}
项目:refactor-faster    文件:UParens.java   
@Override
public Tree visitParenthesized(ParenthesizedTree node, Void v) {
  return node.getExpression().accept(this, null);
}