Example usage for com.google.gwt.uibinder.rebind.model OwnerClass OwnerClass

List of usage examples for com.google.gwt.uibinder.rebind.model OwnerClass OwnerClass

Introduction

In this page you can find the example usage for com.google.gwt.uibinder.rebind.model OwnerClass OwnerClass.

Prototype

public OwnerClass(JClassType ownerType, MortalLogger logger, UiBinderContext context)
        throws UnableToCompleteException 

Source Link

Document

Constructor.

Usage

From source file:com.xemantic.tadedon.gwt.field.rebind.UiFieldAccessorGenerators.java

License:Apache License

public static void write(MortalLogger logger, GeneratorContext context, String packageName, String implName,
        JClassType interfaceType, PrintWriter out, UiBinderContext uiBinderCtx)
        throws UnableToCompleteException {

    // Check for possible misuse 'GWT.create(UiFielcAccessor.class)'
    JClassType accessorItself = context.getTypeOracle().findType(UiFieldAccessor.class.getCanonicalName());
    if (accessorItself.equals(interfaceType)) {
        logger.die("You must use a subtype of UiFieldAccessor in GWT.create(). E.g.,\n"
                + "  interface Accessor extends UiFieldAccessor<MyClass> {}\n"
                + "  GWT.create(Accessor.class);");
    }/* w w w  .ja  v a  2s  .c  om*/

    JClassType[] accessorTypes = interfaceType.getImplementedInterfaces();
    if (accessorTypes.length == 0) {
        throw new RuntimeException("No implemented interfaces for " + interfaceType.getName());
    }

    JClassType accessorType = accessorTypes[0];

    JClassType[] typeArgs = accessorType.isParameterized().getTypeArgs();
    if (typeArgs.length < 1) {
        throw new RuntimeException("Owner type parameter is required for type %s" + accessorType.getName());
    }

    JClassType ownerType = typeArgs[0];

    OwnerClass ownerClass = new OwnerClass(ownerType, logger, uiBinderCtx);
    Set<String> fields = UiFieldAccessorGenerators.getFieldNames(ownerClass);
    UiFieldAccessorGenerators.write(packageName, implName, ownerType.getName(), interfaceType.getName(), fields,
            out);
}