@Override public Number visitUnary(UnaryTree node, Void p) { Number value = node.getExpression().accept(this, null); if (value == null) { return value; } if (value instanceof Long) { return unop(node.getKind(), value.longValue()); } else { return unop(node.getKind(), value.intValue()); } }
@Override public boolean matches(UnaryTree tree, VisitorState state) { return exprMatcher.matches(tree.getExpression(), state); } };
@Override public Void visitUnary(UnaryTree tree, ExpressionTree expr) { if (tree.getKind().equals(Kind.LOGICAL_COMPLEMENT)) { notApplicable = true; } return super.visitUnary(tree, expr); }
@Override public Boolean visitUnary(UnaryTree node, Void aVoid) { return node.getExpression().accept(this, null); }
public BitwiseComplementNode(UnaryTree tree, Node operand) { super(tree, operand); assert tree.getKind() == Kind.BITWISE_COMPLEMENT; }
@Override public JCExpression visitUnary(UnaryTree tree, Void v) { if (tree.getKind() == Kind.LOGICAL_COMPLEMENT) { return (JCExpression) tree.getExpression(); } else { return defaultNegation(tree); } }
@Override public Description matchUnary(UnaryTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } return doUnboxingCheck(state, tree.getExpression()); }
public NumericalMinusNode(UnaryTree tree, Node operand) { super(tree, operand); assert tree.getKind() == Kind.UNARY_MINUS; }
@Override public Boolean visitUnary(UnaryTree node, Void aVoid) { Boolean r = node.getExpression().accept(this, null); if (r == null) { return null; } switch (node.getKind()) { case LOGICAL_COMPLEMENT: return !r; default: return null; } } };
@Override public Description matchMethodInvocation( MethodInvocationTree methodInvocationTree, VisitorState visitorState) { if (methodInvocationTree.getArguments().stream() .filter(arg -> UNARY_OPERATORS.contains(arg.getKind())) .map(arg -> ASTHelpers.getSymbol(((UnaryTree) arg).getExpression())) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) .entrySet() .stream() .anyMatch(e -> e.getValue() > 1)) { return describeMatch(methodInvocationTree); } return Description.NO_MATCH; } }
public NumericalPlusNode(UnaryTree tree, Node operand) { super(tree, operand); assert tree.getKind() == Kind.UNARY_PLUS; }
@Override public Void visitUnary(UnaryTree node, InitializationContext init) { if (UNARY_ASSIGNMENT.contains(node.getKind())) { init = InitializationContext.NONE; writes.recordAssignment(node.getExpression(), init); } return super.visitUnary(node, init); } }
private static Optional<Symbol> returnUnarySym(StatementTree s) { if (s instanceof ExpressionStatementTree) { if (((ExpressionStatementTree) s).getExpression() instanceof UnaryTree) { UnaryTree unaryTree = (UnaryTree) ((ExpressionStatementTree) s).getExpression(); return Optional.ofNullable(ASTHelpers.getSymbol(unaryTree.getExpression())); } } return Optional.empty(); } }
public ConditionalNotNode(UnaryTree tree, Node operand) { super(tree, operand); assert tree.getKind().equals(Kind.LOGICAL_COMPLEMENT); }
@Override public Void visitUnary(UnaryTree tree, Void unused) { switch (tree.getKind()) { case POSTFIX_INCREMENT: case PREFIX_INCREMENT: case POSTFIX_DECREMENT: case PREFIX_DECREMENT: check(tree.getExpression()); break; default: // fall out } return super.visitUnary(tree, unused); }
@Override public Description matchForLoop(ForLoopTree forLoopTree, VisitorState visitorState) { List<? extends ExpressionStatementTree> updates = forLoopTree.getUpdate(); // keep track of all the symbols that are updated in the for loop header final Set<Symbol> incrementedSymbols = updates.stream() .filter(expStateTree -> expStateTree.getExpression() instanceof UnaryTree) .map( expStateTree -> ASTHelpers.getSymbol( ((UnaryTree) expStateTree.getExpression()).getExpression())) .collect(Collectors.toCollection(HashSet::new)); // track if they are updated in the body without a conditional surrounding them StatementTree body = forLoopTree.getStatement(); List<? extends StatementTree> statementTrees = body instanceof BlockTree ? ((BlockTree) body).getStatements() : ImmutableList.of(body); for (StatementTree s : statementTrees) { if (!CONDITIONALS.contains(s.getKind())) { Optional<Symbol> opSymbol = returnUnarySym(s); if (opSymbol.isPresent() && incrementedSymbols.contains(opSymbol.get())) { // both ++ and -- return describeMatch(forLoopTree); } } } return Description.NO_MATCH; }
@Override public Void visitUnary(UnaryTree tree, ExpressionTree expr) { if (tree.getKind().equals(Kind.LOGICAL_COMPLEMENT)) { notApplicable = true; } return super.visitUnary(tree, expr); }
@Override public UUnary visitUnary(UnaryTree tree, Void v) { return UUnary.create(tree.getKind(), template(tree.getExpression())); }
@Override public Choice<State<JCUnary>> visitUnary(UnaryTree node, State<?> state) { final Tag tag = ((JCUnary) node).getTag(); return chooseSubtrees( state, s -> unifyExpression(node.getExpression(), s), expr -> maker().Unary(tag, expr)) .condition( s -> !MUTATING_UNARY_TAGS.contains(tag) || !(s.result().getExpression() instanceof PlaceholderParamIdent)); }
@Override public Void visitUnary(UnaryTree node, Void unused) { switch (node.getKind()) { case PREFIX_DECREMENT: case PREFIX_INCREMENT: case POSTFIX_DECREMENT: case POSTFIX_INCREMENT: recordWrite(node.getExpression()); break; default: break; } return super.visitUnary(node, null); }