Java Code Examples for com.google.gwt.user.rebind.ClassSourceFileComposerFactory#addImplementedInterface()

The following examples show how to use com.google.gwt.user.rebind.ClassSourceFileComposerFactory#addImplementedInterface() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectPresenterCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void initComposer(ClassSourceFileComposerFactory composerFactory) {
	composerFactory.addImport(Place.class.getName());
	composerFactory.addImport(Presenter.class.getName());
	for (JMethod presenterMethod : this.presenterMethods) {
		if (presenterMethod.getParameters().length > 0) {
			JType placeType = presenterMethod.getParameters()[0].getType();
			composerFactory.addImport(placeType.getQualifiedSourceName());
			if (placeType instanceof JParameterizedType) {
				JParameterizedType parameterizedType = (JParameterizedType) placeType;
				for (JType paramType : parameterizedType.getTypeArgs()) {
					composerFactory.addImport(paramType.getQualifiedSourceName());
				}
			}
		}
	}

	composerFactory.addImplementedInterface(Presenter.class.getSimpleName());
	composerFactory.addImport(AcceptsOneWidget.class.getName());
}
 
Example 2
Source File: UiBinderLocalizedCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {

		String packageName = this.binderType.getPackage().getName();
		String className = this.binderProxySimpleName;

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

		composerFactory.addImport(GWT.class.getName());
		composerFactory.addImport(UiBinder.class.getName());
		composerFactory.addImport(UiBinderLocalized.class.getName());
		composerFactory.addImport(UiTemplate.class.getName());

		composerFactory.addImport(this.binderType.getQualifiedSourceName());
		composerFactory.addImport(this.widgetType.getQualifiedSourceName());
		composerFactory.addImport(this.targetType.getQualifiedSourceName());

		composerFactory.addImplementedInterface(UiBinderLocalized.class.getSimpleName() + "<"
			+ this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">");
		composerFactory.addImplementedInterface(UiBinder.class.getSimpleName() + "<"
			+ this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">");
		composerFactory.addImplementedInterface(this.binderType.getSimpleSourceName());

		return composerFactory.createSourceWriter(ctx, printWriter);
	}
 
Example 3
Source File: EventBinderGenerator.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
private SourceWriter createSourceWriter(
    TreeLogger logger,
    GeneratorContext context,
    JClassType eventBinderType,
    JClassType targetType) {
  String simpleName = getSimpleGeneratedClassName(eventBinderType);
  String packageName = eventBinderType.getPackage().getName();
  ClassSourceFileComposerFactory composer =
      new ClassSourceFileComposerFactory(packageName, simpleName);

  composer.setSuperclass(AbstractEventBinder.class.getCanonicalName()
      + "<" + targetType.getQualifiedSourceName() + ">");
  composer.addImplementedInterface(eventBinderType.getName());

  composer.addImport(EventBinder.class.getCanonicalName());
  composer.addImport(EventBus.class.getCanonicalName());
  composer.addImport(GenericEvent.class.getCanonicalName());
  composer.addImport(GenericEventHandler.class.getCanonicalName());
  composer.addImport(HandlerRegistration.class.getCanonicalName());
  composer.addImport(LinkedList.class.getCanonicalName());
  composer.addImport(List.class.getCanonicalName());

  PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
  return (printWriter != null) ? composer.createSourceWriter(context, printWriter) : null;
}
 
Example 4
Source File: Mvp4gGenerator.java    From mvp4g with Apache License 2.0 5 votes vote down vote up
private SourceWriter getSourceWriter(TreeLogger logger,
                                     GeneratorContext context,
                                     JClassType originalType,
                                     String packageName,
                                     String generatedClassName)
  throws UnableToCompleteException {

  logger.log(TreeLogger.INFO,
             "Generating writer for " + packageName + "." + generatedClassName,
             null);

  PrintWriter printWriter = context.tryCreate(logger,
                                              packageName,
                                              generatedClassName);
  if (printWriter == null) {
    return null;
  }

  ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName,
                                                                                   generatedClassName);

  classFactory.addImplementedInterface(originalType.getName());
  String[] classesToImport = getClassesToImport();
  for (String classToImport : classesToImport) {
    classFactory.addImport(classToImport);
  }

  return classFactory.createSourceWriter(context,
                                         printWriter);
}
 
Example 5
Source File: ProxyViewCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {
	ClassSourceFileComposerFactory composerFactory =
		new ClassSourceFileComposerFactory(this.packageName, this.viewProxySimpleName);

	composerFactory.setSuperclass(this.placeType.getSimpleSourceName());

	composerFactory.addImport(GWT.class.getName());
	composerFactory.addImport(RunAsyncCallback.class.getName());
	composerFactory.addImport(ViewProxy.class.getName());
	composerFactory.addImport(Place.class.getName());
	composerFactory.addImport(ViewPlace.class.getName());
	composerFactory.addImport(Activity.class.getName());
	composerFactory.addImport(ViewActivity.class.getName());
	composerFactory.addImport(ApplicationUnreachableException.class.getName());
	composerFactory.addImport(this.placeType.getQualifiedSourceName());
	composerFactory.addImport(this.activityDescrition.view().getCanonicalName());
	if (this.placeTokenizerClass != null) {
		composerFactory.addImport(this.placeTokenizerClass.getCanonicalName());
	}
	if (this.viewDecoratorClass != null) {
		composerFactory.addImport(this.viewDecoratorClass.getCanonicalName());
	}

	composerFactory.addImplementedInterface(
		ViewProxy.class.getSimpleName() + "<" + this.placeType.getSimpleSourceName() + ">");

	return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example 6
Source File: ServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {

		String packageName = this.handlerType.getPackage().getName();
		String className =
			this.proxyModelQualifiedName.indexOf('.') == -1 ?
				this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring(
					this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length());

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

		composerFactory.addImport(AsyncCallback.class.getName());

		composerFactory.addImport(AbstractServiceBinder.class.getName());
		composerFactory.addImport(Arrays.class.getName());
		composerFactory.addImport(Lists.class.getName());
		composerFactory.addImport(CommandDefinition.class.getName());
		composerFactory.addImport(CommandParam.class.getName());
		composerFactory.addImport(CallbackAdapter.class.getName());
		composerFactory.addImport(CommandController.class.getName());

		composerFactory.addImport(this.serviceType.getQualifiedSourceName());
		composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName());

		for (JType jType : this.imports) {
			if (jType.isPrimitive() != null) {
				continue;
			}
			composerFactory.addImport(jType.getQualifiedSourceName());
		}

		composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName()
			+ "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">");

		composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName());
		composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName());

		return composerFactory.createSourceWriter(ctx, printWriter);
	}
 
Example 7
Source File: InjectErrorManagerCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initComposer(ClassSourceFileComposerFactory composerFactory) {
	composerFactory.addImport(EntryPoint.class.getName());
	composerFactory.addImport(SimpleErrorDisplayer.class.getName());
	composerFactory.addImport(ErrorManager.class.getName());
	composerFactory.addImport(ErrorDisplayer.class.getName());

	composerFactory.addImplementedInterface(EntryPoint.class.getName());
}
 
Example 8
Source File: InjectThemeCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initComposer(ClassSourceFileComposerFactory composerFactory) {
	composerFactory.addImport(EntryPoint.class.getName());
	composerFactory.addImport(Theme.class.getName());
	composerFactory.addImport(ThemeController.class.getName());
	composerFactory.addImport(CssLink.class.getName());

	composerFactory.addImplementedInterface(EntryPoint.class.getName());
}
 
Example 9
Source File: InjectMvpDescriptionCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initComposer(ClassSourceFileComposerFactory composerFactory) {
	composerFactory.addImport(EntryPoint.class.getName());
	composerFactory.addImport(MvpController.class.getName());
	composerFactory.addImport(ActivityFactory.class.getName());
	composerFactory.addImport(EntryPoint.class.getName());
	composerFactory.addImport(AcceptsOneWidget.class.getName());
	composerFactory.addImport(IsWidget.class.getName());
	composerFactory.addImport(RootPanel.class.getName());

	composerFactory.addImplementedInterface(EntryPoint.class.getName());
}
 
Example 10
Source File: RestServiceBinderCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) {

		String packageName = this.handlerType.getPackage().getName();
		String className =
			this.proxyModelQualifiedName.indexOf('.') == -1 ?
				this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring(
					this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length());

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

		composerFactory.addImport(AbstractServiceBinder.class.getName());
		composerFactory.addImport(Arrays.class.getName());
		composerFactory.addImport(Lists.class.getName());
		composerFactory.addImport(MethodCallbackAdapter.class.getName());
		composerFactory.addImport(Method.class.getName());
		composerFactory.addImport(CompositeMethodCallback.class.getName());
		composerFactory.addImport(CallbackAdapter.class.getName());
		composerFactory.addImport(REST.class.getName());
		composerFactory.addImport(GWT.class.getName());

		composerFactory.addImport(this.serviceType.getQualifiedSourceName());
		composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName());

		for (JType jType : this.imports) {
			if (jType.isPrimitive() != null) {
				continue;
			}
			composerFactory.addImport(jType.getQualifiedSourceName());
		}

		composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName()
			+ "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">");

		composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName());
		composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName());

		return composerFactory.createSourceWriter(ctx, printWriter);
	}
 
Example 11
Source File: ProductConfigGenerator.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generate source code for new class. Class extends
 * <code>HashMap</code>.
 *
 * @param logger  Logger object
 * @param context Generator context
 */
private void generateClass(TreeLogger logger, GeneratorContext context) throws Throwable {

    // get print writer that receives the source code
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) { return; }

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, className);

    // Imports
    composerFactory.addImport("org.jboss.as.console.client.Console");
    composerFactory.addImport("org.jboss.as.console.client.ProductConfig");

    composerFactory.addImport("java.util.*");

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

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

    // ctor
    generateConstructor(sourceWriter);

    // Methods
    generateMethods(logger, sourceWriter, context);

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

    // commit generated class
    context.commit(logger, printWriter);
}
 
Example 12
Source File: TextBinderGenerator.java    From EasyML with Apache License 2.0 4 votes vote down vote up
@Override
public String generate(TreeLogger logger, GeneratorContext context,
		String requestedClass) throws UnableToCompleteException {

	TypeOracle typeOracle = context.getTypeOracle();

	JClassType objectType = typeOracle.findType(requestedClass);
	if (objectType == null) {
		logger.log(TreeLogger.ERROR, "Could not find type: " + requestedClass);
		throw new UnableToCompleteException();
	}

	implTypeName = objectType.getSimpleSourceName() + "Impl";

	implPackageName = objectType.getPackage().getName();

	JClassType[] implementedTypes = objectType.getImplementedInterfaces();

	// Can only implement one interface
	if (implementedTypes == null
			|| implementedTypes.length != 1
			|| !implementedTypes[0].getQualifiedSourceName().equals(
					TextBinder.class.getName())) {
		logger
		.log(
				TreeLogger.ERROR,
				"The type: " + requestedClass
				+ " Must implement only one interface: "
				+ TextBinder.class.getName());
		throw new UnableToCompleteException();
	}

	// Get parameterized type
	JParameterizedType parameterType = implementedTypes[0].isParameterized();
	if (parameterType == null) {
		logger.log(TreeLogger.ERROR, "The type: " + requestedClass
				+ " Must implement only one parameterized interface: "
				+ TextBinder.class.getName());
		throw new UnableToCompleteException();
	}

	if (parameterType.getTypeArgs() == null

			|| parameterType.getTypeArgs().length != 2) {
		logger.log(TreeLogger.ERROR,
				"The type: " + requestedClass
				+ " Must implement two parameterized interface: "
				+ TextBinder.class.getName() + " with two Parameter");
		throw new UnableToCompleteException();

	}

	parameterizedType1 = parameterType.getTypeArgs()[0];
	parameterizedType2 = parameterType.getTypeArgs()[1];
	// logger.log(TreeLogger.INFO ,
	// parameterizedType2.getParameterizedQualifiedSourceName() +"\n"
	// + parameterizedType2.getQualifiedSourceName());

	ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(
			implPackageName, implTypeName);

	composerFactory.addImport(Map.class.getCanonicalName());
	composerFactory.addImport(List.class.getCanonicalName());
	// composerFactory.addImport(Field.class.getCanonicalName());
	composerFactory
	.addImplementedInterface(objectType.getQualifiedSourceName());

	PrintWriter printWriter = context.tryCreate(logger, implPackageName,
			implTypeName);
	if (printWriter != null) {

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

		composeBindMethod(logger, sourceWriter);
		composeSyncMethod(logger, sourceWriter);
		sourceWriter.commit(logger);

	}
	return implPackageName + "." + implTypeName;
}
 
Example 13
Source File: Mvp4gRunAsyncGenerator.java    From mvp4g with Apache License 2.0 4 votes vote down vote up
private RebindResult create(JClassType originalType,
                            TreeLogger logger,
                            GeneratorContext context,
                            String typeName)
  throws UnableToCompleteException {

  Date start = new Date();

  String packageName = originalType.getPackage()
                                   .getName();
  String originalClassName           = originalType.getSimpleSourceName();
  String generatedClassName          = originalClassName + "Impl";
  String generatedClassQualifiedName = packageName + "." + generatedClassName;

  // check weather there is a usual version or not.
  if (checkAlreadyGenerated(logger,
                            context,
                            generatedClassQualifiedName)) {
    // Log
    logger.log(TreeLogger.INFO,
               "reuse already generated files",
               null);
    // stop generating
    return new RebindResult(RebindMode.USE_EXISTING,
                            generatedClassQualifiedName);
  }

  logger.log(TreeLogger.INFO,
             "Generating writer for " + packageName + "." + generatedClassName,
             null);

  PrintWriter printWriter = context.tryCreate(logger,
                                              packageName,
                                              generatedClassName);

  ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName,
                                                                                   generatedClassName);

  classFactory.addImplementedInterface(originalType.getName());
  String[] classesToImport = getClassesToImport();
  for (String classToImport : classesToImport) {
    classFactory.addImport(classToImport);
  }

  if (printWriter != null) {
    SourceWriter sourceWriter = classFactory.createSourceWriter(context,
                                                                printWriter);
    logger.log(TreeLogger.INFO,
               "Generating source for " + generatedClassQualifiedName + " ",
               null);
    writeClass(sourceWriter,
               getRunAsync(originalType));
    sourceWriter.commit(logger);
  }

  Date end = new Date();

  logger.log(TreeLogger.INFO,
             "Mvp4g Module Cretor: " + (end.getTime() - start.getTime()) + "ms.");

  return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING,
                          generatedClassQualifiedName);
}
 
