Example usage for com.google.gwt.user.rebind ClassSourceFileComposerFactory makeInterface

List of usage examples for com.google.gwt.user.rebind ClassSourceFileComposerFactory makeInterface

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind ClassSourceFileComposerFactory makeInterface.

Prototype

public void makeInterface() 

Source Link

Document

This class is an interface.

Usage

From source file:com.guit.rebind.gin.GinInjectorGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    saveVariables(logger, context, typeName);
    if (typeOracle.findType(GinOracle.packageName, GinOracle.className) != null) {
        return new RebindResult(RebindMode.USE_EXISTING, GinOracle.packageName + "." + GinOracle.className);
    }//from  ww  w.ja v  a2 s .com

    // Clear
    injectedClasses.clear();
    providedClasses.clear();
    asyncProvidedClasses.clear();
    gmodules.clear();

    // Call gin contributors
    List<String> contributors = getConfigurationProperty("app.gin.contributor").getValues();
    for (String c : contributors) {
        GinContributor contributor = instantiateContributor(c);
        contributor.collaborate(this, logger, context);
    }

    // Generate the modules string
    StringBuilder sb = new StringBuilder();
    sb.append("({");
    for (Class<?> m : gmodules) {
        if (sb.length() > 2) {
            sb.append(", ");
        }
        sb.append(m.getCanonicalName() + ".class");
    }
    sb.append("})");

    GinOracle.setModules(gmodules);

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(GinOracle.packageName,
            GinOracle.className);
    composer.makeInterface();
    composer.addImplementedInterface(Ginjector.class.getCanonicalName());
    composer.addAnnotationDeclaration("@" + GinModules.class.getCanonicalName() + sb.toString());
    PrintWriter printWriter = context.tryCreate(logger, GinOracle.packageName, GinOracle.className);

    // Convert to linked to remove possible duplicated entries
    injectedClasses = findClassOrLinkedInjectionKey(injectedClasses);
    providedClasses = findClassOrLinkedInjectionKey(providedClasses);
    asyncProvidedClasses = findClassOrLinkedInjectionKey(asyncProvidedClasses);

    if (printWriter != null) {
        SourceWriter writer = composer.createSourceWriter(context, printWriter);

        writer.println(SINGLETON_DECLARATION);

        for (String classType : injectedClasses) {
            load(classType);
            writer.println(classType + " " + GinOracle.getGetterMethodName(classType) + "();");
        }

        for (String classType : providedClasses) {
            load(classType);
            writer.println(Provider.class.getCanonicalName() + "<" + classType + "> "
                    + GinOracle.getProviderGetterMethodName(classType) + "();");
        }

        for (String classType : asyncProvidedClasses) {
            load(classType);
            writer.println(AsyncProvider.class.getCanonicalName() + "<" + classType + "> "
                    + GinOracle.getAsyncProviderGetterMethodName(classType) + "();");
        }

        writer.commit(logger);
    }

    return new RebindResult(RebindMode.USE_PARTIAL_CACHED, GinOracle.packageName + "." + GinOracle.className);
}

From source file:com.gwtplatform.mvp.rebind.GinjectorGenerator.java

License:Apache License

private ClassSourceFileComposerFactory initComposer() throws UnableToCompleteException {
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(getPackageName(),
            getClassName());/*from w  w  w.j  a v  a 2 s  . co  m*/
    composer.addImport(Ginjector.class.getCanonicalName());
    composer.makeInterface();
    composer.addImplementedInterface(Ginjector.class.getSimpleName());

    addExtensionInterfaces(composer);

    return composer;
}

From source file:com.sencha.gxt.core.rebind.SafeHtmlTemplatesCreator.java

License:sencha.com license

@Override
protected void configureFactory(ClassSourceFileComposerFactory factory) throws UnableToCompleteException {
    super.configureFactory(factory);
    factory.addImport(Name.getSourceNameForClass(SafeHtml.class));
    factory.addImport(Name.getSourceNameForClass(Template.class));
    factory.makeInterface();
}

From source file:de.knightsoftnet.validators.rebind.BeanHelperCache.java

License:Apache License

/**
 * Write an Empty Interface implementing
 * {@link de.knightsoftnet.validators.client.impl.GwtSpecificValidator} with Generic parameter of
 * the bean type./*  w w w. jav a2s .  c om*/
 */
private void writeInterface(final GeneratorContext context, final TreeLogger logger, final BeanHelper bean) {
    final PrintWriter pw = context.tryCreate(logger, bean.getPackage(), bean.getValidatorName());
    if (pw != null) {
        final TreeLogger interfaceLogger = logger.branch(TreeLogger.TRACE,
                "Creating the interface for " + bean.getFullyQualifiedValidatorName());

        final ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(bean.getPackage(),
                bean.getValidatorName());
        factory.addImplementedInterface(
                GwtSpecificValidator.class.getCanonicalName() + " <" + bean.getTypeCanonicalName() + ">");
        factory.addImport(GWT.class.getCanonicalName());
        factory.makeInterface();
        final SourceWriter sw = factory.createSourceWriter(context, pw);

        // static MyValidator INSTANCE = GWT.create(MyValidator.class);
        sw.print("static ");
        sw.print(bean.getValidatorName());
        sw.print(" INSTANCE = GWT.create(");
        sw.print(bean.getValidatorName());
        sw.println(".class);");

        sw.commit(interfaceLogger);
        pw.close();
    }
}

