Package com.google.gwt.user.rebind

Examples of com.google.gwt.user.rebind.SourceWriter


    }

    // start making the class, with basic imports
    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
    factory.addImplementedInterface(typeName);
    SourceWriter sw = factory.createSourceWriter(context, pw);


    // for each method,
    for (JMethod m : toGenerate.getOverridableMethods()) {
      TreeLogger l = logger.branch(Type.DEBUG, "Building method: " + m.getReadableDeclaration());

      // no support for params at this time
      if (m.getParameters().length != 0) {
        l.log(Type.ERROR, "Method " + m.toString() + " must not have parameters.");
        throw new UnableToCompleteException();
      }

      // ask for the types that provide the property data
      JClassType ret = m.getReturnType().isClassOrInterface();
      final AbstractCreator c;
      if (ret.isAssignableTo(valueProviderInterface)) {
        c = new ValueProviderCreator(context, l, m);
      } else if (ret.isAssignableTo(modelKeyProviderInterface)) {
        c = new ModelKeyProviderCreator(context, l, m);
      } else if (ret.isAssignableTo(labelProviderInterface)) {
        c = new LabelProviderCreator(context, l, m);
      } else {
        logger.log(Type.ERROR, "Method uses a return type that cannot be generated");
        throw new UnableToCompleteException();
      }
      c.create();
      // build the method
      // public ValueProvider<T, V> name() { return NameValueProvider.instance;
      // }
      sw.println("public %1$s %2$s() {", m.getReturnType().getQualifiedSourceName(), m.getName());
      sw.indentln("return %1$s;", c.getInstanceExpression());
      sw.println("}");
    }

    sw.commit(logger);

    return factory.getCreatedClassName();
  }
View Full Code Here


      // The whole point of this exercise
      f.addImplementedInterface(sourceType.getQualifiedSourceName());

      // All source gets written through this Writer
      SourceWriter sw = f.createSourceWriter(generatorContext, out);

      // Set the now-calculated simple source name
      resourceContext.setSimpleSourceName(generatedSimpleSourceName);

      // Write the generated code to disk
      createFieldsAndAssignments(logger, sw, generators, resourceContext,
          fields);

      // Print the accumulated field definitions
      sw.println(fields.getCode());

      /*
       * The map-accessor methods use JSNI and need a fully-qualified class
       * name, but should not include any sub-bundles.
       */
      taskList.remove(BundleResourceGenerator.class);
      writeMapMethods(logger, createdClassName, sw, taskList);

      sw.commit(logger);
    }

    finish(logger, resourceContext, generators.keySet());
    doFinish(logger);

View Full Code Here

        // Interfaces
        composerFactory.addImplementedInterface("org.jboss.as.console.client.widgets.forms.PropertyMetaData");

        // SourceWriter
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        // fields
        generateFields(sourceWriter);

        // ctor
        generateConstructor(logger, context, sourceWriter);

        // Methods
        generateMethods(sourceWriter);

        // close generated class
        sourceWriter.outdent();
        sourceWriter.println("}");

        // commit generated class
        context.commit(logger, printWriter);
    }
