Search in sources :

Example 1 with RebindResult

use of com.google.gwt.core.ext.RebindResult in project mvp4g by mvp4g.

the class Mvp4gGenerator method create.

private RebindResult create(TreeLogger logger, GeneratorContext context, String moduleName) throws UnableToCompleteException {
    Date start = new Date();
    String generatedClassQualifiedName;
    try {
        TypeOracle typeOracle = context.getTypeOracle();
        JClassType module = typeOracle.findType(moduleName);
        if (module == null) {
            logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + moduleName + "'", null);
            throw new UnableToCompleteException();
        }
        @SuppressWarnings("unchecked") Map<Class<? extends Annotation>, List<JClassType>> scanResult = AnnotationScanner.scan(logger, typeOracle, new Class[] { Presenter.class, History.class, Events.class, Service.class, EventHandler.class });
        Mvp4gConfiguration configuration = new Mvp4gConfiguration(logger, context);
        String suffix = "Impl" + configuration.load(module, scanResult);
        generatedClassQualifiedName = module.getParameterizedQualifiedSourceName() + suffix;
        String packageName = module.getPackage().getName();
        String originalClassName = module.getSimpleSourceName();
        String generatedClassName = originalClassName + suffix;
        // check weather there is a usual version or not.
        if (checkAlreadyGenerated(logger, context, configuration)) {
            // Log
            logger.log(TreeLogger.INFO, "Reuse already generated files", null);
            // stop generating
            return new RebindResult(RebindMode.USE_EXISTING, packageName + "." + generatedClassName);
        }
        // Log
        logger.log(TreeLogger.INFO, "Start generate files ... ", null);
        // No, there is non. Create a new one.
        SourceWriter sourceWriter = getSourceWriter(logger, context, module, packageName, generatedClassName);
        if (sourceWriter != null) {
            logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null);
            Mvp4gConfigurationFileWriter writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration);
            writer.writeConf();
            sourceWriter.commit(logger);
        } else {
            // don't expect this to occur, but could happen if an instance was
            // recently generated but not yet committed
            new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName);
        }
        Date end = new Date();
        logger.log(TreeLogger.INFO, "Mvp4g Compilation: " + (end.getTime() - start.getTime()) + "ms.");
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + generatedClassName);
    } catch (InvalidMvp4gConfigurationException e) {
        logger.log(TreeLogger.ERROR, e.getMessage(), e);
        throw new UnableToCompleteException();
    }
}
Also used : Mvp4gConfiguration(com.mvp4g.rebind.config.Mvp4gConfiguration) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) Date(java.util.Date) Annotation(java.lang.annotation.Annotation) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) List(java.util.List) RebindResult(com.google.gwt.core.ext.RebindResult)

Example 2 with RebindResult

use of com.google.gwt.core.ext.RebindResult in project mvp4g by mvp4g.

the class Mvp4gRunAsyncGenerator method create.

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);
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) SourceWriter(com.google.gwt.user.rebind.SourceWriter) Date(java.util.Date) RebindResult(com.google.gwt.core.ext.RebindResult) PrintWriter(java.io.PrintWriter)

Aggregations

RebindResult (com.google.gwt.core.ext.RebindResult)2 SourceWriter (com.google.gwt.user.rebind.SourceWriter)2 Date (java.util.Date)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)1 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)1 Mvp4gConfiguration (com.mvp4g.rebind.config.Mvp4gConfiguration)1 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)1 PrintWriter (java.io.PrintWriter)1 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1