예제 #1
0
    @Override
    protected Type visitSimpleCaseExpression(SimpleCaseExpression node, AnalysisContext context) {
      for (WhenClause whenClause : node.getWhenClauses()) {
        coerceToSingleType(
            context,
            node,
            "CASE operand type does not match WHEN clause operand type: %s vs %s",
            node.getOperand(),
            whenClause.getOperand());
      }

      Type type =
          coerceToSingleType(
              context,
              "All CASE results must be the same type: %s",
              getCaseResultExpressions(node.getWhenClauses(), node.getDefaultValue()));
      expressionTypes.put(node, type);

      for (WhenClause whenClause : node.getWhenClauses()) {
        Type whenClauseType = process(whenClause.getResult(), context);
        requireNonNull(
            whenClauseType,
            format("Expression types does not contain an entry for %s", whenClause));
        expressionTypes.put(whenClause, whenClauseType);
      }

      return type;
    }
예제 #2
0
    @Override
    protected String visitSimpleCaseExpression(SimpleCaseExpression node, Boolean unmangleNames) {
      ImmutableList.Builder<String> parts = ImmutableList.builder();

      parts.add("CASE").add(process(node.getOperand(), unmangleNames));

      for (WhenClause whenClause : node.getWhenClauses()) {
        parts.add(process(whenClause, unmangleNames));
      }

      node.getDefaultValue()
          .ifPresent((value) -> parts.add("ELSE").add(process(value, unmangleNames)));

      parts.add("END");

      return "(" + Joiner.on(' ').join(parts.build()) + ")";
    }