Package org.jboss.errai.codegen

Examples of org.jboss.errai.codegen.Statement


          for (final Annotation a : annotationSet) {
            LiteralFactory.getLiteral(a).generate(buildContext);
          }

          classStructureBuilder.privateField(fieldName, literalValue.getType())
              .modifiers(Modifier.Final).initializesWith(new Statement() {
            @Override
            public String generate(final Context context) {
              return new ArrayLiteral(literalValue.getValue()).getCanonicalString(context);
            }
View Full Code Here


        .extend()
        .publicOverridesMethod("callback", Parameter.finalOf(producerMember.getDeclaringClass(), "bean"));

    doBindings(blockBuilder, injectionContext, Refs.get("bean"));

    final Statement producerCreationalCallback = blockBuilder.finish().finish();

    statements.append(Stmt.loadVariable("async").invoke("runOnFinish", Stmt.newObject(Runnable.class)
        .extend().publicOverridesMethod("run")
        .append(Stmt.declareFinalVariable(producerBeanCBVar, callbackMC, producerCreationalCallback))
        .append(AsyncInjectUtil.getInjectorOrProxy(injectionContext, injectableInstance,
            producerMember.getDeclaringClass(), producerInjectableInstance.getQualifyingMetadata())
        ).finish().finish()
    ));

    statements.append(Stmt.loadVariable("async").invoke("finish"));

    final Statement producerBeanProvider = statements.finish().finish();

    injectionContext.getProcessingContext().getBootstrapBuilder()
        .privateField(creationalCallbackVarName, beanProviderMC).modifiers(Modifier.Final)
        .initializesWith(producerBeanProvider).finish();
View Full Code Here

    final String producerClassCallbackVar = InjectUtil.getUniqueVarName();
    final MetaClass producerClassType = producerInjectableInstance.getTargetInjector().getInjectedType();
    final MetaClass creationalCallback_MC
        = MetaClassFactory.parameterizedAs(CreationalCallback.class, typeParametersOf(producerClassType));

    final Statement callback = AsyncInjectUtil.generateCallback(producerClassType,
        InjectUtil.invokePublicOrPrivateMethod(injectionContext,
            Refs.get("bean"),
            disposerMethod,
            Refs.get("obj")));
View Full Code Here


    if (producerMember instanceof MetaMethod) {
      final MetaMethod producerMethod = (MetaMethod) producerMember;

      final Statement producerInvocationStatement = InjectUtil.invokePublicOrPrivateMethod(injectionContext,
          beanRef,
          producerMethod,
          AsyncInjectUtil.resolveInjectionDependencies(
              producerMethod.getParameters(),
              injectionContext,
View Full Code Here

          if (injector.isSingleton() && ctx.typeContainsGraphCycles(type)) {
            final MetaClass providerType = MetaClassFactory.parameterizedAs(Provider.class,
                MetaClassFactory.typeParametersOf(type));

            final Statement newObjectCallback = Stmt.newObject(providerType)
                .extend()
                .publicOverridesMethod("get")
                .append(Stmt.nestedCall(Stmt.newObject(type, parameterStatements)).returnValue())
                .finish().finish();

            runBlock.append(Stmt.declareFinalVariable(injector.getInstanceVarName(), type,
                Stmt.loadVariable("context").invoke("getWiredOrNew", Refs.get("beanRef"), newObjectCallback)));
          }
          else {
            runBlock.append(Stmt.declareFinalVariable(injector.getInstanceVarName(), type, Stmt.newObject(type, parameterStatements)));
          }
          final Statement finishedCallback = runBlock
              .append(Stmt.loadVariable("async").invoke("setConstructedObject", Refs.get(injector.getInstanceVarName())))
              .finish()
              .finish();

          processingContext.append(Stmt.loadVariable("async").invoke("setOnConstruct", finishedCallback));

          processingContext.pushBlockBuilder(runBlock);

          callback.beanConstructed(ConstructionType.CONSTRUCTOR);

          handleAsyncInjectionTasks(ctx, injectionTasks);

          if (!postConstructTasks.isEmpty() || !preDestroyTasks.isEmpty()) {
            pushFinishRunnable(ctx);

            InjectUtil.doPostConstruct(ctx, injector, postConstructTasks);
            InjectUtil.doPreDestroy(ctx, injector, preDestroyTasks);

            processingContext.popBlockBuilder(); // once for the finish runnable
          }

          processingContext.popBlockBuilder(); // once for the constructed object callback
        }
      };
    }
    else {
      // field injection
      if (!InjectUtil.hasDefaultConstructor(type))
        throw new InjectionFailure("there is no public default constructor or suitable injection constructor for type: "
            + type.getFullyQualifiedName());

      return new ConstructionStrategy() {
        @Override
        public void generateConstructor(final ConstructionStatusCallback callback) {
          if (injector.isSingleton() && injector.isCreated()) return;

          final IOCProcessingContext processingContext = ctx.getProcessingContext();

          if (injector.isSingleton() && ctx.typeContainsGraphCycles(type)) {
            final MetaClass providerType = MetaClassFactory.parameterizedAs(Provider.class,
                MetaClassFactory.typeParametersOf(type));

            final Statement newObjectCallback = Stmt.newObject(providerType)
                .extend()
                .publicOverridesMethod("get")
                .append(Stmt.nestedCall(Stmt.newObject(type)).returnValue())
                .finish().finish();
View Full Code Here

    final MetaClass[] parmTypes = InjectUtil.parametersToClassTypeArray(parms);
    final Statement[] parmValues = new Statement[parmTypes.length];

    for (int i = 0; i < parmTypes.length; i++) {
      Statement stmt;
      try {
        final InjectableInstance injectableInstance = InjectableInstance.getParameterInjectedInstance(
            parms[i],
            null,
            ctx);
View Full Code Here

                                                         final MetaConstructor constructor) {
    final MetaClass[] parmTypes = InjectUtil.parametersToClassTypeArray(parms);
    final Statement[] parmValues = new Statement[parmTypes.length];

    for (int i = 0; i < parmTypes.length; i++) {
      final Statement stmt;
      final MetaClass parmType = parmTypes[i];
      final MetaParameter metaParameter = parms[i];
      try {
        final QualifyingMetadata qualifyingMetadata = ctx.getProcessingContext().getQualifyingMetadataFactory().createFrom(
            parms[i].getAnnotations()
        );

        // Get the injection value.
        final BlockBuilder<?> blockBuilder = ctx.getProcessingContext().getBlockBuilder();


        blockBuilder.append(getInjectorOrProxy(
            ctx,
            InjectableInstance.getParameterInjectedInstance(parms[i], null, ctx),
            parmType,
            qualifyingMetadata,
            true, new AsyncInjectorResolveCallback() {
          @Override
          public void onResolved(final Injector resolvedInjector) {

            final MetaClass injectedType = resolvedInjector.getInjectedType();
            final MetaClass creationType = MetaClassFactory
                .parameterizedAs(CreationalCallback.class, MetaClassFactory.typeParametersOf(injectedType));

            final Statement callback = Stmt.newObject(creationType).extend()
                .publicOverridesMethod("callback", Parameter.of(injectedType, "beanInstance"))
                .append(Stmt.loadVariable("async").invoke("finish", Refs.get("this"), Refs.get("beanInstance")))
                .finish()
                .finish();
View Full Code Here

  private static Statement recordInlineReference(final InjectionContext ctx,
                                                 final MetaParameter parm) {

    final Injector injector = ctx.getQualifiedInjector(parm.getType(), parm.getAnnotations());

    final Statement stmt = Cast.to(parm.getType(), Stmt.loadVariable("async").invoke("getBeanValue",
        Refs.get(InjectUtil.getVarNameFromType(injector.getConcreteInjectedType(), parm))));

    ctx.addInlineBeanReference(parm, stmt);
    return stmt;
  }
View Full Code Here

     /* get the construction strategy and execute it to wire the bean */
    getConstructionStrategy(this, injectContext).generateConstructor(new ConstructionStatusCallback() {
      @Override
      public void beanConstructed(final ConstructionType constructionType) {
        final Statement beanRef = Refs.get(instanceVarName);

        callbackBuilder.append(
            loadVariable("context").invoke("addBean", loadVariable("context").invoke("getBeanReference", load(type),
                load(qualifyingMetadata.getQualifiers())), beanRef)
        );
View Full Code Here

        = MetaClassFactory.parameterizedAs(CreationalCallback.class,
        MetaClassFactory.typeParametersOf(providerInjector.getInjectedType()));

    final String varName = InjectUtil.getVarNameFromType(providerInjector.getConcreteInjectedType(), injectableInstance);

    final Statement valueRef;

    if (providerInjector.isSingleton() && providerInjector.isRendered()) {
      valueRef = Stmt.loadVariable("beanInstance").invoke("provide", typeArgsClasses,
          qualifiers.length != 0 ? qualifiers : null);
    }
View Full Code Here

TOP

Related Classes of org.jboss.errai.codegen.Statement

Copyright © 2018 www.massapicom. 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.