Examples of BlockStatement


Examples of org.jboss.errai.codegen.BlockStatement

      String newValueParam = method.getParameters()[1].getName();

      if (getJavaMember(attr) instanceof Field) {


        BlockStatement methodBody = new BlockStatement();

        // Now unwrap in case it's a WrappedPortable
        methodBody.addStatement(
                If.instanceOf(Stmt.loadVariable(entityInstanceParam), WrappedPortable.class)
                    .append(Stmt.loadVariable(entityInstanceParam).assignValue(Stmt.castTo(WrappedPortable.class, Stmt.loadVariable(entityInstanceParam)).invoke("unwrap")))
                    .finish());

        MetaField field = MetaClassFactory.get((Field) getJavaMember(attr));

        // Now generate a call to the private accessor method for the field in question.
        // (The write accessor for the field was defined while generating the get() method).
        methodBody.addStatement(
                Stmt.loadVariable("this")
                    .invoke(PrivateAccessUtil.getPrivateFieldInjectorName(field),
                        Stmt.castTo(et.getJavaType(), Stmt.loadVariable(entityInstanceParam)),
                        Stmt.castTo(MetaClassFactory.get(attr.getJavaType()).asBoxed(), Stmt.loadVariable(newValueParam))));
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

        // First we need to generate an accessor for the field.
        MetaField field = MetaClassFactory.get((Field) getJavaMember(attr));
        PrivateAccessUtil.addPrivateAccessStubs(PrivateAccessType.Both, "jsni", containingClassBuilder, field, new Modifier[] {});

        BlockStatement methodBody = new BlockStatement();

        // Now unwrap in case it's a WrappedPortable
        methodBody.addStatement(
                If.instanceOf(Stmt.loadVariable(entityInstanceParam), WrappedPortable.class)
                    .append(Stmt.loadVariable(entityInstanceParam).assignValue(Stmt.castTo(WrappedPortable.class, Stmt.loadVariable(entityInstanceParam)).invoke("unwrap")))
                    .finish());

        // Now generate a call to the private accessor method for the field in question.
        methodBody.addStatement(
                Stmt.loadVariable("this")
                    .invoke(PrivateAccessUtil.getPrivateFieldInjectorName(field),
                        Stmt.castTo(et.getJavaType(), Stmt.loadVariable(entityInstanceParam)))
                        .returnValue());
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

              .append(Stmt.loadVariable("this").invoke("proceed", Variable.get("interceptorCallback")))
              .finish();
  }

  private static Statement generateInterceptorStackProceedMethod(final Statement proceed, final InterceptedCall interceptedCall) {
    final BlockStatement proceedLogic = new BlockStatement();
    proceedLogic.addStatement(Stmt.loadVariable("status").invoke("proceed"));

    final BlockBuilder<ElseBlockBuilder> interceptorStack =
              If.isNotNull(Stmt.loadVariable("status").invoke("getNextInterceptor"));

    for (final Class<?> interceptor : interceptedCall.value()) {
      interceptorStack.append(If.cond(Bool.equals(
              Stmt.loadVariable("status").invoke("getNextInterceptor"), interceptor))
              .append(Stmt.loadVariable("status").invoke("setProceeding", false))
              .append(
                  Stmt.nestedCall(Stmt.newObject(interceptor))
                      .invoke("aroundInvoke", Variable.get("this")))
              .append(
                  If.not(Stmt.loadVariable("status").invoke("isProceeding"))
                      .append(
                          Stmt.loadVariable("remoteCallback").invoke("callback",
                              Stmt.loadVariable("this").invoke("getResult")))
                      .finish())
              .finish()
          );
    }
    proceedLogic.addStatement(interceptorStack.finish().else_().append(proceed).finish());
    return proceedLogic;
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

            .finish();
  }

  private Statement generateRequest(ClassStructureBuilder<?> classBuilder,
      MetaMethod method, Statement methodParams, boolean intercepted) {
    BlockStatement requestBlock = new BlockStatement();

    requestBlock.addStatement(Stmt.declareVariable("sendable", RemoteCallSendable.class, null));
    requestBlock.addStatement(
        If.isNull(Variable.get("errorCallback"))
        .append(Stmt.loadVariable("sendable").assignValue(
            Stmt
                .invokeStatic(MessageBuilder.class, "createCall")
                .invoke("call", remote.getFullyQualifiedName())
                .invoke("endpoint", ProxyUtil.createCallSignature(method),
                    Stmt.loadClassMember("qualifiers"),
                    methodParams)
                .invoke("respondTo", method.getReturnType().asBoxed(), Stmt.loadVariable("remoteCallback"))
                .invoke("defaultErrorHandling")))
        .finish()
        .else_()
        .append(Stmt.loadVariable("sendable").assignValue(
            Stmt
                .invokeStatic(MessageBuilder.class, "createCall")
                .invoke("call", remote.getFullyQualifiedName())
                .invoke("endpoint", ProxyUtil.createCallSignature(method),
                    Stmt.loadClassMember("qualifiers"),
                    methodParams)
                .invoke("respondTo", method.getReturnType().asBoxed(), Stmt.loadVariable("remoteCallback"))
                .invoke("errorsHandledBy", Stmt.loadVariable("errorCallback"))))
        .finish());

    requestBlock.addStatement(Stmt.loadStatic(classBuilder.getClassDefinition(), "this")
        .invoke("sendRequest", Variable.get("bus"), Variable.get("sendable")));

    return requestBlock;
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

                  Variable.get("name"), Variable.get("handler")))
          .finish();
  }

  private Statement generatePropertiesMap() {
    BlockStatement block = new BlockStatement();
    for (String property : bindable.getBeanDescriptor().getProperties()) {
      MetaMethod readMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property);
      if (!readMethod.isFinal()) {
        block.addStatement(field("propertyTypes").invoke("put", property,
            readMethod.getReturnType().asBoxed().asClass()));
      }
    }
    return block;
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

  private static Statement generateInterceptorStackProceedMethod(
          final GeneratorContext context,
          final Class<? extends RemoteCallContext> callContextType,
          final Statement proceed, final List<Class<?>> interceptors) {
    final BlockStatement proceedLogic = new BlockStatement();
    proceedLogic.addStatement(Stmt.loadVariable("status").invoke("proceed"));

    final BlockBuilder<ElseBlockBuilder> interceptorStack =
              If.isNotNull(Stmt.loadVariable("status").invoke("getNextInterceptor"));

    for (final Class<?> interceptor : interceptors) {
      interceptorStack.append(If.cond(Bool.equals(
              Stmt.loadVariable("status").invoke("getNextInterceptor"), interceptor))
              .append(Stmt.loadVariable("status").invoke("setProceeding", false))
              .append(Stmt.declareFinalVariable("ctx", callContextType, Stmt.loadVariable("this")))
              .append(
                  Stmt.declareVariable(CreationalCallback.class).asFinal().named("icc")
                      .initializeWith(
                          Stmt.newObject(CreationalCallback.class).extend()
                              .publicOverridesMethod("callback", Parameter.of(Object.class, "beanInstance", true))
                              .append(
                                  Stmt.castTo(interceptor, Stmt.loadVariable("beanInstance")).invoke("aroundInvoke",
                                      Variable.get("ctx")))
                              .append(
                                  If.not(Stmt.loadVariable("status").invoke("isProceeding"))
                                      .append(
                                          Stmt.loadVariable("remoteCallback").invoke("callback",
                                              Stmt.loadVariable("ctx").invoke("getResult")))
                                      .finish())
                              .finish() // finish the method override body
                              .finish() // finish the anonymous CreationalCallback class body
                      ))
              .append(generateAsyncInterceptorCreation(context, interceptor))
              .finish()
          );
    }
    proceedLogic.addStatement(interceptorStack.finish().else_().append(proceed).finish());
    return proceedLogic;
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

  /**
   * Generates code to collect all existing properties and their types.
   */
  private Statement generatePropertiesMap() {
    BlockStatement block = new BlockStatement();
    for (String property : bindable.getBeanDescriptor().getProperties()) {
      MetaMethod readMethod = bindable.getBeanDescriptor().getReadMethodForProperty(property);
      if (readMethod != null && !readMethod.isFinal()) {
        block.addStatement(agent("propertyTypes").invoke(
            "put",
            property,
            Stmt.newObject(PropertyType.class, readMethod.getReturnType().asBoxed().asClass(),
                readMethod.getReturnType().isAnnotationPresent(Bindable.class),
                readMethod.getReturnType().isAssignableTo(List.class))
            )
            );
      }
    }
    return (block.isEmpty()) ? EmptyStatement.INSTANCE : block;
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

    injectionContext.mapElementType(WiringElementType.SingletonBean, ApplicationScoped.class);
    injectionContext.mapElementType(WiringElementType.ProducerElement, Produces.class);
  }

  private static void addTypeHierarchyFor(final IOCProcessingContext context, final Set<MetaClass> classes) {
    final BlockStatement instanceInitializer = context.getBootstrapClass().getInstanceInitializer();

    int i = 0, addLookupMethodCount = 0;
    MethodCommentBuilder<?> currentBlock = null;
    for (final MetaClass subClass : classes) {
      MetaClass cls = subClass;
      do {
        // We'll generate a separate lookup method for every 500 lines to make sure we're not
        // exceeding the method size byte limit. See ERRAI-346 and ERRAI-679
        if ((i++ % 500) == 0) {
          Statement lookupMethod = Stmt.invokeStatic(context.getBootstrapClass(), "addLookups_" + addLookupMethodCount);
          if (currentBlock != null) {
            currentBlock
                .append(lookupMethod);
            currentBlock.modifiers(Modifier.Static).finish();
          }
          else {
            instanceInitializer.addStatement(lookupMethod);
          }
          currentBlock =
              context.getBootstrapBuilder().privateMethod(void.class, "addLookups_" + addLookupMethodCount++);
        }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

 
  @Override
  public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext,
      final IOCConfigProcessor procFactory) {
   
    final BlockStatement instanceInitializer = context.getBootstrapClass().getInstanceInitializer();
    final Set<MetaClass> knownObserverTypes = new HashSet<MetaClass>();

    for (final MetaParameter parameter : ClassScanner.getParametersAnnotatedWith(Observes.class,
            context.getGeneratorContext())) {
      knownObserverTypes.add(parameter.getType());
    }

    final Set<MetaClass> knownTypesWithSuperTypes = new HashSet<MetaClass>(knownObserverTypes);
    for (final MetaClass cls : knownObserverTypes) {
      for (final MetaClass subClass : ClassScanner.getSubTypesOf(cls, context.getGeneratorContext())) {
        knownTypesWithSuperTypes.add(subClass);
      }
    }

    addTypeHierarchyFor(context, knownTypesWithSuperTypes);

    instanceInitializer.addStatement(Stmt.nestedCall(Stmt.newObject(CDI.class))
            .invoke("initLookupTable", Stmt.invokeStatic(CDIEventTypeLookup.class, "get")));
  }
View Full Code Here

Examples of org.jboss.errai.codegen.BlockStatement

          uiBinderBoilerPlaterIface.addAnnotation(handler);
          uiBinderBoilerPlaterIface.addAnnotation(packageTarget);

          context.getBootstrapClass().addInnerClass(new InnerClass(uiBinderBoilerPlaterIface));

          final BlockStatement staticInit = context.getBootstrapClass().getStaticInitializer();

          String varName = "uiBinderInst_" + enclosingType.getFullyQualifiedName()
                  .replaceAll("\\.", "_");

          if (Boolean.getBoolean("errai.simulatedClient")) {
            staticInit.addStatement(Stmt.declareVariable(UiBinder.class).named(varName).initializeWith(
                    ObjectBuilder.newInstanceOf(uiBinderBoilerPlaterIface)
                            .extend()
                            .publicOverridesMethod("createAndBindUi", Parameter.of(type, "w"))
                            .append(Stmt.loadLiteral(null).returnValue())
                            .finish().finish()
            )
            );
          }
          else {
            staticInit.addStatement(Stmt.declareVariable(UiBinder.class).named(varName).initializeWith(
                    Stmt.invokeStatic(GWT.class, "create", LiteralFactory.getLiteral(uiBinderBoilerPlaterIface))
            ));
          }

          staticInit.addStatement(Stmt.invokeStatic(UiBinderProvider.class, "registerBinder",
              enclosingType, Refs.get(varName)));
        }
        else if (type.isAssignableTo(SafeHtmlTemplates.class)) {
          final String varName = "safeTemplateInst_" + type.getFullyQualifiedName()
                  .replaceAll("\\.", "_");
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.