Package org.jboss.errai.codegen.builder.impl

Examples of org.jboss.errai.codegen.builder.impl.ObjectBuilder


            .extend()
            .publicOverridesMethod(handlerType.getMethods()[0].getName(), Parameter.of(eventType, "event"));
        listenerBuiler.append(InjectUtil.invokePublicOrPrivateMethod(ctx.getInjectionContext(), component,
            method, Stmt.loadVariable("event")));

        ObjectBuilder listenerInstance = listenerBuiler.finish().finish();

        int eventsToSink = Event.FOCUSEVENTS | Event.GESTUREEVENTS | Event.KEYEVENTS | Event.MOUSEEVENTS
            | Event.TOUCHEVENTS;
        if (method.isAnnotationPresent(SinkNative.class)) {
          eventsToSink = method.getAnnotation(SinkNative.class).value();
        }

        for (String name : targetDataFieldNames) {

          if (processedNativeHandlers.contains(name) || processedEventHandlers.contains(name)) {
            throw new GenerationException(
                "Cannot specify more than one @EventHandler method when @SyncNative is used for data-field ["
                    + name + "] in class ["
                    + declaringClass.getFullyQualifiedName()
                    + "].");
          }
          else {
            processedNativeHandlers.add(name);
          }

          if (dataFieldTypes.containsKey(name)) {
            MetaClass dataFieldType = dataFieldTypes.get(name);
            if (!dataFieldType.isAssignableTo(Element.class)) {
              /*
               * We have a GWT or other Widget type.
               */
              throw new GenerationException("@DataField [" + name + "] of type [" + dataFieldType.getName()
                  + "] in class [" + declaringClass.getFullyQualifiedName() + "] is not assignable to ["
                  + Element.class.getName() + "] specified by @EventHandler method " + method.getName()
                  + "("
                  + eventType.getName() + ")]");
            }
            else {
              /*
               * We have a wrapped native Element reference
               */
              throw new GenerationException("Cannot attach native DOM events to @DataField [" + name
                  + "] of type ["
                  + dataFieldType.getName() + "] in class [" + declaringClass.getFullyQualifiedName()
                  + "] specified by @EventHandler method " + method.getName() + "(" + eventType.getName()
                  + ")] - Use the corresponding GWT 'EventHandler' types instead.");
            }
          }
          else {
            /*
             * We are completely native and have no reference to this data-field
             * Element in Java
             */
            builder.append(Stmt.invokeStatic(TemplateUtil.class, "setupNativeEventListener", component,
                Stmt.loadVariable(dataFieldElementsVarName).invoke("get", name), listenerInstance,
                eventsToSink));
          }
        }
      }
      else {
        /*
         * We have a GWT Widget type
         */
        MetaClass handlerType;
        try {
          handlerType = getHandlerForEvent(eventType);
        }
        catch (GenerationException e) {
          /*
           *  see ERRAI-373 for details on this crazy inference (without this message, the cause of the
           *  problem is nearly impossible to diagnose)
           */
          if (declaringClass.getClass() == JavaReflectionClass.class) {
            throw new GenerationException(
                "The type " + declaringClass.getFullyQualifiedName() + " looks like a client-side" +
                    " @Templated class, but it is not known to GWT. This probably means that " +
                    declaringClass.getName() + " or one of its supertypes contains non-translatable code." +
                    " Run the GWT compiler with logLevel=DEBUG to pinpoint the problem.", e);
          }
          throw e;
        }

        BlockBuilder<AnonymousClassStructureBuilder> listenerBuiler = ObjectBuilder.newInstanceOf(handlerType)
            .extend()
            .publicOverridesMethod(handlerType.getMethods()[0].getName(), Parameter.of(eventType, "event"));


        listenerBuiler.append(InjectUtil.invokePublicOrPrivateMethod(ctx.getInjectionContext(),
            component, method, Stmt.loadVariable("event")));

        ObjectBuilder listenerInstance = listenerBuiler.finish().finish();

        MetaClass hasHandlerType = MetaClassFactory.get("com.google.gwt.event.dom.client.Has"
            + handlerType.getName()
            + "s");

View Full Code Here


        final String varName = InjectUtil.getVarNameFromType(concreteInjectedType, metaParameter);

        final MetaClass depCreationCallbackMC = parameterizedAs(CreationalCallback.class,
            typeParametersOf(concreteInjectedType));

        final ObjectBuilder callback = Stmt.newObject(depCreationCallbackMC)
            .extend().publicOverridesMethod("callback", Parameter.finalOf(concreteInjectedType, "beanValue"))
            .append(Stmt.loadVariable("async").invoke("finish", Refs.get("this"), Refs.get("beanValue")))
            .finish().finish();

        statements.append(Stmt.declareFinalVariable(varName, depCreationCallbackMC, callback));
View Full Code Here

    final BlockBuilder<AnonymousClassStructureBuilder> run = Stmt.newObject(Runnable.class)
        .extend().publicOverridesMethod("run");

    ctx.getProcessingContext().pushBlockBuilder(run);

    final ObjectBuilder objectBuilder = run.finish().finish();

    blockBuilder.append(Stmt.loadVariable("async").invoke("runOnFinish", objectBuilder));
  }
View Full Code Here

    for (final Statement stmt : fieldAccessStmt) {
      statements.append(stmt);
    }

    final ObjectBuilder finish = statements.finish()
        .publicOverridesMethod("toString")
        .append(Stmt.load(type).invoke("getName").returnValue()).finish()
        .finish();

    return finish;
