Search in sources :

Example 1 with SourceWriter

use of com.google.gwt.user.rebind.SourceWriter in project rstudio by rstudio.

the class MenuEmitter method generate.

public String generate() throws UnableToCompleteException {
    String className = bundleType_.getSimpleSourceName() + "__Menu_" + menuId_;
    PrintWriter printWriter = context_.tryCreate(logger_, packageName_, className);
    if (printWriter == null)
        return null;
    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName_, className);
    factory.addImport("org.rstudio.core.client.Debug");
    factory.addImport("org.rstudio.core.client.command.MenuCallback");
    SourceWriter writer = factory.createSourceWriter(context_, printWriter);
    emitFields(writer);
    emitConstructor(writer, className);
    emitMethod(writer);
    writer.outdent();
    writer.println("}");
    context_.commit(logger_, printWriter);
    return packageName_ + "." + className;
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 2 with SourceWriter

use of com.google.gwt.user.rebind.SourceWriter in project rstudio by rstudio.

the class JavaScriptSerializerGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    List<JClassType> classes = new ArrayList<JClassType>();
    // locate all the types annotated with JavaScriptSerializable
    for (JClassType classType : oracle.getTypes()) {
        if (isAnnotatedSerializable(classType))
            classes.add(classType);
    }
    ClassSourceFileComposerFactory sourceFile = new ClassSourceFileComposerFactory(genPackageName, genClassName);
    sourceFile.addImplementedInterface(JavaScriptSerializer.class.getCanonicalName());
    sourceFile.addImport("com.google.gwt.core.client.JavaScriptObject");
    sourceFile.addImport("org.rstudio.core.client.js.JsObject;");
    PrintWriter printWriter = context.tryCreate(logger, genPackageName, genClassName);
    if (printWriter != null) {
        SourceWriter sourceWriter = sourceFile.createSourceWriter(context, printWriter);
        sourceWriter.println(genClassName + "() {");
        sourceWriter.println("}");
        printSerializers(classes, sourceWriter);
        printDeserializers(classes, sourceWriter);
        sourceWriter.commit(logger);
    }
    return sourceFile.getCreatedClassName();
}
Also used : JavaScriptSerializer(org.rstudio.core.client.js.JavaScriptSerializer) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) ArrayList(java.util.ArrayList) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 3 with SourceWriter

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

the class ReflectionCacheSourceCreator method createProxy.

private void createProxy(JClassType type) {
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(type.getPackage().getName(), type.getSimpleSourceName() + "Proxy");
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.commit(logger);
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 4 with SourceWriter

use of com.google.gwt.user.rebind.SourceWriter in project gerrit by GerritCodeReview.

the class PluginGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();
    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);
    // Ensure that the requested type exists
    if (sourceType == null) {
        logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
        throw new UnableToCompleteException();
    }
    // Make sure the Gadget type is correctly defined
    validateType(logger, sourceType);
    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "PluginImpl";
    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(), generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.setSuperclass(typeName);
    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);
    // If an implementation already exists, we don't need to do any work
    if (out != null) {
        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);
        sw.commit(logger);
    }
    return f.getCreatedClassName();
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) GWT(com.google.gwt.core.client.GWT) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 5 with SourceWriter

use of com.google.gwt.user.rebind.SourceWriter 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

SourceWriter (com.google.gwt.user.rebind.SourceWriter)12 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)11 PrintWriter (java.io.PrintWriter)11 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)4 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)4 GWT (com.google.gwt.core.client.GWT)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 StringSourceWriter (com.google.gwt.user.rebind.StringSourceWriter)1