Example usage for com.google.gwt.user.rebind SourceWriter commit

List of usage examples for com.google.gwt.user.rebind SourceWriter commit

Introduction

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

Prototype

void commit(TreeLogger logger);

Source Link

Usage

From source file:org.cruxframework.crux.plugin.gadget.rebind.gwt.UserPreferencesGenerator.java

License:Apache License

@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();
    }/*w ww.  ja v  a  2s.c o  m*/

    // Make sure the UserPreferences type is correctly defined
    validateType(logger, sourceType);

    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "UserPreferencesImpl";

    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(),
            generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.addImport(PreferencesUtil.class.getName());
    f.addImplementedInterface(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) {
        JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace('$', '.'));
        assert preferenceType != null;

        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);

        for (JMethod m : sourceType.getOverridableMethods()) {
            JClassType extendsPreferenceType = m.getReturnType().isClassOrInterface();
            if (extendsPreferenceType == null) {
                logger.log(TreeLogger.ERROR,
                        "Return type of " + m.getName() + " is not a class or interface (must be assignable to "
                                + preferenceType.getName() + ").",
                        null);
                throw new UnableToCompleteException();
            }

            if (!preferenceType.isAssignableFrom(extendsPreferenceType)) {
                logger.log(TreeLogger.ERROR, "Cannot assign " + extendsPreferenceType.getQualifiedSourceName()
                        + " to " + preferenceType.getQualifiedSourceName(), null);
                throw new UnableToCompleteException();
            }

            // private final FooProperty __propName = new FooProperty()
            // {...}
            sw.print("private final " + extendsPreferenceType.getParameterizedQualifiedSourceName() + " __"
                    + m.getName() + " = ");
            writeInstantiation(logger, sw, extendsPreferenceType, m);
            sw.println(";");

            // public FooProperty property() { return __property; }
            sw.print("public ");
            sw.print(m.getReadableDeclaration(true, true, true, true, true));
            sw.println("{");
            sw.indent();
            sw.println("return __" + m.getName() + ";");
            sw.outdent();
            sw.println("}");
        }

        sw.commit(logger);
    }

    return f.getCreatedClassName();
}

From source file:org.cruxframework.crux.plugin.gadget.rebind.rpc.CruxGadgetProxyCreator.java

License:Apache License

/**
 * @param logger/*www .  ja  va  2  s. c  o m*/
 * @param context
 * @param cruxServiceTypeName
 * @return
 * @throws UnableToCompleteException 
 */
private RebindResult createGadgetWrapper(GeneratorContext context, String cruxServiceTypeName)
        throws UnableToCompleteException {
    SourceWriter srcWriter = getSourceWriter(logger, context, cruxServiceTypeName);

    String gadgetWrapperName = getGadgetProxyQualifiedName();
    if (srcWriter == null) {
        return new RebindResult(RebindMode.USE_EXISTING, gadgetWrapperName);
    }

    generateGadgetProxyContructor(srcWriter);

    srcWriter.commit(logger);

    return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, gadgetWrapperName);
}

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

public String generate(TreeLogger logger, GeneratorContext context, String requestedClass)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType objectType = typeOracle.findType(requestedClass);
    if (objectType == null) {
        logger.log(TreeLogger.ERROR, "Could not find type: " + requestedClass);
        throw new UnableToCompleteException();
    }//from   ww w  . ja  v a  2s  .  c om

    String implTypeName = objectType.getSimpleSourceName() + "Impl";
    String implPackageName = objectType.getPackage().getName();

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(implPackageName,
            implTypeName);

    composerFactory.addImport(Map.class.getCanonicalName());
    composerFactory.addImport(List.class.getCanonicalName());
    composerFactory.addImport(Constants.class.getCanonicalName());
    composerFactory.addImport(Images.class.getCanonicalName());
    composerFactory.addImport(ImageResource.class.getCanonicalName());
    composerFactory.addImport(Asset.class.getCanonicalName());
    composerFactory.addImport(RuleViewer.class.getCanonicalName());
    composerFactory.addImport(DefaultContentUploadEditor.class.getCanonicalName());
    composerFactory.addImport(Widget.class.getCanonicalName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    composerFactory.addImport(ClientFactory.class.getCanonicalName());
    composerFactory.addImport(EventBus.class.getCanonicalName());
    composerFactory.addImplementedInterface(objectType.getQualifiedSourceName());

    PrintWriter printWriter = context.tryCreate(logger, implPackageName, implTypeName);
    if (printWriter != null) {
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        List<AssetEditorConfiguration> registeredEditors = loadAssetEditorMetaData();
        generateAttributes(sourceWriter);
        generateGetRegisteredAssetEditorFormatsMethod(sourceWriter, registeredEditors);
        generateGetAssetEditorMethod(sourceWriter, registeredEditors);
        generateGetAssetEditorIcon(sourceWriter, registeredEditors);
        generateGetAssetEditorTitle(sourceWriter, registeredEditors);
        sourceWriter.commit(logger);
    }
    return implPackageName + "." + implTypeName;
}