From source file:net.sf.mmm.util.nls.impl.rebind.NlsBundleGeneratorGwtI18n.java

License:Apache License

/**
 * This method generates the GWT-i18n-interface for the NLS-bundle.
 *
 * @param bundleClass is the {@link JClassType class} of the {@link net.sf.mmm.util.nls.api.NlsBundle} to
 *        generate.//  w ww  .  j  a v a  2 s.  c om
 * @param logger is the {@link TreeLogger}.
 * @param context is the {@link GeneratorContext}.
 * @return the name of the generated class.
 */
@SuppressWarnings({ "rawtypes" })
private String generateBundleInterface(JClassType bundleClass, TreeLogger logger, GeneratorContext context) {

    Class bundleJavaClass;
    String bundleName = bundleClass.getQualifiedSourceName();
    try {
        bundleJavaClass = Class.forName(bundleName);
    } catch (ClassNotFoundException e) {
        throw new TypeNotFoundException(bundleName);
    }
    @SuppressWarnings("unchecked")
    ClassName bundleClassName = NlsBundleHelper.getInstance().getQualifiedLocation(bundleJavaClass);
    String packageName = bundleClassName.getPackageName();
    String simpleName = bundleClassName.getSimpleName();
    if (bundleClassName.getName().equals(bundleName)) {
        logger.log(TreeLogger.ERROR, getClass().getSimpleName() + ": Illegal NlsBundle '" + bundleName
                + "' - has to end with suffix 'Root'. Localization will not work!");
        simpleName = simpleName + "_Interface";
    }
    logger.log(TreeLogger.INFO, getClass().getSimpleName() + ": Generating " + simpleName);
    ClassSourceFileComposerFactory sourceComposerFactory = new ClassSourceFileComposerFactory(packageName,
            simpleName);
    sourceComposerFactory.makeInterface();
    // import statements
    sourceComposerFactory.addImport(Constants.class.getName());
    sourceComposerFactory.addImport(Generate.class.getCanonicalName());

    sourceComposerFactory.addImplementedInterface(Constants.class.getSimpleName());

    // @Generate annotation
    StringBuilder annotationBuffer = new StringBuilder();
    annotationBuffer.append("@");
    annotationBuffer.append(Generate.class.getSimpleName());
    annotationBuffer.append("(format = \"");
    annotationBuffer.append(PropertiesFormat.class.getName());
    annotationBuffer.append("\")");

    sourceComposerFactory.addAnnotationDeclaration(annotationBuffer.toString());

    PrintWriter writer = context.tryCreate(logger, packageName, simpleName);
    if (writer != null) {
        SourceWriter sourceWriter = sourceComposerFactory.createSourceWriter(context, writer);

        // generate methods for fields of bundle
        for (JMethod method : bundleClass.getOverridableMethods()) {
            JType returnType = method.getReturnType();
            if (!isLookupMethod(method)) {
                if (!NlsMessage.class.getName().equals(returnType.getQualifiedSourceName())) {
                    throw new IllegalCaseException(returnType.getQualifiedSourceName());
                }
                NlsBundleMessage messageAnnotation = method.getAnnotation(NlsBundleMessage.class);
                if (messageAnnotation != null) {
                    String message = messageAnnotation.value();
                    // generate message annotation
                    sourceWriter.print("@DefaultStringValue(\"");
                    sourceWriter.print(escape(message));
                    sourceWriter.println("\")");
                }

                NlsBundleKey keyAnnotation = method.getAnnotation(NlsBundleKey.class);
                if (keyAnnotation != null) {
                    // generate key annotation
                    sourceWriter.print("@Key(\"");
                    sourceWriter.print(escape(keyAnnotation.value()));
                    sourceWriter.println("\")");
                }
                // generate method
                sourceWriter.print("String ");
                sourceWriter.print(method.getName());
                sourceWriter.println("();");

                sourceWriter.println();
            }

        }
        sourceWriter.commit(logger);
    }
    return sourceComposerFactory.getCreatedClassName();
}

From source file:org.cruxframework.crux.core.rebind.screen.widget.ViewFactoryCreator.java

License:Apache License

/**
* Create a new printer for a subType. That subType will be declared on the package name informed in the first parameter
* if packageName isEmpty, subType will be declared on the same package of the { @code ViewFactory }.
*
* @param packageName//  w  ww.  j  a va  2 s .c  o m
 * @param subType
 * @param superClass
 * @param interfaces
 * @param imports
 * @param isInterface
 * @return
 */
