All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.codetrans.expression.ListModel Maven / Gradle / Ivy

package io.vertx.codetrans.expression;

import io.vertx.codegen.type.TypeInfo;
import io.vertx.codetrans.CodeBuilder;
import io.vertx.codetrans.CodeWriter;
import io.vertx.codetrans.MethodSignature;
import io.vertx.codetrans.TypeArg;

import java.util.List;

/**
 * @author Julien Viet
 */
public class ListModel extends ExpressionModel {

  private final ExpressionModel expression;

  public ListModel(CodeBuilder builder, ExpressionModel expression) {
    super(builder);
    this.expression = expression;
  }

  @Override
  public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List typeArguments, List argumentModels, List argumentTypes) {
    String methodName = method.getName();
    switch (methodName) {
      case "add":
        return builder.render(writer -> {
          writer.renderListAdd(expression, argumentModels.get(0));
        });
      case "size":
        return builder.render(writer -> {
          writer.renderListSize(expression);
        });
      case "get":
        return builder.render(writer -> {
          writer.renderListGet(expression, argumentModels.get(0));
        });
      default:
        throw new UnsupportedOperationException("List " + method + " method not supported");
    }
  }

  @Override
  public void render(CodeWriter writer) {
    expression.render(writer);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy