Search in sources :

Example 6 with ClassSourceFileComposerFactory

use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project GwtMobile by dennisjzh.

the class GenUtils method generateClass.

public String generateClass(String requestedTypeName, String gennedTypeNameSuffix, ClassGenerator classGenerator) {
    // The package the class is going to be in.
    String packageName = getPackageName(requestedTypeName);
    String gennedTypeName = getClassName(requestedTypeName) + gennedTypeNameSuffix;
    PrintWriter pw = context.tryCreate(logger, packageName, gennedTypeName);
    // No PrintWriter means we've generated the same code before.
    if (pw != null) {
        factory = new ClassSourceFileComposerFactory(packageName, gennedTypeName);
        classGenerator.classSetup();
        sw = factory.createSourceWriter(context, pw);
        classGenerator.generateClass();
        sw.commit(logger);
    }
    return packageName + "." + gennedTypeName;
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) PrintWriter(java.io.PrintWriter)

Example 7 with ClassSourceFileComposerFactory

use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project che by eclipse.

the class ExtensionRegistryGenerator method generateClass.

/**
     * Generate the content of the class
     *
     * @param logger
     * @param context
     * @param packageName
     * @param className
     * @param extensions
     * @throws UnableToCompleteException
     */
private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className, List<JClassType> extensions) throws UnableToCompleteException {
    PrintWriter pw = context.tryCreate(logger, packageName, className);
    if (pw == null) {
        return;
    }
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);
    // generate imports
    generateImports(extensions, composerFactory);
    // interface
    composerFactory.addImplementedInterface(ExtensionRegistry.class.getCanonicalName());
    // get source writer
    SourceWriter sw = composerFactory.createSourceWriter(context, pw);
    // begin class definition
    // fields
    sw.println("private final Map<String, ExtensionDescription> extensions = new HashMap<>();");
    generateConstructor(className, extensions, sw);
    // methods
    generateGetExtensionsMethod(sw);
    // close it out
    sw.outdent();
    sw.println("}");
    context.commit(logger, pw);
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter) ExtensionRegistry(org.eclipse.che.ide.api.extension.ExtensionRegistry)

Example 8 with ClassSourceFileComposerFactory

use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project gwt-test-utils by gwt-test-utils.

the class MyGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    String packageName = "com.slazzer";
    String className = "MyGeneratedClass";
    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, className);
    PrintWriter pw = context.tryCreate(logger, packageName, className);
    if (pw != null) {
        factory.addImplementedInterface(IGenerateWith.class.getCanonicalName());
        factory.addImport(GWT.class.getCanonicalName());
        factory.addImport(JavaScriptObject.class.getCanonicalName());
        factory.addImport(HashMap.class.getCanonicalName());
        SourceWriter writer = factory.createSourceWriter(context, pw);
        writer.println("public String getMessage() {");
        writer.println("   return \"generated with MyGenerator class\";");
        writer.println("}");
        writer.commit(logger);
    }
    return factory.getCreatedClassName();
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) GWT(com.google.gwt.core.client.GWT) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 9 with ClassSourceFileComposerFactory

use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project libgdx by libgdx.

the class PreloaderBundleGenerator method createDummyClass.

private String createDummyClass(TreeLogger logger, GeneratorContext context) {
    String packageName = "com.badlogic.gdx.backends.gwt.preloader";
    String className = "PreloaderBundleImpl";
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImplementedInterface(packageName + ".PreloaderBundle");
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);
    if (printWriter == null) {
        return packageName + "." + className;
    }
    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);
    sourceWriter.commit(logger);
    return packageName + "." + className;
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 10 with ClassSourceFileComposerFactory

use of com.google.gwt.user.rebind.ClassSourceFileComposerFactory in project gwtphonegap by dankurka.

the class PhoneGapLogValueGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    int value = 100;
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
        } else {
            String stringValue = values.get(0);
            try {
                value = Integer.parseInt(stringValue);
            } catch (Exception e) {
                logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
            }
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
    }
    JClassType classType = null;
    try {
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }
    String packageName = classType.getPackage().getName();
    String simpleName = classType.getSimpleSourceName() + "_" + value;
    String fullName = packageName + "." + simpleName;
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.addImplementedInterface(typeName);
    composer.addImport(typeName);
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return fullName;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.println("public int getMaxEntries() {");
    writer.println("return " + value + ";");
    writer.println("}");
    writer.commit(logger);
    return fullName;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Aggregations

ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)13 PrintWriter (java.io.PrintWriter)13 SourceWriter (com.google.gwt.user.rebind.SourceWriter)11 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)4 GWT (com.google.gwt.core.client.GWT)3 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)3 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)3 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 BadPropertyValueException (com.google.gwt.core.ext.BadPropertyValueException)1 ConfigurationProperty (com.google.gwt.core.ext.ConfigurationProperty)1 PropertyOracle (com.google.gwt.core.ext.PropertyOracle)1 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)1 Resource (com.google.gwt.dev.resource.Resource)1 ClientBundleWithLookup (com.google.gwt.resources.client.ClientBundleWithLookup)1 DataResource (com.google.gwt.resources.client.DataResource)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 ResourcePrototype (com.google.gwt.resources.client.ResourcePrototype)1 TextResource (com.google.gwt.resources.client.TextResource)1 File (java.io.File)1