From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java

License:Apache License

public String generate(TreeLogger logger, GeneratorContext context, String requestedClass)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType objectType = typeOracle.findType(requestedClass);
    if (objectType == null) {
        logger.log(TreeLogger.ERROR, "Could not find type: " + requestedClass);
        throw new UnableToCompleteException();
    }/*from  w  w  w .j  a  v a  2s. c o m*/

    String implTypeName = objectType.getSimpleSourceName() + "Impl";
    String implPackageName = objectType.getPackage().getName();

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(implPackageName,
            implTypeName);

    composerFactory.addImport(Map.class.getCanonicalName());
    composerFactory.addImport(List.class.getCanonicalName());
    composerFactory.addImport(Constants.class.getCanonicalName());
    composerFactory.addImport(Images.class.getCanonicalName());
    composerFactory.addImport(ImageResource.class.getCanonicalName());
    composerFactory.addImport(Asset.class.getCanonicalName());
    composerFactory.addImport(RuleViewer.class.getCanonicalName());
    composerFactory.addImport(DefaultContentUploadEditor.class.getCanonicalName());
    composerFactory.addImport(Widget.class.getCanonicalName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    composerFactory.addImport(ClientFactory.class.getCanonicalName());
    composerFactory.addImport(EventBus.class.getCanonicalName());
    composerFactory.addImport(Module.class.getCanonicalName());
    composerFactory.addImport(Command.class.getCanonicalName());
    composerFactory.addImport(AbstractModuleEditor.class.getCanonicalName());
    composerFactory.addImport(StackItemHeaderViewImpl.class.getCanonicalName());
    composerFactory.addImport(StackItemHeader.class.getCanonicalName());
    composerFactory.addImport(Util.class.getCanonicalName());
    composerFactory.addImport(SafeHtml.class.getCanonicalName());
    composerFactory.addImport(IsWidget.class.getCanonicalName());
    composerFactory.addImplementedInterface(objectType.getQualifiedSourceName());

    PrintWriter printWriter = context.tryCreate(logger, implPackageName, implTypeName);
    if (printWriter != null) {
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        Map<String, List<ModuleEditorConfiguration>> registeredEditors = loadModuleEditorMetaData();
        generateAttributes(sourceWriter);
        generateGetRegisteredAssetEditorFormatsMethod(sourceWriter, registeredEditors);
        generateGetRegisteredModuleEditorFormatsMethod(sourceWriter, registeredEditors);
        generateGetRegisteredPerspectiveTypesMethod(sourceWriter, registeredEditors);
        generateGetModuleEditorMethod(sourceWriter, registeredEditors);
        generateGetPerspectiveMethod(sourceWriter, registeredEditors);

        generateGetModulesHeaderViewMethod(sourceWriter, registeredEditors);
        generateGetModulesTreeRootNodeHeaderMethod(sourceWriter, registeredEditors);
        generateGetModulesNewAssetMenuMethod(sourceWriter, registeredEditors);
        generateGetModuleEditorActionToolbarMethod(sourceWriter, registeredEditors);
        generateGetAssetEditorActionToolbarMethod(sourceWriter, registeredEditors);

        sourceWriter.commit(logger);
    }
    return implPackageName + "." + implTypeName;
}

From source file:org.gwt.beansbinding.core.rebind.BeanPropertyDescriptorGenerator.java

License:Apache License

public String doGenerate(String typeName, JClassType[] types) throws NotFoundException {
    TypeOracle typeOracle = context.getTypeOracle();
    JClassType type = typeOracle.getType(typeName);
    String packageName = type.getPackage().getName();
    String simpleClassName = type.getSimpleSourceName();
    String className = simpleClassName + "Introspector";
    String qualifiedBeanClassName = packageName + "." + className;
    SourceWriter sourceWriter = getSourceWriter(packageName, className, type);
    if (sourceWriter == null) {
        return qualifiedBeanClassName;
    }/* ww w  . ja v a 2  s . com*/
    write(sourceWriter, type, types);
    sourceWriter.commit(logger);
    return qualifiedBeanClassName;
}

