Package org.jboss.errai.codegen

Examples of org.jboss.errai.codegen.Statement


    if (!disposerMethod.isPublic()) {
      injectionContext.addExposedMethod(disposerMethod);
    }

    final Statement disposerInvoke = InjectUtil.invokePublicOrPrivateMethod(injectionContext,
        Refs.get(producerInjectableInstance.getTargetInjector().getInstanceVarName()),
        disposerMethod,
        Refs.get("obj"));

    initMeth._(disposerInvoke);
View Full Code Here


        .extend()
        .publicOverridesMethod("getInstance", Parameter.of(CreationalContext.class, "pContext"));

    injectionContext.getProcessingContext().pushBlockBuilder(statements);

    final Statement producerCreationalCallback = statements
        ._(Stmt.declareVariable(injectedType)
            .named(var).initializeWith(getValueStatement(injectionContext,
                injectionContext.getInjector(producerMember.getDeclaringClass()).getBeanInstance(injectableInstance))))
        ._(loadVariable("context").invoke("addBean",
            loadVariable("context").invoke("getBeanReference",
View Full Code Here

    for (String property : bindable.getBeanDescriptor().getProperties()) {
      generateGetter(classBuilder, property, getMethod);
      generateSetter(classBuilder, property, setMethod);
    }

    Statement nonExistingPropertyException = Stmt.throw_(NonExistingPropertyException.class, Variable.get("property"));
    getMethod.append(nonExistingPropertyException).finish();
    setMethod.append(nonExistingPropertyException).finish();
  }
View Full Code Here

          );

      MetaClass paramType = setterMethod.getParameters()[0].getType();

      // If the setter method we are proxying returns a value, capture that value into a local variable
      Statement returnValueOfSetter = null;
      String returnValName = ensureSafeLocalVariableName("returnValueOfSetter", setterMethod);
     
      Statement wrappedListProperty = EmptyStatement.INSTANCE;
      if (paramType.isAssignableTo(List.class)) {
        wrappedListProperty = Stmt.loadVariable(property).assignValue(
            agent().invoke("ensureBoundListIsProxied", property, Stmt.loadVariable(property)));
      }
     
      Statement callSetterOnTarget =
          target().invoke(setterMethod.getName(), Cast.to(paramType, Stmt.loadVariable(property)));
      if (!setterMethod.getReturnType().equals(MetaClassFactory.get(void.class))) {
        callSetterOnTarget =
            Stmt.declareFinalVariable(returnValName, setterMethod.getReturnType(), callSetterOnTarget);
        returnValueOfSetter = Stmt.nestedCall(Refs.get(returnValName)).returnValue();
      }
      else {
        returnValueOfSetter = EmptyStatement.INSTANCE;
      }

      Statement updateNestedProxy = null;
      if (paramType.isAnnotationPresent(Bindable.class)) {
        updateNestedProxy =
            Stmt.if_(Bool.expr(agent("binders").invoke("containsKey", property)))
                .append(Stmt.loadVariable(property).assignValue(Cast.to(paramType,
                    agent("binders").invoke("get", property).invoke("setModel", Variable.get(property)))))
View Full Code Here

          MetaClass type = getTypeOrFirstUpperBound(method.getGenericParameterTypes()[i], method);
          if (type == null) return;
          parms[i] = Parameter.of(type, parms[i].getName());
        }

        Statement callOnTarget = null;
        Statement returnValue = null;
        String returnValName = ensureSafeLocalVariableName("returnValue", method);
       
        MetaClass returnType = getTypeOrFirstUpperBound(method.getGenericReturnType(), method);
        if (returnType == null)
          return;
View Full Code Here

  private ContextualStatementBuilder agent() {
    return Stmt.loadClassMember(agentField);
  }

  private ContextualStatementBuilder target() {
    return Stmt.nestedCall(new Statement() {
      @Override
      public String generate(Context context) {
        return agent().loadField("target").generate(context);
      }
View Full Code Here

      throw new RuntimeException("transient value already exists: " + name + "::" + type.getFullyQualifiedName());
    }

    final IOCProcessingContext pCtx = getInjectionContext().getProcessingContext();
    if (hasUnsatisfiedTransientValue(name, type)) {
      final Statement unsatisfiedTransientValue = getUnsatisfiedTransientValue(name, type);
      pCtx.append(Stmt.nestedCall(unsatisfiedTransientValue).invoke("set", valueRef));
      classStatementMap.put(type, Stmt.nestedCall(unsatisfiedTransientValue).invoke("get"));
      markSatisfied(name, type);
    }
    else {
View Full Code Here

  public Statement getTransientValue(final String name, final MetaClass type) {
    final TransientDataHolder holder = getTransientDataHolder();
    final Map<MetaClass, Statement> metaClassStatementMap = holder.transientValues.get(name);
    if (metaClassStatementMap != null) {
      final Statement statement = metaClassStatementMap.get(type);
      if (statement != null) {
        return statement;
      }
    }
View Full Code Here

   * @return a statement representing the value of the injection point.
   */
  public Statement getValueStatement() {

    final Statement[] stmt;
    final Statement val;

    if (getTargetInjector().getInjectedType().equals(getEnclosingType()) &&
        getTargetInjector().getQualifyingMetadata().equals(getQualifyingMetadata()) &&
        getInjector() != null) {

      val = Refs.get(getInjector().getInstanceVarName());
    }
    else {
      val = Refs.get(getTargetInjector().getInstanceVarName());
    }

    switch (taskType) {
      case Field:
      case PrivateField:
        return InjectUtil.getPublicOrPrivateFieldValue(injectionContext,
            val,
            field);

      case PrivateMethod:
      case Method:
        if (method.getReturnType().isVoid()) {
          return Stmt.load(Void.class);
        }

        if (injectionContext.isAsync()) {
          stmt = AsyncInjectUtil.resolveInjectionDependencies(method.getParameters(), injectionContext, method);
        }
        else {
          stmt = InjectUtil.resolveInjectionDependencies(method.getParameters(), injectionContext, method);
        }


        return InjectUtil.invokePublicOrPrivateMethod(injectionContext,
            val,
            method,
            stmt);

      case Parameter:
        final Statement inlineStmt = injectionContext.getInlineBeanReference(parm);
        if (inlineStmt == null) {
          return Stmt.loadVariable("context").invoke("getBeanInstance",
              parm.getType(),
              InjectUtil.getQualifiersFromAnnotationsAsArray(parm.getAnnotations()));
        }
View Full Code Here

  public boolean doTask(final InjectionContext ctx) {
    final IOCProcessingContext processingContext = ctx.getProcessingContext();
    final InjectableInstance injectableInstance = getInjectableInstance(ctx);
    final QualifyingMetadata qualifyingMetadata = processingContext.getQualifyingMetadataFactory()
        .createFrom(injectableInstance.getQualifiers());
    final Statement val;

    ctx.allowProxyCapture();

    switch (taskType) {
      case Type:
        ctx.getQualifiedInjector(type, qualifyingMetadata);
        break;

      case PrivateField:
        ctx.addExposedField(field, PrivateAccessType.Write);

      case Field: {
        final Statement beanRefStmt = ctx.getBeanReference(injector.getInjectedType());
        final Statement fieldAccessStmt;

        if (field.isStatic()) {
          throw new InjectionFailure("attempt to inject bean into a static field: "
              + field.getDeclaringClass().getFullyQualifiedName() + "." + field.getName());
        }
        else {
          fieldAccessStmt = InjectUtil.setPublicOrPrivateFieldValue(ctx, beanRefStmt, field, Refs.get("bean"));
        }

        try {
          val = AsyncInjectUtil.getInjectorOrProxy(ctx, getInjectableInstance(ctx), field.getType(), qualifyingMetadata,
              new AsyncInjectorResolveCallback() {
                @Override
                public void onResolved(final Injector resolvedInjector) {
                  generateCallback(InjectUtil.getVarNameFromType(resolvedInjector.getConcreteInjectedType(), field),
                      resolvedInjector.getInjectedType(), ctx, fieldAccessStmt,
                      Stmt.loadVariable("async").invoke("finish", Refs.get("this")));
                }
              });
        }
        catch (InjectionFailure e) {
          throw UnsatisfiedDependenciesException.createWithSingleFieldFailure(field, field.getDeclaringClass(),
              field.getType(), e.getMessage());
        }
        catch (UnproxyableClassException e) {
          final String err = "your object graph may have cyclical dependencies and the cycle could not be proxied. " +
              "use of the @Dependent scope and @New qualifier may not " +
              "produce properly initalized objects for: " + getInjector().getInjectedType().getFullyQualifiedName() + "\n" +
              "\t Offending node: " + toString() + "\n" +
              "\t Note          : this issue can be resolved by making "
              + e.getUnproxyableClass().getFullyQualifiedName() + " proxyable. Introduce a default" +
              " no-arg constructor and make sure the class is non-final.";

          throw UnsatisfiedDependenciesException.createWithSingleFieldFailure(field, field.getDeclaringClass(),
              field.getType(), err);
        }

        processingContext.append(val);

        break;
      }

      case PrivateMethod:
        ctx.addExposedMethod(method);

      case Method: {
        for (final MetaParameter parm : method.getParameters()) {
          ctx.getProcessingContext().handleDiscoveryOfType(
              InjectableInstance.getParameterInjectedInstance(parm, injector, ctx), parm.getType());
        }

        final AtomicInteger atomicInteger = new AtomicInteger(0);

        final Statement[] args = AsyncInjectUtil.resolveInjectionDependencies(method.getParameters(), ctx, method,
            new AsyncInjectorResolveCallback() {
              @Override
              public void onResolved(final Injector resolvedInjector) {
                generateCallback(
                    InjectUtil.getVarNameFromType(resolvedInjector.getConcreteInjectedType(),
                        method.getParameters()[atomicInteger.getAndIncrement()]),
                    resolvedInjector.getInjectedType(),
                    ctx,
                    Stmt.loadVariable("async").invoke("finish", Refs.get("this"), Refs.get("bean")));
              }
            });

        final Statement beanRef = ctx.getBeanReference(method.getDeclaringClass());

        final Statement methodCallStatement = InjectUtil.invokePublicOrPrivateMethod(ctx,
            beanRef,
            method,
            args);

        final Statement finishCallback = Stmt.newObject(Runnable.class).extend()
            .publicOverridesMethod("run")
            .append(methodCallStatement)
            .finish()
            .finish();
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.