Examples of ContextualStatementBuilder


Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

    }

    // set headers based on @HeaderParams
    if (params.getHeaderParameters() != null) {
      for (String headerParamName : params.getHeaderParameters().keySet()) {
        ContextualStatementBuilder headerValueBuilder = Stmt.nestedCall(Stmt.newObject(StringBuilder.class));

        int i = 0;
        for (Parameter headerParam : params.getHeaderParameters(headerParamName)) {
          if (i++ > 0) {
            headerValueBuilder = headerValueBuilder.invoke(APPEND, ",");
          }
          headerValueBuilder = headerValueBuilder.invoke(APPEND, marshal(headerParam));
        }

        methodBlock.append(Stmt.loadVariable("requestBuilder").invoke("setHeader", headerParamName,
            headerValueBuilder.invoke("toString")));
      }
    }

    // set cookies based on @CookieParams
    if (params.getCookieParameters() != null) {
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

              .modifiers(Modifier.Static)
              .body();

      BlockBuilder<CatchBlockBuilder> tryBuilder = Stmt.try_();

      ContextualStatementBuilder statementBuilder = Stmt.loadVariable(cachedMethod)
              .invoke("invoke", Refs.get("instance"), args);

      if (m.getReturnType().isVoid()) {
        tryBuilder.append(statementBuilder);
      }
      else {
        tryBuilder.append(statementBuilder.returnValue());
      }

      body.append(tryBuilder
              .finish()
              .catch_(Throwable.class, "e")
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

              .modifiers(Modifier.Static)
              .body();

      BlockBuilder<CatchBlockBuilder> tryBuilder = Stmt.try_();

      ContextualStatementBuilder statementBuilder = Stmt.loadVariable(cachedMethod)
              .invoke("invoke", Refs.get("instance"), args);

      if (m.getReturnType().isVoid()) {
        tryBuilder.append(statementBuilder);
      }
      else {
        tryBuilder.append(statementBuilder.returnValue());
      }

      body.append(tryBuilder
              .finish()
              .catch_(Throwable.class, "e")
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

    methodBlock.finish();
  }

  private void generateUrl(BlockBuilder<?> methodBlock) {
    JaxrsResourceMethodParameters params = resourceMethod.getParameters();
    ContextualStatementBuilder pathValue = Stmt.loadLiteral(resourceMethod.getPath());

    List<String> pathParams =
        ((UriBuilderImpl) UriBuilderImpl.fromTemplate(resourceMethod.getPath())).getPathParamNamesInDeclarationOrder();
    int i = 0;
    for (String pathParam : pathParams) {
      pathValue = pathValue.invoke("replaceFirst", "\\{" + pathParam + "\\}",
          marshal(params.getPathParameter(pathParam, i++)));
    }

    methodBlock.append(Stmt.declareVariable("url", StringBuilder.class,
        Stmt.newObject(StringBuilder.class).withParameters(pathValue)));

    ContextualStatementBuilder urlBuilder = null;
    if (params.getQueryParameters() != null) {
      urlBuilder = Stmt.loadVariable("url").invoke(APPEND, "?");

      i = 0;
      for (String queryParamName : params.getQueryParameters().keySet()) {
        for (Parameter queryParam : params.getQueryParameters(queryParamName)) {
          if (i++ > 0)
            urlBuilder = urlBuilder.invoke(APPEND, "&");

          urlBuilder = urlBuilder.invoke(APPEND, queryParamName);
          urlBuilder = urlBuilder.invoke(APPEND, "=");
          urlBuilder = urlBuilder.invoke(APPEND, marshal(queryParam));
        }
      }
    }
   
    // TODO MatrixParams
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

          resourceMethod.getHeaders().get(key)));
    }
   
    if (params.getHeaderParameters() != null) {
      for (String headerParamName : params.getHeaderParameters().keySet()) {
        ContextualStatementBuilder headerValueBuilder = Stmt.nestedCall(Stmt.newObject(StringBuilder.class));
       
        int i = 0;
        for (Parameter headerParam : params.getHeaderParameters(headerParamName)) {
          if (i++ > 0) {
            headerValueBuilder = headerValueBuilder.invoke(APPEND, ",");
          }
          headerValueBuilder = headerValueBuilder.invoke(APPEND, marshal(headerParam));
        }

        methodBlock.append(Stmt.loadVariable("requestBuilder").invoke("setHeader", headerParamName,
            headerValueBuilder.invoke("toString")));
      }
    }
   
    // TODO CookieParams
  }
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

    methodBlock.append(requestBuilder);
  }

  private void generateRequest(BlockBuilder<?> methodBlock) {
    ContextualStatementBuilder sendRequest = Stmt.loadVariable("requestBuilder");
    if (resourceMethod.getParameters().getEntityParameter() == null) {
      sendRequest = sendRequest.invoke("sendRequest", null, generateRequestCallback());
    }
    else {
      Statement body = marshal(resourceMethod.getParameters().getEntityParameter());
      sendRequest = sendRequest.invoke("sendRequest", body, generateRequestCallback());
    }

    methodBlock.append(Stmt
        .try_()
        .append(sendRequest)
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

  public static StringBuilderBuilder newStringBuilder() {
    return newStringBuilder(64);
  }
 
  public static StringBuilderBuilder newStringBuilder(int length) {
    final ContextualStatementBuilder statementBuilder
            = Stmt.nestedCall(Stmt.newObject(StringBuilder.class).withParameters(length));

    return new StringBuilderBuilder() {

      @Override
      public StringBuilderBuilder append(Object statement) {
        statementBuilder.invoke("append", statement);
        return this;
      }

      String generatedCache;

      @Override
      public String generate(Context context) {
        if (generatedCache != null) return generatedCache;
        return generatedCache = statementBuilder.generate(context);
      }

      @Override
      public MetaClass getType() {
        return statementBuilder.getType();
      }
    };
  }
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

              .modifiers(Modifier.Static)
              .body();

      BlockBuilder<CatchBlockBuilder> tryBuilder = Stmt.try_();

      ContextualStatementBuilder statementBuilder = Stmt.loadVariable(cachedMethod)
              .invoke("invoke", Refs.get("instance"), args);

      if (m.getReturnType().isVoid()) {
        tryBuilder.append(statementBuilder);
      }
      else {
        tryBuilder.append(statementBuilder.returnValue());
      }

      body.append(tryBuilder
              .finish()
              .catch_(Throwable.class, "e")
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

              Stmt.load(m.getDeclaringClass().asClass()).invoke("getDeclaredMethod", m.getName(),
                      MetaClassFactory.asClassArray(m.getParameters()))))

              .append(Stmt.loadVariable("method").invoke("setAccessible", true));

      ContextualStatementBuilder statementBuilder = Stmt.loadVariable("method")
              .invoke("invoke", Refs.get("instance"), args);

      if (m.getReturnType().isVoid()) {
        tryBuilder.append(statementBuilder);
      }
      else {
        tryBuilder.append(statementBuilder.returnValue());
      }

      body.append(tryBuilder
              .finish()
              .catch_(Throwable.class, "e")
View Full Code Here

Examples of org.jboss.errai.codegen.framework.builder.ContextualStatementBuilder

    builder.privateField(name, type)
            .initializesWith(Stmt.newObject(implementation)).finish();
  }

  public static StringBuilderBuilder newStringBuilder() {
    final ContextualStatementBuilder statementBuilder
            = Stmt.nestedCall(Stmt.newObject(StringBuilder.class));
   
    return new StringBuilderBuilder() {

      @Override
      public StringBuilderBuilder append(Object statement) {
        statementBuilder.invoke("append", statement);
        return this;
      }

      @Override
      public String generate(Context context) {
        return statementBuilder.generate(context);
      }

      @Override
      public MetaClass getType() {
        return statementBuilder.getType();
      }
    };
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.