private static List<? extends TypeMirror> computeConditionalExpression(
      Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    ConditionalExpressionTree cet = (ConditionalExpressionTree) parent.getLeaf();

    if (cet.getCondition() == error) {
      types.add(ElementKind.PARAMETER);
      types.add(ElementKind.LOCAL_VARIABLE);
      types.add(ElementKind.FIELD);

      return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.BOOLEAN));
    }

    if (cet.getTrueExpression() == error || cet.getFalseExpression() == error) {
      types.add(ElementKind.PARAMETER);
      types.add(ElementKind.LOCAL_VARIABLE);
      types.add(ElementKind.FIELD);

      return resolveType(types, info, parent.getParentPath(), cet, offset, null, null);
    }

    return null;
  }
Beispiel #2
0
 @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())));
 }
 @Override
 public Void visitConditionalExpression(ConditionalExpressionTree node, Void p) {
   checkForNullability(node.getCondition(), CONDITION_NULLABLE);
   return super.visitConditionalExpression(node, p);
 }