Example 14
Source File: JsonAutoBeanGenerator.java    From requestor with Apache License 2.0 4 votes vote down vote up
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx, JClassType intfType) {
    JPackage serviceIntfPkg = intfType.getPackage();
    String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName();
    PrintWriter printWriter = ctx.tryCreate(logger, packageName, getTypeSimpleName());
    if (printWriter == null) {
        return null;
    }

    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, getTypeSimpleName());

    String[] imports = new String[]{
            // java.util
            ArrayList.class.getCanonicalName(),
            Collection.class.getCanonicalName(),
            List.class.getCanonicalName(),
            Iterator.class.getCanonicalName(),
            Set.class.getCanonicalName(),
            // com.google.gwt.core.client
            GWT.class.getCanonicalName(),
            // com.google.web.bindery.autobean.shared
            AutoBean.class.getCanonicalName(),
            AutoBeanCodex.class.getCanonicalName(),
            AutoBeanFactory.class.getCanonicalName(),
            AutoBeanUtils.class.getCanonicalName(),
            // io.reinert.requestor.serialization
            DeserializationContext.class.getCanonicalName(),
            Deserializer.class.getCanonicalName(),
            HasImpl.class.getCanonicalName(),
            Serdes.class.getCanonicalName(),
            Serializer.class.getCanonicalName(),
            SerializationContext.class.getCanonicalName(),
            UnableToDeserializeException.class.getName(),
            UnableToSerializeException.class.getName(),
            // io.reinert.requestor.serialization.json
            JsonObjectSerdes.class.getCanonicalName(),
            JsonRecordReader.class.getCanonicalName(),
            JsonRecordWriter.class.getCanonicalName(),
    };

    for (String imp : imports) {
        composerFactory.addImport(imp);
    }

    composerFactory.addImplementedInterface(intfType.getErasedType().getQualifiedSourceName());

    return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example 15
Source File: JsonGwtJacksonGenerator.java    From requestor with Apache License 2.0 4 votes vote down vote up
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx, JClassType intfType) {
    JPackage serviceIntfPkg = intfType.getPackage();
    String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName();
    PrintWriter printWriter = ctx.tryCreate(logger, packageName, getTypeSimpleName());
    if (printWriter == null) {
        return null;
    }

    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, getTypeSimpleName());

    String[] imports = new String[]{
            // java
            ArrayList.class.getCanonicalName(),
            Collection.class.getCanonicalName(),
            HashSet.class.getCanonicalName(),
            Iterator.class.getCanonicalName(),
            LinkedHashSet.class.getCanonicalName(),
            LinkedList.class.getCanonicalName(),
            List.class.getCanonicalName(),
            Set.class.getCanonicalName(),
            TreeSet.class.getCanonicalName(),
            // com.github.nmorel.gwtjackson
            ObjectMapper.class.getCanonicalName(),
            ObjectReader.class.getCanonicalName(),
            ObjectWriter.class.getCanonicalName(),
            // com.google.gwt
            GWT.class.getCanonicalName(),
            // io.reinert.requestor
            DeserializationContext.class.getCanonicalName(),
            Deserializer.class.getCanonicalName(),
            JsonObjectSerdes.class.getCanonicalName(),
            JsonRecordReader.class.getCanonicalName(),
            JsonRecordWriter.class.getCanonicalName(),
            UnableToDeserializeException.class.getName(),
            UnableToSerializeException.class.getName(),
            Serdes.class.getCanonicalName(),
            Serializer.class.getCanonicalName(),
            SerializationContext.class.getCanonicalName()
    };

    for (String imp : imports) {
        composerFactory.addImport(imp);
    }

    composerFactory.addImplementedInterface(intfType.getErasedType().getQualifiedSourceName());

    return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example 16
Source File: ApplicationMetaDataGenerator.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Generate source code for new class. Class extends
 * <code>HashMap</code>.
 *
 * @param logger  Logger object
 * @param context Generator context
 */
private void generateClass(TreeLogger logger, GeneratorContext context)
{

    // get print writer that receives the source code
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) return;

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, className);

    // Imports
    composerFactory.addImport("org.jboss.as.console.client.Console");
    composerFactory.addImport("org.jboss.as.console.client.widgets.forms.*");
    composerFactory.addImport("java.util.*");

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

    // 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);
}