Example usage for com.google.gwt.core.ext.typeinfo JClassType findAnnotationInTypeHierarchy

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType findAnnotationInTypeHierarchy

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType findAnnotationInTypeHierarchy.

Prototype

<T extends Annotation> T findAnnotationInTypeHierarchy(Class<T> annotationType);

Source Link

Document

Find an annotation on a type or on one of its superclasses or superinterfaces.

Usage

From source file:com.pietschy.gwt.pectin.rebind.BeanModelProviderCreator.java

License:Apache License

private Set<Class> getNestedTypeClasses(JClassType classType) {
    NestedTypes nestedTypeAnnotation = classType.findAnnotationInTypeHierarchy(NestedTypes.class);

    return nestedTypeAnnotation == null ? Collections.<Class>emptySet()
            : new HashSet<Class>(Arrays.asList(nestedTypeAnnotation.value()));
}

From source file:com.pietschy.gwt.pectin.rebind.BeanModelProviderCreator.java

License:Apache License

private int getRecursionDepth(JClassType classType) {
    LimitPropertyDepth maxNestedDepth = classType.findAnnotationInTypeHierarchy(LimitPropertyDepth.class);

    return maxNestedDepth == null ? -1 : maxNestedDepth.value();
}

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

License:Apache License

/**
 * get the list of the annotated beans.//from w  w w. java  2 s. com
 *
 * @param plogger logger
 * @param pvalidatorType class type
 * @return list of classes
 * @throws UnableToCompleteException it's thrown, if no classes can be found
 */
private Class<?>[] getBeans(final TreeLogger plogger, final JClassType pvalidatorType)
        throws UnableToCompleteException {
    final String typeName = pvalidatorType.getName();

    final GwtValidation gwtValidation = pvalidatorType.findAnnotationInTypeHierarchy(GwtValidation.class);

    if (gwtValidation == null) {
        plogger.log(TreeLogger.ERROR,
                typeName + " must be anntotated with " + GwtValidation.class.getCanonicalName(), null);
        throw new UnableToCompleteException();
    }

    if (gwtValidation.value().length == 0) {
        plogger.log(TreeLogger.ERROR, "The @" + GwtValidation.class.getSimpleName() + "  of " + typeName
                + "must specify at least one bean type to validate.", null);
        throw new UnableToCompleteException();
    }

    return gwtValidation.value();
}

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

License:Apache License

private String generateGenericValidator(final TreeLogger logger, final GeneratorContext context,
        final JClassType validatorType) throws UnableToCompleteException {
    final String typeName = validatorType.getName();

    final GwtValidation gwtValidation = validatorType.findAnnotationInTypeHierarchy(GwtValidation.class);

    if (gwtValidation == null) {
        logger.log(TreeLogger.ERROR,/*ww w.  j a  v  a2  s . c  o m*/
                typeName + " must be anntotated with " + GwtValidation.class.getCanonicalName(), null);
        throw new UnableToCompleteException();
    }

    if (gwtValidation.value().length == 0) {
        logger.log(TreeLogger.ERROR, "The @" + GwtValidation.class.getSimpleName() + "  of " + typeName
                + "must specify at least one bean type to validate.", null);
        throw new UnableToCompleteException();
    }

    if (gwtValidation.groups().length == 0) {
        logger.log(TreeLogger.ERROR, "The @" + GwtValidation.class.getSimpleName() + "  of " + typeName
                + "must specify at least one validation group.", null);
        throw new UnableToCompleteException();
    }

    this.validGroups = gwtValidation.groups();

    final TreeLogger validatorLogger = logger.branch(TreeLogger.DEBUG,
            "Generating Validator for  '" + validatorType.getQualifiedSourceName() + "'", null);
    final AbstractCreator creator = new ValidatorCreator(validatorType, gwtValidation, validatorLogger, context,
            this.cache);
    return creator.create();
}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    typeOracle = context.getTypeOracle();
    String className = "";
    String packageName = "";
    try {//from   w w  w  .j  a v a  2s  .  c  o m

        JClassType classType = typeOracle.getType(typeName);
        className = classType.getSimpleSourceName() + "Impl";
        packageName = classType.getPackage().getName();
        Class<?> superInterface = Class.forName(packageName + "." + classType.getSimpleSourceName());
        PrintWriter pw = context.tryCreate(logger, classType.getPackage().getName(), className);
        if (pw != null) {
            WebApp annotatedApp = classType.findAnnotationInTypeHierarchy(WebApp.class);
            if (annotatedApp == null) {
                return null;
            }
            // String container = annotatedApp.container();
            String mainPage = annotatedApp.mainPage();
            Class<?> modelClass = annotatedApp.appStateType();

            TypeSpec objectMapperInterface = createObjectMapperInterface(
                    "ObjectMapper" + modelClass.getSimpleName(), modelClass);
            TypeSpec.Builder webappBuilder = createWebAppClass(className, mainPage, modelClass, superInterface,
                    objectMapperInterface);
            Geolocation geolocation = scanGeolocationService(classType);
            if (geolocation != null) {
                webappBuilder = addGeolocationService(webappBuilder, geolocation);
            }
            Battery battery = scanBatteryService(classType);
            if (battery != null) {
                webappBuilder = addBatteryService(webappBuilder, battery);
            }
            Storage storage = scanStorageService(classType);
            if (storage != null) {
                webappBuilder = addStorageService(webappBuilder, storage, objectMapperInterface);
            }
            ScreenOrientation screenOrientation = scanScreenOrientation(classType);
            if (screenOrientation != null) {
                webappBuilder = addScreenOrientationService(webappBuilder, screenOrientation);
            }
            Offline offline = scanOfflineService(classType);
            if (offline != null) {
                webappBuilder = addOfflineApplicationCacheService(webappBuilder, offline);
            }
            webappBuilder = overrideStoreCurrentAppState(webappBuilder, modelClass);
            TypeSpec webapp = webappBuilder.build();
            JavaFile file = buildJavaFile(packageName, webapp);
            file.writeTo(pw);
            context.commit(logger, pw);
        }
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return packageName + "." + className;
}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

protected Offline scanOfflineService(JClassType classType) {
    Offline annotation = classType.findAnnotationInTypeHierarchy(Offline.class);
    if (annotation != null) {
        return annotation;
    }/*  w  ww.  jav  a  2s . c o  m*/
    return null;
}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

protected ScreenOrientation scanScreenOrientation(JClassType classType) {
    ScreenOrientation annotation = classType.findAnnotationInTypeHierarchy(ScreenOrientation.class);
    if (annotation != null) {
        return annotation;
    }//from  w  w  w . ja v a  2  s .  c o m
    return null;
}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

protected Storage scanStorageService(JClassType classType) {
    Storage annotation = classType.findAnnotationInTypeHierarchy(Storage.class);

    if (annotation != null) {
        return annotation;
    }//  ww  w . ja  v a 2s.  com
    return null;
}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

protected Battery scanBatteryService(JClassType classType) {
    Battery annoatation = classType.findAnnotationInTypeHierarchy(Battery.class);
    if (annoatation != null) {
        return annoatation;
    }//w  w  w.jav  a2  s. c  o m
    return null;

}

From source file:it.appify.generator.WebAppGenerator.java

License:Open Source License

protected Geolocation scanGeolocationService(JClassType classType) {
    Geolocation geolocationAnnotation = classType.findAnnotationInTypeHierarchy(Geolocation.class);
    if (geolocationAnnotation != null) {
        return geolocationAnnotation;
    }/*from  w w w .  ja v a 2  s  .  c  om*/
    return null;

}