static Stream<String> constValues(Tree tree) { if (tree instanceof ConditionalExpressionTree) { ConditionalExpressionTree cond = (ConditionalExpressionTree) tree; String t = ASTHelpers.constValue(cond.getTrueExpression(), String.class); String f = ASTHelpers.constValue(cond.getFalseExpression(), String.class); if (t == null || f == null) { return null; } return Stream.of(t, f); } String r = ASTHelpers.constValue(tree, String.class); return r != null ? Stream.of(r) : null; }
@Override public Void visitConditionalExpression( ConditionalExpressionTree node, VisitorState state) { node.getTrueExpression().accept(this, state); node.getFalseExpression().accept(this, state); return null; } };
@Override public Boolean visitConditionalExpression( ConditionalExpressionTree tree, Void unused) { return reduce( tree.getTrueExpression().accept(this, null), tree.getFalseExpression().accept(this, null)); }
@Override public JCConditional visitConditionalExpression(ConditionalExpressionTree tree, Void v) { return maker.Conditional( (JCExpression) tree.getCondition(), copy((JCExpression) tree.getTrueExpression()), copy((JCExpression) tree.getFalseExpression())); } }.copy(expr);
@Override public Number visitConditionalExpression(ConditionalExpressionTree node, Void p) { Number ifTrue = node.getTrueExpression().accept(this, null); Number ifFalse = node.getFalseExpression().accept(this, null); Boolean condition = ASTHelpers.constValue(node.getCondition(), Boolean.class); if (condition == null) { return null; } return condition ? ifTrue : ifFalse; }
@Override public UExpression visitConditionalExpression(ConditionalExpressionTree tree, Void v) { return UConditional.create( template(tree.getCondition()), template(tree.getTrueExpression()), template(tree.getFalseExpression())); }
@Override public Choice<State<JCConditional>> visitConditionalExpression( final ConditionalExpressionTree node, State<?> state) { return chooseSubtrees( state, s -> unifyExpression(node.getCondition(), s), s -> unifyExpression(node.getTrueExpression(), s), s -> unifyExpression(node.getFalseExpression(), s), maker()::Conditional); }
@Override public Description matchConditionalExpression( ConditionalExpressionTree conditionalExpression, VisitorState state) { if (conditionalExpression.getFalseExpression().getKind() != Kind.NULL_LITERAL && conditionalExpression.getTrueExpression().getKind() != Kind.NULL_LITERAL) { return NO_MATCH; } ASTHelpers.TargetType targetType = ASTHelpers.targetType(state); if (targetType == null || !targetType.type().isPrimitive()) { return NO_MATCH; } return describeMatch(conditionalExpression); } }
if (!(trueIsArray ^ types.isArray(getType(cond.getFalseExpression())))) { return NO_MATCH; SuggestedFixes.qualifyType( state, fix, types.elemtype(getLast(sym.getParameters()).asType())); Tree toFix = !trueIsArray ? cond.getTrueExpression() : cond.getFalseExpression(); fix.prefixWith(toFix, String.format("new %s[] {", qualified)).postfixWith(toFix, "}"); return describeMatch(tree, fix.build());
@Override @Nullable public Choice<Unifier> visitConditionalExpression( ConditionalExpressionTree conditional, Unifier unifier) { return getCondition() .unify(conditional.getCondition(), unifier.fork()) .thenChoose(unifications(getTrueExpression(), conditional.getTrueExpression())) .thenChoose(unifications(getFalseExpression(), conditional.getFalseExpression())) .or( getCondition() .negate() .unify(conditional.getCondition(), unifier.fork()) .thenChoose(unifications(getFalseExpression(), conditional.getTrueExpression())) .thenChoose(unifications(getTrueExpression(), conditional.getFalseExpression()))); }
Type falseExpressionType = ASTHelpers.getType(cet.getFalseExpression()); if (!isValidArrayFill(state, arrayComponentType, falseExpressionType)) { return reportMismatch(invocationTree, arrayComponentType, falseExpressionType);
ExpressionTree falseExpression = conditionalExpression.getFalseExpression();
condTree.getFalseExpression().accept(CONSTANT_VISITOR, state); boolean trueFirst; if (trueConst == ComparisonResult.NEGATIVE_CONSTANT
(ConditionalExpressionTree) path.getLeaf(); if (conditionalExpressionTree.getTrueExpression().equals(prev.getLeaf()) || conditionalExpressionTree.getFalseExpression().equals(prev.getLeaf())) { continue OUTER;
@Override public Void visitConditionalExpression(ConditionalExpressionTree expected, Tree actual) { Optional<ConditionalExpressionTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getTrueExpression(), other.get().getTrueExpression()); scan(expected.getFalseExpression(), other.get().getFalseExpression()); return null; }
@Override public Void visitConditionalExpression(ConditionalExpressionTree expected, Tree actual) { Optional<ConditionalExpressionTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getTrueExpression(), other.get().getTrueExpression()); scan(expected.getFalseExpression(), other.get().getFalseExpression()); return null; }
@Override public Void visitConditionalExpression(ConditionalExpressionTree expected, Tree actual) { Optional<ConditionalExpressionTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getTrueExpression(), other.get().getTrueExpression()); scan(expected.getFalseExpression(), other.get().getFalseExpression()); return null; }
public Boolean visitConditionalExpression(ConditionalExpressionTree node, TreePath p) { if (p == null) { super.visitConditionalExpression(node, p); return false; } ConditionalExpressionTree t = (ConditionalExpressionTree) p.getLeaf(); if (!scan(node.getCondition(), t.getCondition(), p)) return false; if (!scan(node.getFalseExpression(), t.getFalseExpression(), p)) return false; return scan(node.getTrueExpression(), t.getTrueExpression(), p); }
public R visitConditionalExpression(ConditionalExpressionTree node, P p) { R r = scan(node.getCondition(), p); r = scanAndReduce(node.getTrueExpression(), p, r); r = scanAndReduce(node.getFalseExpression(), p, r); return r; }
@Override public JCConditional visitConditionalExpression(ConditionalExpressionTree tree, Void v) { return maker.Conditional( (JCExpression) tree.getCondition(), copy((JCExpression) tree.getTrueExpression()), copy((JCExpression) tree.getFalseExpression())); } }.copy(expr);