From source file:org.gwt.json.serialization.SerializerGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {

    Map<String, String> serializers = new HashMap<String, String>();
    List<JClassType> genericSerializableTypes = new LinkedList<JClassType>();
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType[] allTypes = typeOracle.getTypes();
    for (JClassType jClassType : allTypes) {

        Serializable annotation = jClassType.getAnnotation(Serializable.class);
        if (annotation != null && !jClassType.isAbstract()) {
            //Ok, this one is a candidate for serializer generation
            if (annotation.customSerializer().length() > 0) {
                JClassType customSerializer = typeOracle.findType(annotation.customSerializer());
                if (customSerializer != null) { //generated serializer not required, use specified custom instead
                    serializers.put(jClassType.getQualifiedSourceName(),
                            customSerializer.getQualifiedSourceName());
                } else {
                    genericSerializableTypes.add(jClassType);
                }//from w w  w.  ja va  2  s . c  o  m
            } else {
                genericSerializableTypes.add(jClassType);
            }
        }
    }

    //add default built-in serializers (Collections & primitives)
    //Collection.class.getName()
    //List.class.getName()
    //ArrayList.class.getName()
    //HashSet.class.getName()
    //Date.class.getName()
    //HashMap.class.getName()
    //Map.class.getName()
    //String, Boolean, Integer, Long, Float, Double, Character

    //context.getPropertyOracle().getConfigurationProperty()
    try {
        //primitives
        serializers.put(Float.class.getName(), JsonFloatSerializer.class.getName());
        serializers.put(Double.class.getName(), JsonDoubleSerializer.class.getName());
        serializers.put(Integer.class.getName(), JsonIntegerSerializer.class.getName());
        serializers.put(Long.class.getName(), JsonLongSerializer.class.getName());
        serializers.put(Character.class.getName(), JsonCharacterSerializer.class.getName());
        serializers.put(Boolean.class.getName(), JsonBooleanSerializer.class.getName());
        //common objects
        serializers.put(String.class.getName(), JsonStringSerializer.class.getName());
        serializers.put(Date.class.getName(), JsonDateSerializer.class.getName());

        //collections
        //Collection, List (Linked-, Array-), Set (Hash-, Tree-, LinkedHash-) --> JSONArray
        //Collection, List --> ArrayList, Set -> HashSet
        serializers.put(Collection.class.getName(), JsonCollectionSerializer.class.getName());

        serializers.put(List.class.getName(), JsonListSerializer.class.getName());
        serializers.put(ArrayList.class.getName(), JsonArrayListSerializer.class.getName());
        serializers.put(LinkedList.class.getName(), JsonLinkedListSerializer.class.getName());

        serializers.put(Set.class.getName(), JsonSetSerializer.class.getName());
        serializers.put(HashSet.class.getName(), JsonHashSetSerializer.class.getName());
        serializers.put(TreeSet.class.getName(), JsonTreeSetSerializer.class.getName());
        serializers.put(LinkedHashSet.class.getName(), JsonLinkedHashSetSerializer.class.getName());

        serializers.put(Map.class.getName(), JsonMapSerializer.class.getName());
        serializers.put(HashMap.class.getName(), JsonHashMapSerializer.class.getName());
        serializers.put(TreeMap.class.getName(), JsonTreeMapSerializer.class.getName());

        JClassType classType = context.getTypeOracle().getType(typeName);
        String simpleName = classType.getSimpleSourceName() + "_Generated";

        SourceWriter sourceWriter = getSourceWriter(classType, simpleName, context, logger);
        jArrayTypes = new HashSet<>();
        generatedTypes = new HashSet<>();
        for (JClassType genericClassType : genericSerializableTypes) {
            serializers.put(genericClassType.getQualifiedSourceName(),
                    new InternalSerializerGenerator(genericClassType, jArrayTypes)
                            .generateSerializers(sourceWriter));
        }
        while (!generatedTypes.containsAll(jArrayTypes)) {
            Set<JArrayType> copyOfTypes = new HashSet<>(jArrayTypes);
            for (JArrayType arrayType : copyOfTypes) {
                if (!generatedTypes.contains(arrayType)) {
                    serializers.put(arrayType.getQualifiedSourceName(),
                            new InternalArraySerializerGenerator(arrayType, jArrayTypes)
                                    .generateSerializers(sourceWriter));
                    generatedTypes.add(arrayType);
                }
            }
        }
        generateRegisterConstructor(serializers, simpleName, sourceWriter, typeOracle);
        sourceWriter.commit(logger);
        String packageName = classType.getPackage().getName();
        return packageName + "." + simpleName;
    } catch (NotFoundException e) {
        logger.log(TreeLogger.Type.ERROR, e.toString());
        e.printStackTrace();
        throw new UnableToCompleteException();
    }
}

From source file:org.jrydberg.bindings.rebind.DataBindingGenerator.java

License:Apache License

public String generateRootClass(TreeLogger logger, GeneratorContext context, JClassType bindingType) {

    JClassType[] implementedInterfaces = bindingType.getImplementedInterfaces();
    if (implementedInterfaces.length != 1) {
        logger.log(TreeLogger.WARN,/*ww  w.  j  ava 2 s  . co m*/
                "Binding interface '" + bindingType.getName() + "' does not extend DataBinding<T>.");
        return null;
    }
    JClassType implementedInterface = implementedInterfaces[0];
    if (!implementedInterface.getErasedType().getQualifiedSourceName().equals(DATA_BINDING_CLASS_NAME)) {
        logger.log(TreeLogger.WARN,
                "Binding interface '" + bindingType.getName() + "' does not extend DataBinding<T>.");
        return null;
    }
    JParameterizedType isParameterized = implementedInterface.isParameterized();
    if (isParameterized == null) {
        logger.log(TreeLogger.WARN,
                "Binding interface '" + bindingType.getName() + "' does not parameterize DataBinding.");
        return null;
    }
    JClassType[] argTypes = isParameterized.getTypeArgs();
    if (argTypes.length != 1) {
        logger.log(TreeLogger.WARN, "Binding interface '" + bindingType.getName()
                + "' should have one parameter for DataBinding interface.");
        return null;
    }
    JClassType beanType = argTypes[0];

    String className = bindingType.getName() + "_ROOT";
    String qualClassName = bindingType.getPackage().getName() + "." + className;

    String superType = bindingType.getName() + "_IMPL<" + beanType.getName() + ">";

    PrintWriter printWriter = context.tryCreate(logger, bindingType.getPackage().getName(), className);
    if (printWriter == null) {
        return qualClassName;
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(
            bindingType.getPackage().getName(), className);
    composerFactory.setSuperclass(superType);
    composerFactory.addImplementedInterface(bindingType.getName());

    composerFactory.addImport(bindingType.getQualifiedSourceName());
    composerFactory.addImport(bindingType.getQualifiedSourceName() + "_IMPL");
    composerFactory.addImport(HasValue.class.getName());
    composerFactory.addImport("org.jrydberg.bindings.client.ValueBox");

    SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

    sourceWriter.println("public " + className + "() {");
    sourceWriter.println("  super(null);");
    sourceWriter.println("}");

    sourceWriter.println("@Override");
    sourceWriter.println("public void initWithValueBox(HasValue<" + beanType.getName() + "> valueBox) {");
    sourceWriter.println("  setSourceBox(valueBox);");
    sourceWriter.println("}\n");

    sourceWriter.println("@Override");
    sourceWriter.println("public void initWithValue(" + beanType.getName() + " value) {");
    sourceWriter.println("  setSourceBox(new ValueBox<" + beanType.getName() + ">(value));");
    sourceWriter.println("}");

    sourceWriter.println("@Override");
    sourceWriter.println("public " + beanType.getName() + " getValue() {");
    sourceWriter.println("  return getSource();");
    sourceWriter.println("}");

    sourceWriter.println("@Override");
    sourceWriter.println("public void setValue(" + beanType.getName() + " value) {");
    sourceWriter.println("  setSource(value);");
    sourceWriter.println("}");

    sourceWriter.commit(null);
    return qualClassName;
}

From source file:org.jrydberg.bindings.rebind.DataBindingGenerator.java

License:Apache License

public void generateImplClass(TreeLogger logger, GeneratorContext context, JClassType type,
        JClassType beanType) {/*from ww w  .  j a v a  2 s  .  c o  m*/
    String superType = "AbstractBinding<ST, " + beanType.getName() + ">";
    String className = type.getName() + "_IMPL";

    PrintWriter printWriter = context.tryCreate(logger, type.getPackage().getName(), className);
    if (printWriter == null) {
        return;
    }

    Set<Binding> bindings = findBindings(type);

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(
            type.getPackage().getName(), className + "<ST>");
    composerFactory.addImport("org.jrydberg.bindings.client.AbstractBinding");
    composerFactory.addImport("org.jrydberg.bindings.client.DataBinding");
    composerFactory.addImport("org.jrydberg.bindings.client.Property");
    composerFactory.addImport(type.getQualifiedSourceName());
    composerFactory.addImport(beanType.getQualifiedSourceName());
    composerFactory.addImport(HasValue.class.getName());
    for (Binding binding : bindings) {
        composerFactory.addImport(binding.type.getQualifiedSourceName());
        if (binding.nested) {
            composerFactory.addImport(binding.type.getQualifiedSourceName() + "_IMPL");
        }
    }

    composerFactory.setSuperclass(superType);
    composerFactory.addImplementedInterface(type.getName());

    SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

    sourceWriter.println("public " + className + "(HasValue<ST> sourceBox) {");
    sourceWriter.println("  super(sourceBox);");
    sourceWriter.println("}");

    for (Binding binding : bindings) {
        PropertyDescription propDescr = findPropertyDescription(beanType, binding.name);

        if (!binding.nested) {
            // This should return a Property<type>
            sourceWriter.println("@Override");
            sourceWriter.println("public Property<" + binding.type.getName() + "> " + binding.name + "() {");
            sourceWriter.indent();

            sourceWriter.println("return new AbstractBinding<" + beanType.getName() + ","
                    + binding.type.getName() + ">(this) {");
            sourceWriter.indent();

            sourceWriter.println("@Override");
            sourceWriter.println("public String getPropertyName() {");
            sourceWriter.println("  return \"" + binding.name + "\";");
            sourceWriter.println("}");
            writeProperty(sourceWriter, binding.type, beanType, propDescr);
            sourceWriter.outdent();
            sourceWriter.println("};");
            sourceWriter.outdent();
            sourceWriter.println("}");
        } else {
            // This should return a Property<type>
            sourceWriter.println("@Override");
            sourceWriter.println("public " + binding.type.getName() + " " + binding.name + "() {");
            sourceWriter.indent();
            sourceWriter.println(
                    "return new " + binding.type.getName() + "_IMPL<" + beanType.getName() + ">(this) {");
            sourceWriter.indent();
            writeProperty(sourceWriter, binding.parameterType, beanType, propDescr);

            stubBindingMethods(sourceWriter, binding.parameterType.getName());
            // FIXME: do we need to overwrite the root-methods?

            sourceWriter.outdent();
            sourceWriter.println("};");
            sourceWriter.outdent();
            sourceWriter.println("}");
        }

    }

    stubBindingMethods(sourceWriter, beanType.getName());

    sourceWriter.commit(null);
}

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

License:Apache License

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

    if (!typeName.endsWith(Constants.JSONIZER_SUFFIX)) {
        logger.log(TreeLogger.ERROR, "Jsonizer named must be suffixed with '" + Constants.JSONIZER_SUFFIX + "'",
                null);//from  ww  w  .j  a v  a  2  s  . co m
        throw new UnableToCompleteException();
    }

    JClassType converterClass;

    try {
        converterClass = typeOracle.getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "Doesn't exists a Jsonizer for '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }

    if (converterClass.isClass() != null) {
        if (converterClass.isAbstract()) {
            logger.log(TreeLogger.ERROR, "Jsonizer class '" + typeName + "' cant be abstract", null);
            throw new UnableToCompleteException();
        }
        return null;
    }

    String simpleBeanClassName = simpleBeanClassName(converterClass);

    String qualifiedBeanClassName = converterClass.getPackage().getName() + "." + simpleBeanClassName;
    //  logger.log(TreeLogger.INFO, "buscando el bean '" + qualifiedBeanClassName + "'", null);

    JClassType beanClass = context.getTypeOracle().findType(qualifiedBeanClassName);
    String packageName = converterClass.getPackage().getName();
    if (beanClass == null) {
        JsonizerBean beanClassAnnotation = converterClass.getAnnotation(JsonizerBean.class);
        if (beanClassAnnotation != null) {
            qualifiedBeanClassName = beanClassAnnotation.value();
            beanClass = context.getTypeOracle().findType(qualifiedBeanClassName);
            packageName = beanClass.getPackage().getName();
        } else {
            logger.log(TreeLogger.ERROR, "Class '" + qualifiedBeanClassName
                    + "' not found but Jsonizer found. Please use Jsonizer bean annotation if both jsonizer and the bean are not in the same package",
                    null);
            throw new UnableToCompleteException();
        }
    }

    JClassType superBeanClass = beanClass.getSuperclass();

    // Verificacion de que los conversores de superclase implementen BeanJ2BConverter
    // si el bean no es subclase de object
    if (!superBeanClass.equals(typeOracle.getJavaLangObject())) {
        String superConverterName = packageName + "." + RebindUtils.jsonizerSimpleName(superBeanClass);
        JClassType superConverter = typeOracle.findType(superConverterName);
        //si el superconverter esta definido
        if (superConverter != null) {

            // si el super converter es clase
            if (superConverter.isClass() != null) {
                if (superConverter.isAbstract()) {
                    logger.log(TreeLogger.ERROR, "An user defined Jsonizer is abstract: '"
                            + superConverter.getQualifiedSourceName() + "'", null);
                    throw new UnableToCompleteException();
                }

                JClassType beanConverterClass = typeOracle.findType(Constants.BEAN_JSONIZER_CLASS);
                if (beanConverterClass == null) {
                    logger.log(TreeLogger.ERROR, "'" + Constants.BEAN_JSONIZER_CLASS + "' class not found",
                            null);
                    throw new UnableToCompleteException();
                }

                if (!superConverter.isAssignableTo(beanConverterClass)) {
                    logger.log(TreeLogger.ERROR,
                            "Super Jsonizer for '" + beanClass.getQualifiedSourceName()
                                    + "' class doesn't extends '" + Constants.BEAN_JSONIZER_CLASS + "' class",
                            null);
                    throw new UnableToCompleteException();
                }

            }

        }
    }

    String simpleStubClassName = RebindUtils.simpleStubClassName(converterClass);

    String qualifiedStubClassName = packageName + "." + simpleStubClassName;
    SourceWriter swBean = getSourceWriter(logger, context, packageName, simpleBeanClassName);
    SourceWriter sw = getSourceWriter(logger, context, packageName, simpleStubClassName,
            converterClass.getQualifiedSourceName());
    if (sw == null) {
        return qualifiedStubClassName;
    }

    JsonizerWriter converterWriter = new JsonizerWriter(logger, context, sw, beanClass);

    converterWriter.writeMethods();

    sw.commit(logger);

    return qualifiedStubClassName;
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectFactoryGenerator.java

License:Apache License

/**
 * Generate the code for the type with the given name.
 *
 * @param logger The logger./*w w w . j  av  a 2  s .  c o  m*/
 * @param context The context.
 * @param typeName The type name.
 * @return The name of the generated  class.
 * @throws UnableToCompleteException
 */
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType typeClassType = typeOracle.findType(typeName);
    if (!typeClassType.getQualifiedBinaryName().equals(JsonObjectFactory.class.getName())) {
        logger.log(TreeLogger.ERROR, "This generator only supports " + JsonObjectFactory.class.getName(), null);

        throw new UnableToCompleteException();
    }

    JClassType implBaseClassType = typeOracle.findType(GwtJsonObjectFactoryImplBase.class.getName());

    String implPackage = implBaseClassType.getPackage().getName();
    String implClassName = "GwtJsonObjectFactoryImpl";

    PrintWriter printWriter = context.tryCreate(logger, implPackage, implClassName);
    if (printWriter != null) {
        ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(implPackage,
                implClassName);

        composerFactory.setSuperclass(implBaseClassType.getQualifiedSourceName());

        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        sourceWriter.println("@SuppressWarnings(\"unchecked\")");
        sourceWriter.println("public " + implClassName + "() {");
        sourceWriter.indent();

        for (Map.Entry<String, String> entry : this.getJsonObjectImplClasses(logger, context).entrySet()) {
            this.writeJsonObjectInstantiator(sourceWriter, entry.getKey(), entry.getValue());
        }

        for (String jsonPropertyAdapterTypeName : this.getJsonPropertyAdapterClasses(logger, context)) {
            this.writeJsonPropertyAdapterInstantiator(sourceWriter, jsonPropertyAdapterTypeName);
        }

        sourceWriter.outdent();
        sourceWriter.println("}");

        sourceWriter.commit(logger);
    }

    return implPackage + "." + implClassName;
}