View Full Code Here

    BlockBuilder<?> blockBuilder =
            classStructureBuilder.publicMethod(BootstrapperInjectionContext.class, "bootstrapContainer")
            .methodComment("The main IOC bootstrap method.");

    SourceWriter sourceWriter = new StringSourceWriter();

    procContext = new IOCProcessingContext(logger, context, sourceWriter, buildContext, bootStrapClass, blockBuilder);
    injectionContext = new InjectionContext(procContext);
    procFactory = new IOCProcessorFactory(injectionContext);

    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    Properties props = scanner.getProperties("ErraiApp.properties");


    if (props != null) {
      logger.log(TreeLogger.Type.INFO, "Checking ErraiApp.properties for configured types ...");

      for (Object o : props.keySet()) {
        String key = (String) o;
        if (key.equals(QUALIFYING_METADATA_FACTORY_PROPERTY)) {
          String fqcnQualifyingMetadataFactory = String.valueOf(props.get(key));

          try {
            QualifyingMetadataFactory factory = (QualifyingMetadataFactory)
                    Class.forName
                            (fqcnQualifyingMetadataFactory).newInstance();

            procContext.setQualifyingMetadataFactory(factory);
          }
          catch (ClassNotFoundException e) {
            e.printStackTrace();
          }
          catch (InstantiationException e) {
            e.printStackTrace();
          }
          catch (IllegalAccessException e) {
            e.printStackTrace();
          }
        }
        else if (key.equals(ENABLED_ALTERNATIVES_PROPERTY)) {
          String[] alternatives = String.valueOf(props.get(ENABLED_ALTERNATIVES_PROPERTY)).split("\\s");
          for (String alternative : alternatives) {
            injectionContext.addEnabledAlternative(alternative.trim());
          }
        }
      }
    }

    procContext.setPackages(packages);

    defaultConfigureProcessor();

    // generator constructor source code
    initializeProviders();
    generateExtensions(sourceWriter, classStructureBuilder, blockBuilder);
    // close generated class

    return sourceWriter.toString();
  }
View Full Code Here

        // Interfaces
        composerFactory.addImplementedInterface("org.jboss.as.console.client.ProductConfig");

        // SourceWriter
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        // ctor
        generateConstructor(sourceWriter);

        // Methods
        generateMethods(sourceWriter, context);

        // close generated class
        sourceWriter.outdent();
        sourceWriter.println("}");

        // commit generated class
        context.commit(logger, printWriter);
    }
View Full Code Here

    composer.addImport("com.google.gwt.core.client.GWT");
    composer.addImport("com.google.gwt.resources.client.ImageResource");

    composer.addImplementedInterface("org.jboss.errai.workspaces.client.api.ResourceFactory");

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    // parse classes
    List<File> targets = ConfigUtil.findAllConfigTargets();
    ConfigUtil.visitAllTargets(
        targets, context, logger,
        sourceWriter,
        new RebindVisitor()
        {
          public void visit(Class<?> clazz, GeneratorContext context, TreeLogger logger, SourceWriter writer)
          {          
            if (clazz.isAnnotationPresent(DefaultBundle.class)) {
              bundleClass = clazz.getAnnotation(DefaultBundle.class).value();
            }
            else if(clazz.isAnnotationPresent(LoadTool.class))
            {
              LoadTool lt = clazz.getAnnotation(LoadTool.class);
              if(!"".equals(lt.icon()))
                tool2imageRes.put(lt.name(), lt.icon());
            }
          }
        }
    );
   
    // generator constructor source code
    generateFactoryClass(context, logger, sourceWriter);

    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);
  }
View Full Code Here

        ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName,
                className);

        composer.addImplementedInterface("org.jboss.errai.workspaces.client.framework.WorkspaceConfig");

        SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

        // generator constructor source code
        generateBootstrapClass(context, logger, sourceWriter);
        // close generated class
        sourceWriter.outdent();
        sourceWriter.println("}");

        // commit generated class
        context.commit(logger, printWriter);
    }
