private Expression makeExpression()

in api_dev/src/main/java/com/google/appengine/api/search/dev/ExpressionBuilder.java [491:566]


  private Expression makeExpression(Tree tree) {
    if (tree == null) {
      throw new IllegalArgumentException("Unexpected null node encountered");
    }

    switch (tree.getType()) {
      case ExpressionLexer.COUNT:
        return makeCountFieldsFunction(tree);
      case ExpressionLexer.SNIPPET:
        return makeSnippetFunction(tree);
      case ExpressionLexer.ABS:
        return makeAbsoluteValueFunction(tree);
      case ExpressionLexer.LOG:
        return makeLogFunction(tree);
      case ExpressionLexer.DISTANCE:
        return makeDistanceFunction(tree);
      case ExpressionLexer.GEOPOINT:
        return makeGeopointFunction(tree);
      case ExpressionLexer.MAX:
        return makeMaxFunction(tree);
      case ExpressionLexer.MIN:
        return makeMinFunction(tree);
      case ExpressionLexer.SWITCH:
        log.warning(
            String.format("Function %s not implemented. Using dummy expression.", tree.getText()));
        return new EmptyExpression();
      case ExpressionLexer.TIMES:
      case ExpressionLexer.DIV:
      case ExpressionLexer.PLUS:
      case ExpressionLexer.MINUS:
      case ExpressionLexer.POW:
      case ExpressionLexer.LT:
      case ExpressionLexer.GT:
      case ExpressionLexer.LE:
      case ExpressionLexer.EQ:
      case ExpressionLexer.NE:
      case ExpressionLexer.GE:
        return makeNumericBinaryExpression(tree);

      case ExpressionLexer.INT:
      case ExpressionLexer.FLOAT:
        return makeNumericValueExpression(tree);

      case ExpressionLexer.NEG:
        return new NegExpression(makeNumericExpression(tree.getChild(0)));

      case ExpressionLexer.NAME:
        switch (tree.getText()) {
          case SortExpression.SCORE_FIELD_NAME:
            return new ScoreExpression();
          case SortExpression.RANK_FIELD_NAME:
            return new RankExpression();
          default:
            return FieldExpression.makeFieldExpression(
                tree.getText(), fieldTypes.get(tree.getText()));
        }

      // Not yet handled token types
      case ExpressionLexer.DOLLAR:
      case ExpressionLexer.EXPONENT:
      case ExpressionLexer.LSQUARE:
      case ExpressionLexer.ASCII_LETTER:
      case ExpressionLexer.NAME_START:
      case ExpressionLexer.EOF:
      case ExpressionLexer.LPAREN:
      case ExpressionLexer.INDEX:
      case ExpressionLexer.RPAREN:
      case ExpressionLexer.DIGIT:
      case ExpressionLexer.UNDERSCORE:
      case ExpressionLexer.RSQUARE:
      case ExpressionLexer.PHRASE:
      case ExpressionLexer.WS:
      default:
        throw new IllegalArgumentException("Not yet implemented: " + getTokenName(tree.getType()));
    }
  }