Java Code Examples for com.sun.source.tree.UnaryTree#getKind()

The following examples show how to use com.sun.source.tree.UnaryTree#getKind() . 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: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) {
    switch (node.getKind()) {
        case UNARY_MINUS:
        case UNARY_PLUS:
            break;
        default:
            return false;
    }
    if (!(node.getExpression() instanceof UnaryTree)) {
        return false;
    }
    int tag = ((JCTree) node.getExpression()).getTag();
    if (OpUtil.isPostUnaryOp(tag)) {
        return false;
    }
    if (!operatorName(node).startsWith(operatorName)) {
        return false;
    }
    return true;
}
 
Example 2
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) {
    switch (node.getKind()) {
        case UNARY_MINUS:
        case UNARY_PLUS:
            break;
        default:
            return false;
    }
    if (!(node.getExpression() instanceof UnaryTree)) {
        return false;
    }
    int tag = ((JCTree) node.getExpression()).getTag();
    if (OpUtil.isPostUnaryOp(tag)) {
        return false;
    }
    if (!operatorName(node).startsWith(operatorName)) {
        return false;
    }
    return true;
}
 
Example 3
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) {
  switch (node.getKind()) {
    case UNARY_MINUS:
    case UNARY_PLUS:
      break;
    default:
      return false;
  }
  if (!(node.getExpression() instanceof UnaryTree)) {
    return false;
  }
  JCTree.Tag tag = ((JCTree) node.getExpression()).getTag();
  if (tag.isPostUnaryOp()) {
    return false;
  }
  if (!operatorName(node).startsWith(operatorName)) {
    return false;
  }
  return true;
}
 
Example 4
Source File: ModelBuilder.java    From vertx-codetrans with Apache License 2.0 6 votes vote down vote up
@Override
public ExpressionModel visitUnary(UnaryTree node, VisitContext p) {
  ExpressionModel expression = scan(node.getExpression(), p);
  switch (node.getKind()) {
    case POSTFIX_INCREMENT:
      // Note we don't handle the case (3++) that is not legal in JavaScript
      return expression.onPostFixIncrement();
    case POSTFIX_DECREMENT:
      // Note we don't handle the case (3--) that is not legal in JavaScript
      return expression.onPostFixDecrement();
    case PREFIX_INCREMENT:
      // Note we don't handle the case (++3) that is not legal in JavaScript
      return expression.onPrefixIncrement();
    case PREFIX_DECREMENT:
      // Note we don't handle the case (--3) that is not legal in JavaScript
      return expression.onPrefixDecrement();
    case LOGICAL_COMPLEMENT:
      return expression.onLogicalComplement();
    case UNARY_MINUS:
      return expression.unaryMinus();
    case UNARY_PLUS:
      return expression.unaryPlus();
    default:
      throw new UnsupportedOperationException("Unary operator " + node.getKind().name() + " not yet implemented");
  }
}
 
Example 5
Source File: JavaFixUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Number visitUnary(UnaryTree node, Void p) {
    Number op  = scan(node.getExpression(), p);

    if (op != null) {
        Number result = null;
        switch (node.getKind()) {
            case UNARY_MINUS:
                    if (op instanceof Double) {
                        result = -op.doubleValue();
                    } else if (op instanceof Float) {
                        result = -op.floatValue();
                    } else if (op instanceof Long) {
                        result = -op.longValue();
                    } else if (op instanceof Integer) {
                        result = -op.intValue();
                    } else {
                        throw new IllegalStateException("op=" + op.getClass());
                    }
                    break;
            case UNARY_PLUS:
                result = op;
                break;
        }

        if (result != null) {
            rewrite(node, make.Literal(result));

            return result;
        }
    }

    return super.visitUnary(node, p);
}
 
Example 6
Source File: MethodMetrics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitUnary(UnaryTree node, Object p) {
    if (node.getKind() == Tree.Kind.LOGICAL_COMPLEMENT) {
        negationsCount++;
    }
    return super.visitUnary(node, p);
}
 
Example 7
Source File: SideEffectVisitor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitUnary(UnaryTree node, Object p) {
    switch (node.getKind()) {
        case POSTFIX_DECREMENT:
        case POSTFIX_INCREMENT:
        case PREFIX_DECREMENT:
        case PREFIX_INCREMENT:
            break;
        default:
            return super.visitUnary(node, p);
    }
    checkVariableAccess(node.getExpression(), node);
    return super.visitUnary(node, p);
}
 
Example 8
Source File: AssignmentIssues.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitUnary(UnaryTree node, List<TreePath> p) {
    switch (node.getKind()) {
        case PREFIX_INCREMENT:
        case PREFIX_DECREMENT:
        case POSTFIX_INCREMENT:
        case POSTFIX_DECREMENT:
            if (param == trees.getElement(TreePath.getPath(getCurrentPath(), node.getExpression()))) {
                p.add(getCurrentPath());
                return null;
            }
    }
    return super.visitUnary(node, p);
}
 
Example 9
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<? extends TypeMirror> visitUnary(UnaryTree node, Object p) {
    switch (node.getKind()) {
        case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: case PREFIX_DECREMENT: case PREFIX_INCREMENT:
            // the incremented value is a l-value, it's type cannot be changed. We shouldn't be at this code path at all
            return null;
        case PLUS:
        case BITWISE_COMPLEMENT:
            scanParent();
            break;
        case LOGICAL_COMPLEMENT:
            return booleanType();
    }
    return null;
}
 
Example 10
Source File: TreePruner.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visitUnary(UnaryTree node, Void p) {
  switch (node.getKind()) {
    case UNARY_PLUS:
    case UNARY_MINUS:
    case BITWISE_COMPLEMENT:
    case LOGICAL_COMPLEMENT:
      break;
    default:
      // non-constant unary expression
      return false;
  }
  return node.getExpression().accept(this, null);
}
 
Example 11
Source File: ArithmeticUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitUnary(UnaryTree node, Void p) {
    Object op  = scan(node.getExpression(), p);
    if (op != null) {
        Object result = null;
        if (op instanceof Character) {
            op = Integer.valueOf(((Character)op).charValue());
        }
        switch (node.getKind()) {
            case BITWISE_COMPLEMENT:
                if (op instanceof Long) {
                    result = ~((Long)op).longValue();
                } else if (op instanceof Number && integerLike((Number)op)) {
                    result = ~(((Number)op).intValue());
                }
                break;
            case LOGICAL_COMPLEMENT:
                if (op instanceof Boolean) {
                    result = !((Boolean)op).booleanValue();
                }
                break;
            case UNARY_MINUS:
                if (op instanceof Number) {
                    Number nop = (Number)op;
                    if (op instanceof Double) {
                        result = -nop.doubleValue();
                    } else if (op instanceof Float) {
                        result = -nop.floatValue();
                    } else if (op instanceof Long) {
                        result = -nop.longValue();
                    } else if (integerLike(nop)) {
                        result = -nop.intValue();
                    } else {
                        return null;
                    }
                }
                break;
            case UNARY_PLUS:
                if (op instanceof Number) {
                    result = op;
                }
                break;
        }
        return result;
    }

    return super.visitUnary(node, p);
}