View Full Code Here

    for (ProxyEventDescription desc : proxyEvents) {
      composerFactory.addImplementedInterface(desc.handlerFullName);
    }

    // Get a source writer
    SourceWriter writer = composerFactory.createSourceWriter(ctx, printWriter);

    // Private variable to store the gingector
    writer.println();
    writer.println("private " + ginjectorClassName + " ginjector;");

    if (nameToken == null) {
      // Not a place proxy
     
      if (tabContainerClass != null) {
        // A TabContentProxy
        writeGetTabDataInternalMethod(ginjectorClassName, presenterClassName,
            tabLabel, tabPriority, tabInfoFunctionDescription, writer);
      }
     
    } else {
      // Place proxy

      // BEGIN Enclosed proxy class
      writer.println();
      writer.println("public static class WrappedProxy");
      if (tabContainerClass == null) {
        writer.println("extends " + proxyImplClassName + "<"
            + presenterClassName + "> {");
      } else {
        writer.println("extends " + tabContentProxyImplClassName + "<"
            + presenterClassName + "> {");
      }
      writer.indent();

      if (tabContainerClass != null) {
        // A TabContentProxy
        writeGetTabDataInternalMethod(ginjectorClassName, presenterClassName,
            tabLabel, tabPriority, tabInfoFunctionDescription, writer);
      }
     
      // Enclosed proxy construcotr
      writer.println();
      writer.println("public WrappedProxy() {}");

      // BEGIN Enclosed proxy Bind method
      writer.println();
      writer.println("private void delayedBind(" + ginjectorClassName
          + " ginjector) {");
      writer.indent();

      if (tabContainerClass != null) {
        writeRequestTabHandler(logger, presenterClassName, nameToken,
            tabContainerClass, tabContainerClassName, tabPriority, tabLabel,
            tabInfoFunctionDescription, writer);
      }
     
      // Call ProxyImpl bind method.
      writer.println("bind(ginjector.getProxyFailureHandler(),ginjector.getEventBus());");

      writePresenterProvider(logger, ctx, writer, proxyCodeSplitAnnotation,
          proxyCodeSplitBundleAnnotation, ginjectorClass, ginjectorClassName,
          presenterClass, presenterClassName);
      writeSlotHandlers(logger, ctx, proxyCodeSplitAnnotation,
          proxyCodeSplitBundleAnnotation, presenterClass, presenterClassName,
          ginjectorClassName, ginjectorClass, writer);
      writer.outdent();
      writer.println("}");

      // END Enclosed proxy class
      writer.outdent();
      writer.println("}");

      // Check if title override if needed

      // Simple string title
      if (title != null) {
        writer.println();
        writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
        writer.indent();
        writer.println("event.getHandler().onSetPlaceTitle( \"" + title
            + "\" );");
        writer.outdent();
        writer.println("}");
      }

      // Presenter static title method returning string
      if (titleFunctionDescription != null && titleFunctionDescription.isStatic
          && titleFunctionDescription.returnString) {
        writer.println();
        writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
        writer.indent();
        writer.print("String title = " + presenterClassName + ".");
        writeTitleFunction(titleFunctionDescription, writer);
        writer.println();
        writer.println("event.getHandler().onSetPlaceTitle( title );");
        writer.outdent();
        writer.println("}");
      }

      // Presenter static title method taking a handler (not returning a string)
      if (titleFunctionDescription != null && titleFunctionDescription.isStatic
          && !titleFunctionDescription.returnString) {
        writer.println();
        writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
        writer.indent();
        writer.print(presenterClassName + ".");
        writeTitleFunction(titleFunctionDescription, writer);
        writer.println();
        writer.println("}");
      }

      // Presenter non-static title method returning a string
      if (titleFunctionDescription != null
          && !titleFunctionDescription.isStatic
          && titleFunctionDescription.returnString) {
        writer.println();
        writer.println("protected void getPlaceTitle(final GetPlaceTitleEvent event) {");
        writer.indent();
        writer.println("getPresenter( new AsyncCallback<" + presenterClassName
            + ">(){");
        writer.indent();
        writer.indent();
        writer.println("public void onSuccess(" + presenterClassName + " p ) {");
        writer.indent();
        writer.print("String title = p.");
        writeTitleFunction(titleFunctionDescription, writer);
        writer.println();
        writer.println("event.getHandler().onSetPlaceTitle( title );");
        writer.outdent();
        writer.println(" }");
        writer.println("public void onFailure(Throwable t) { event.getHandler().onSetPlaceTitle(null); }");
        writer.outdent();
        writer.println("} );");
        writer.outdent();
        writer.println("}");
      }

      // Presenter non-static title method taking a handler (not returning a string)
      if (titleFunctionDescription != null
          && !titleFunctionDescription.isStatic
          && !titleFunctionDescription.returnString) {
        writer.println();
        writer.println("protected void getPlaceTitle(final GetPlaceTitleEvent event) {");
        writer.indent();
        writer.println("getPresenter( new AsyncCallback<" + presenterClassName
            + ">(){");
        writer.indent();
        writer.indent();
        writer.print("public void onSuccess(" + presenterClassName
            + " p ) { p.");
        writeTitleFunction(titleFunctionDescription, writer);
        writer.println(" }");
        writer.println("public void onFailure(Throwable t) { event.getHandler().onSetPlaceTitle(null); }");
        writer.outdent();
        writer.println("} );");
        writer.outdent();
        writer.println("}");
      }
    }

    // Constructor
    writer.println();
    writer.println("public " + implClassName + "() {");
    writer.indent();
    writer.println("DelayedBindRegistry.register(this);");
    writer.outdent();
    writer.println("}");

    // BEGIN Bind method
    writer.println();
    writer.println("@Override");
    writer.println("public void delayedBind(Ginjector baseGinjector) {");
    writer.indent();
    writeGinjector(writer, ginjectorClassName);
    if (nameToken == null) {
      // Standard proxy (not a Place)

      if (tabContainerClass != null) {
        writeRequestTabHandler(logger, presenterClassName, tabNameToken,
            tabContainerClass, tabContainerClassName, tabPriority, tabLabel,
            tabInfoFunctionDescription, writer);
      }

      // Call ProxyImpl bind method.
      writer.println("bind(ginjector.getProxyFailureHandler(),ginjector.getEventBus());");

      writePresenterProvider(logger, ctx, writer, proxyCodeSplitAnnotation,
          proxyCodeSplitBundleAnnotation, ginjectorClass, ginjectorClassName,
          presenterClass, presenterClassName);

      writeSlotHandlers(logger, ctx, proxyCodeSplitAnnotation,
          proxyCodeSplitBundleAnnotation, presenterClass, presenterClassName,
          ginjectorClassName, ginjectorClass, writer);
    } else {

      // Place proxy

      // Call ProxyPlaceAbstract bind method.
      writer.println("bind(ginjector.getProxyFailureHandler(), ");
      writer.println("    ginjector.getPlaceManager(),");
      writer.println("    ginjector.getEventBus());");
      writer.println("WrappedProxy wrappedProxy = GWT.create(WrappedProxy.class);");
      writer.println("wrappedProxy.delayedBind( ginjector ); ");
      writer.println("proxy = wrappedProxy; ");
      writer.println("String nameToken = \"" + nameToken + "\"; ");
      if (newPlaceCode == null) {
        if (getGatekeeperMethod == null) {
          writer.println("place = new " + placeImplClassName + "( nameToken );");
        } else {
          writer.println("place = new " + placeWithGatekeeperClassName
              + "( nameToken, ginjector." + getGatekeeperMethod + "() );");
        }
      } else {
        writer.println("place = " + newPlaceCode + ";");
      }
    }

    // Register all @ProxyEvent
    for (ProxyEventDescription desc : proxyEvents) {
      writer.println("getEventBus().addHandler( " + desc.eventFullName
          + ".getType(), this );");
    }

    // END Bind method
    writer.outdent();
    writer.println("}");

    // Write all handler methods
    for (ProxyEventDescription desc : proxyEvents) {
      writer.println("");
      writeHandlerMethod(presenterClassName, desc, writer);
    }

    writer.commit(logger);

    return generatedClassName;
  }
View Full Code Here

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName,
        className);

    composer.addImplementedInterface("org.jboss.errai.workspaces.client.framework.WorkspaceConfig");

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    ctx = new ProcessingContext(logger, context, sourceWriter, typeOracle);
    iocGenerator = new IOCGenerator(ctx);
    iocGenerator.initializeProviders(context, logger, sourceWriter);

    // generator constructor source code
    generateBootstrapClass(context, logger, sourceWriter);
    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);
  }
View Full Code Here

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
        packageName, simpleSourceName);
    factory.setSuperclass(AbstractClientRequestFactory.class.getCanonicalName());
    factory.addImplementedInterface(typeName);
    SourceWriter sw = factory.createSourceWriter(context, pw);
    writeAutoBeanFactory(sw);
    writeContextMethods(sw);
    writeContextImplementations();
    writeTypeMap(sw);
    sw.commit(logger);

    return factory.getCreatedClassName();
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.user.rebind.SourceWriter

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.