Search in sources :

Example 1 with TypeOracle

use of com.google.gwt.core.ext.typeinfo.TypeOracle 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 2 with TypeOracle

use of com.google.gwt.core.ext.typeinfo.TypeOracle in project libgdx by libgdx.

the class ReflectionCacheGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    TypeOracle oracle = context.getTypeOracle();
    assert (oracle != null);
    JClassType type = oracle.findType(typeName);
    if (type == null) {
        logger.log(ERROR, "Couldn't find type '" + typeName + "'");
        throw new UnableToCompleteException();
    }
    if (type.isInterface() == null) {
        logger.log(ERROR, "Type '" + typeName + "' must be an interface");
        throw new UnableToCompleteException();
    }
    ReflectionCacheSourceCreator source = new ReflectionCacheSourceCreator(logger, context, type);
    return source.create();
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException)

Example 3 with TypeOracle

use of com.google.gwt.core.ext.typeinfo.TypeOracle 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 4 with TypeOracle

use of com.google.gwt.core.ext.typeinfo.TypeOracle in project che by eclipse.

the class ExtensionRegistryGenerator method generate.

/** {@inheritDoc} */
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();
    JClassType extensionManager = typeOracle.findType(typeName);
    if (extensionManager == null) {
        logger.log(TreeLogger.ERROR, "Can't find interface type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }
    if (extensionManager.isInterface() == null) {
        logger.log(TreeLogger.ERROR, extensionManager.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    List<JClassType> extensions = new ArrayList<>();
    for (JClassType type : typeOracle.getTypes()) {
        if (type.isAnnotationPresent(Extension.class)) {
            extensions.add(type);
        }
    }
    String packageName = extensionManager.getPackage().getName();
    String className = extensionManager.getSimpleSourceName() + "Impl";
    generateClass(logger, context, packageName, className, extensions);
    return packageName + "." + className;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) ArrayList(java.util.ArrayList)

Example 5 with TypeOracle

use of com.google.gwt.core.ext.typeinfo.TypeOracle in project gwt-test-utils by gwt-test-utils.

the class GwtFactory method createOverlayRewriter.

private OverlayTypesRewriter createOverlayRewriter(CompilationState compilationState) {
    TypeOracle typeOracle = compilationState.getTypeOracle();
    JClassType jsoType = typeOracle.findType(JsValueGlue.JSO_CLASS);
    // If we couldn't find the JSO class, we don't need to do any rewrites.
    return jsoType != null ? new OverlayTypesRewriter(compilationState, jsoType) : null;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) OverlayTypesRewriter(com.googlecode.gwt.test.internal.rewrite.OverlayTypesRewriter)

Aggregations

JClassType (com.google.gwt.core.ext.typeinfo.JClassType)6 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)6 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)4 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)3 SourceWriter (com.google.gwt.user.rebind.SourceWriter)3 PrintWriter (java.io.PrintWriter)3 GWT (com.google.gwt.core.client.GWT)2 ArrayList (java.util.ArrayList)2 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)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 OverlayTypesRewriter (com.googlecode.gwt.test.internal.rewrite.OverlayTypesRewriter)1 File (java.io.File)1 HashSet (java.util.HashSet)1 JavaScriptSerializer (org.rstudio.core.client.js.JavaScriptSerializer)1