Example usage for com.google.gwt.dev.cfg ModuleDef getName

List of usage examples for com.google.gwt.dev.cfg ModuleDef getName

Introduction

In this page you can find the example usage for com.google.gwt.dev.cfg ModuleDef getName.

Prototype

public synchronized String getName() 

Source Link

Usage

From source file:gwt.ns.webworker.rebind.NativeWorkerFactoryGenerator.java

License:Apache License

@Override
public void generateWorkerFactory(TreeLogger logger, GeneratorContext context, JClassType sourceType,
        String genName, PrintWriter out, ModuleDef modDef, JClassType workerEntryType)
        throws UnableToCompleteException {

    // native worker, so request worker compilation
    WorkerRequestArtifact request = new WorkerRequestArtifact(modDef.getCanonicalName(), modDef.getName());
    context.commitArtifact(logger, request);

    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(),
            genName);//  ww w. j  a  v a2 s.c  om

    // imports and interface
    f.addImport(Worker.class.getName());
    f.addImport(WorkerImplNative.class.getName());
    f.addImplementedInterface(sourceType.getName());

    // new generated source file
    if (out != null) {
        SourceWriter sw = f.createSourceWriter(context, out);

        // @Override
        // public Worker createAndStart() {
        //   return WorkerImplNative.create("PLACEHOLDER_PATH"); }
        // Note: placeholder path will be replaced by linker
        sw.println("@Override");
        sw.println("public Worker createAndStart() {");
        sw.indent();
        sw.print("return WorkerImplNative.create(\"");
        sw.print(request.getRelativePlaceholderUrl());
        sw.println("\");");
        sw.outdent();
        sw.println("}");

        sw.commit(logger);
    }
}

From source file:org.jboss.errai.ioc.rebind.IOCGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    typeOracle = context.getTypeOracle();

    /**//from ww  w  .j  a v  a 2s  .c o  m
     * Try to determine the module package -- hackishly
     */
    //TODO: Find a more standard way to do this.
    try {
        if (context instanceof StandardGeneratorContext) {
            StandardGeneratorContext stdContext = (StandardGeneratorContext) context;
            Field field = StandardGeneratorContext.class.getDeclaredField("module");
            field.setAccessible(true);

            ModuleDef moduleDef = (ModuleDef) field.get(stdContext);

            String moduleName = moduleDef.getName();

            for (int i = 0; i < moduleName.length(); i++) {
                if (moduleName.charAt(i) == '.' && i < moduleName.length()
                        && Character.isUpperCase(moduleName.charAt(i + 1))) {
                    this.modulePackage = moduleName.substring(0, i);
                    break;
                }
            }

            logger.log(TreeLogger.INFO, "will scan in package: " + modulePackage);
        }
    } catch (Exception e) {
        // could not determine package.
    }

    try {
        // get classType and save instance variables

        JClassType classType = typeOracle.getType(typeName);
        packageName = classType.getPackage().getName();
        className = classType.getSimpleSourceName() + "Impl";

        logger.log(TreeLogger.INFO, "Generating Extensions Bootstrapper...");

        // Generate class source code
        generateIOCBootstrapClass(logger, context);
    } catch (Throwable e) {
        // record sendNowWith logger that Map generation threw an exception
        e.printStackTrace();
        logger.log(TreeLogger.ERROR, "Error generating extensions", e);
    }

    // return the fully qualified name of the class generated
    return packageName + "." + className;
}