private static ImmutableMultimap parseAnnotationArguments()

in legacy/java/piranha/src/main/java/com/uber/piranha/testannotations/TestAnnotationResolver.java [64:107]


  private static ImmutableMultimap<String, AnnotationArgument> parseAnnotationArguments(
      AnnotationTree at) {
    ImmutableMultimap.Builder<String, AnnotationArgument> builder = ImmutableMultimap.builder();
    for (ExpressionTree et : at.getArguments()) {
      if (et.getKind() == Tree.Kind.ASSIGNMENT) {
        AssignmentTree assn = (AssignmentTree) et;
        String key = "$" + PiranhaUtils.expressionToSimpleName(assn.getVariable());
        ExpressionTree assnExpression = assn.getExpression();
        Tree.Kind assnExprKind = assnExpression.getKind();
        switch (assnExprKind) {
          case IDENTIFIER: // Fallthrough
          case MEMBER_SELECT:
            builder.put(
                key,
                new AnnotationArgument(
                    PiranhaUtils.expressionToSimpleName(assnExpression), assnExpression));
            break;
          case STRING_LITERAL: // Fallthrough
          case BOOLEAN_LITERAL:
            builder.put(
                key,
                new AnnotationArgument(
                    ((LiteralTree) assnExpression).getValue().toString(), assnExpression));
            break;
          case NEW_ARRAY:
            // For each in the array
            NewArrayTree arrayExpression = (NewArrayTree) assnExpression;
            for (ExpressionTree expr : arrayExpression.getInitializers()) {
              if (expr instanceof LiteralTree) {
                builder.put(
                    key, new AnnotationArgument(((LiteralTree) expr).getValue().toString(), expr));
              } else {
                builder.put(
                    key, new AnnotationArgument(PiranhaUtils.expressionToSimpleName(expr), expr));
              }
            }
            break;
          default:
            builder.put(key, new AnnotationArgument(UNPARSED_FIELD_VALUE, assnExpression));
        }
      }
    }
    return builder.build();
  }