View Full Code Here

      statements.append(stmt);
    }

    ctx.setAttribute(RECEIVING_CALLBACK_ATTRIB, statements);

    final ObjectBuilder finish = statements.finish()
        .publicOverridesMethod("toString")
        .append(Stmt.load(type).invoke("getName").returnValue()).finish()
        .finish();

    processingContext.append(Stmt.declareFinalVariable(callbackVarName, callbackClass, finish));
View Full Code Here

            loadVariable("context").invoke("addBean", Refs.get("beanRef"), Refs.get(instanceVarName))
        );

        /* add the bean to SimpleCreationalContext */

        final ObjectBuilder objectBuilder = Stmt.create().newObject(Runnable.class);
        final BlockBuilder<AnonymousClassStructureBuilder> blockBuilder = objectBuilder
            .extend().publicOverridesMethod("run");

        final BlockBuilderUpdater updater
            = new BlockBuilderUpdater(injectContext, AsyncTypeInjector.this, constructionType, targetBlock, blockBuilder);

        setAttribute("BlockBuilderUpdater", updater);
        final Statement beanRef = updater.run();

        injectContext.addBeanReference(type, beanRef);
        addStatementToEndOfInjector(Stmt.loadVariable("async").invoke("runOnFinish", blockBuilder.finish().finish()));

        /* mark this injector as injected so we don't go into a loop if there is a cycle. */
        setCreated(true);
      }
    });

    /*
    return the instance of the bean from the creational callback.
    */

    targetBlock.appendAll(getAddToEndStatements());

    targetBlock._(Stmt.loadVariable("async").invoke("finish"));

    /* pop the block builder of the stack now that we're done wiring. */
    ctx.popBlockBuilder();

    if (loadAsync) {
      final ObjectBuilder objectBuilder = targetBlock.finish().finish();

      final String frameworkOrSystemProperty
          = EnvUtil.getEnvironmentConfig().getFrameworkOrSystemProperty("errai.ioc.testing.simulated_loadasync_latency");
      if (Boolean.parseBoolean(frameworkOrSystemProperty)) {
        callbackBuilder.append(Stmt.invokeStatic(FakeGWT.class, "runAsync", objectBuilder));
View Full Code Here

    final BlockBuilder<AnonymousClassStructureBuilder> run = Stmt.newObject(Runnable.class)
        .extend().publicOverridesMethod("run");

    ctx.getProcessingContext().pushBlockBuilder(run);

    final ObjectBuilder objectBuilder = run.finish().finish();

    blockBuilder.append(Stmt.loadVariable("async").invoke("runOnFinish", objectBuilder));
  }
View Full Code Here

    for (final Statement stmt : fieldAccessStmt) {
      statements.append(stmt);
    }

    final ObjectBuilder finish = statements.finish()
        .publicOverridesMethod("toString")
        .append(Stmt.load(type).invoke("getName").returnValue()).finish()
        .finish();

    return finish;
View Full Code Here

            loadVariable("context").invoke("addBean", Refs.get("beanRef"), Refs.get(instanceVarName))
        );

        /* add the bean to SimpleCreationalContext */

        final ObjectBuilder objectBuilder = Stmt.create().newObject(Runnable.class);
        final BlockBuilder<AnonymousClassStructureBuilder> blockBuilder = objectBuilder
            .extend().publicOverridesMethod("run");

        final BlockBuilderUpdater updater
            = new BlockBuilderUpdater(injectContext, AsyncTypeInjector.this, constructionType, targetBlock, blockBuilder);

        setAttribute("BlockBuilderUpdater", updater);
        final Statement beanRef = updater.run();

        injectContext.addBeanReference(type, beanRef);
        addStatementToEndOfInjector(Stmt.loadVariable("async").invoke("runOnFinish", blockBuilder.finish().finish()));

        /* mark this injector as injected so we don't go into a loop if there is a cycle. */
        setCreated(true);
      }
    });

    /*
    return the instance of the bean from the creational callback.
    */

    targetBlock.appendAll(getAddToEndStatements());

    targetBlock._(Stmt.loadVariable("async").invoke("finish"));

    /* pop the block builder of the stack now that we're done wiring. */
    ctx.popBlockBuilder();

    if (loadAsync) {
      final ObjectBuilder objectBuilder = targetBlock.finish().finish();

      final String frameworkOrSystemProperty
          = EnvUtil.getEnvironmentConfig().getFrameworkOrSystemProperty("errai.ioc.testing.simulated_loadasync_latency");
     
      Class<?> fragmentName = type.getAnnotation(LoadAsync.class).value();
View Full Code Here

        final String varName = InjectUtil.getVarNameFromType(concreteInjectedType, metaParameter);

        final MetaClass depCreationCallbackMC = parameterizedAs(CreationalCallback.class,
            typeParametersOf(concreteInjectedType));

        final ObjectBuilder callback = Stmt.newObject(depCreationCallbackMC)
            .extend().publicOverridesMethod("callback", Parameter.finalOf(concreteInjectedType, "beanValue"))
            .append(Stmt.loadVariable("async").invoke("finish", Refs.get("this"), Refs.get("beanValue")))
            .finish().finish();

        statements.append(Stmt.declareFinalVariable(varName, depCreationCallbackMC, callback));
View Full Code Here

TOP

Related Classes of org.jboss.errai.codegen.builder.impl.ObjectBuilder

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.