protected SourcePrinter getSubTypeWriter(String packageName, String subType, String superClass,
        String[] interfaces, String[] imports, boolean isInterface) {
    if (StringUtils.isEmpty(packageName)) {
        packageName = ViewFactory.class.getPackage().getName();
    }
    PrintWriter printWriter = context.tryCreate(logger, packageName, subType);

    if (printWriter == null) {
        return null;
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, subType);
    if (isInterface) {
        composerFactory.makeInterface();
    }

    if (imports != null) {
        for (String imp : imports) {
            composerFactory.addImport(imp);
        }
    }

    if (superClass != null) {
        composerFactory.setSuperclass(superClass);
    }

    if (interfaces != null) {
        for (String intf : interfaces) {
            composerFactory.addImplementedInterface(intf);
        }
    }

    return new SourcePrinter(composerFactory.createSourceWriter(context, printWriter), logger);
}

From source file:org.fusesource.restygwt.rebind.DirectRestBaseSourceCreator.java

License:Apache License

protected ClassSourceFileComposerFactory createClassSourceComposerFactory(JavaSourceCategory createWhat,
        String[] annotationDeclarations, String[] extendedInterfaces) {
    String genericTypeParameters = createClassDeclarationGenericType();

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            shortName + genericTypeParameters);

    if (createWhat == JavaSourceCategory.INTERFACE) {
        composerFactory.makeInterface();
    }/*w  ww  .j a  va  2 s .  co m*/

    if (annotationDeclarations != null) {
        for (String annotationDeclaration : annotationDeclarations) {
            composerFactory.addAnnotationDeclaration(annotationDeclaration);
        }
    }

    if (extendedInterfaces != null) {
        for (String anInterface : extendedInterfaces) {
            composerFactory.addImplementedInterface(anInterface);
        }
    }

    return composerFactory;
}

From source file:org.jsonmaker.gwt.rebind.JsonizerWriter.java

License:Apache License

private String ensureJsonizer(JClassType beanClass) {
    String simpleName = RebindUtils.jsonizerSimpleName(beanClass);

    PrintWriter writer = ctx.tryCreate(logger, beanClass.getPackage().getName(), simpleName);
    if (writer != null) {
        ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(
                beanClass.getPackage().getName(), simpleName);

        composerFactory.makeInterface();

        composerFactory.addImplementedInterface(Constants.JSONIZER_INTERFACE);

        composerFactory.createSourceWriter(ctx, writer).commit(logger);
    }// w ww .j  a va  2s .  c  om

    return beanClass.getPackage().getName() + "." + simpleName;

}

From source file:org.rstudio.core.rebind.command.CommandBundleGenerator.java

License:Open Source License

private ImageResourceInfo generateImageBundle() {
    String className = bundleType_.getSimpleSourceName() + "__AutoGenResources";
    String pathToInstance = packageName_ + "." + className + ".INSTANCE";
    ImageResourceInfo iri = new ImageResourceInfo(pathToInstance);

    PrintWriter printWriter = context_.tryCreate(logger_, packageName_, className);
    if (printWriter == null)
        return null;

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName_, className);
    factory.addImport("com.google.gwt.core.client.GWT");
    factory.addImport("com.google.gwt.resources.client.*");
    factory.makeInterface();
    factory.addImplementedInterface("ClientBundle");
    SourceWriter writer = factory.createSourceWriter(context_, printWriter);

    Set<String> resourceNames = context_.getResourcesOracle().getPathNames();
    for (JMethod method : commandMethods_) {
        String commandId = method.getName();

        String key = packageName_.replace('.', '/') + "/" + commandId + ".png";
        if (resourceNames.contains(key)) {
            writer.println("ImageResource " + commandId + "();");
            iri.addImage(commandId);// w w w .j a  v a 2s . c om
        }
    }
    writer.println("public static final " + className + " INSTANCE = " + "(" + className + ")GWT.create("
            + className + ".class);");

    writer.outdent();
    writer.println("}");
    context_.commit(logger_, printWriter);

    return iri;

}

From source file:rocket.generator.rebind.type.NewConcreteOrInterfaceType.java

License:Apache License

/**
 * Requests this generated type to write out its definition including its
 * constructors, methods and fields. This operation may only be attempted
 * once./*from w w w . ja v a2s  .  c om*/
 * 
 * @param printWriter
 *            The printwriter returned by
 *            context.tryCreateTypePrintWriter(packageName,
 *            simpleClassName);
 */
public void write() {
    final String packageName = this.getPackage().getName();
    final String simpleClassName = this.getSimpleName();

    final ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            simpleClassName);
    if (this.isInterface()) {
        composerFactory.makeInterface();
    }

    this.setSuperClassUponClassSourceFileComposerFactory(composerFactory);
    this.addImplementedInterfacesToClassSourceFileComposerFactory(composerFactory);
    this.setClassJavaDoc(composerFactory);

    final TypeOracleGeneratorContext context = (TypeOracleGeneratorContext) this.getGeneratorContext();
    final PrintWriter printWriter = this.getPrintWriter();
    final SourceWriter writer = context.createSourceWriter(composerFactory, printWriter);

    try {
        context.branch();
        this.log();

        this.writeInitializers(writer);
        this.writeConstructors(writer);
        this.writeFields(writer);
        this.writeMethods(writer);
        this.writeNestedTypes(writer);
        context.unbranch();

    } catch (final GeneratorException caught) {
        this.handleWriteFailure(writer, caught);

        throw caught;
    } finally {
        writer.commit();
    }
}