List of usage examples for com.google.gwt.core.ext.typeinfo JClassType getAnnotations
Annotation[] getAnnotations();
From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java
License:Apache License
public static boolean hasAnnotationNamed(JClassType clazz, Class<? extends Annotation> ann) { String annClazzName = ann.getSimpleName(); if (!classNameAnnotationMap.containsKey(clazz, annClazzName)) { JClassType c = clazz; Annotation found = null;/* w w w.j av a 2 s .c o m*/ while (c != null && found == null) { for (Annotation a : c.getAnnotations()) { if (a.annotationType().getSimpleName().equals(annClazzName)) { found = a; break; } } c = c.getSuperclass(); } classNameAnnotationMap.put(clazz, annClazzName, found); } return classNameAnnotationMap.get(clazz, annClazzName) != null; }
From source file:org.cruxframework.crux.core.rebind.context.JClassScanner.java
License:Apache License
private void initializeAnnotationsMap() { if (annotationsMap == null) { annotationsMap = new HashMap<String, List<JClassType>>(); for (JClassType type : context.getTypeOracle().getTypes()) { Annotation[] annotations = type.getAnnotations(); if (annotations != null) { for (Annotation annotation : annotations) { String annotationName = annotation.annotationType().getCanonicalName(); List<JClassType> annotationsList = annotationsMap.get(annotationName); if (annotationsList == null) { annotationsList = new ArrayList<JClassType>(); annotationsMap.put(annotationName, annotationsList); }//from www.j a v a 2 s . c om annotationsList.add(type); } } } } }
From source file:org.jboss.errai.codegen.meta.impl.gwt.GWTClass.java
License:Apache License
protected GWTClass(final TypeOracle oracle, final JType classType, final boolean erased) { super(classType); this.oracle = oracle; final JClassType classOrInterface = classType.isClassOrInterface(); if (classOrInterface != null) { annotations = AnnotationParser.parseAnnotations(classOrInterface.getAnnotations()); } else {/*from w w w. ja v a 2 s . c o m*/ annotations = new Annotation[0]; } if (classType.getQualifiedSourceName().contains(" ") || classType.getQualifiedSourceName().contains("?")) { throw new IllegalArgumentException("Cannot represent \"" + classType + "\" as a class. Try a different meta type such as GWTWildcardType or GWTTypeVaraible."); } final JParameterizedType parameterizedType = classType.isParameterized(); if (!erased) { if (parameterizedType != null) { super.parameterizedType = new GWTParameterizedType(oracle, parameterizedType); } } }
From source file:org.lirazs.gbackbone.gen.AnnotationsHelper.java
License:Apache License
public static Annotation[] getAnnotations(JClassType classType) { return classType.getAnnotations(); }
From source file:xapi.dev.generators.InstanceInjectionGenerator.java
License:Open Source License
/** * @throws ClassNotFoundException//from w ww . j a v a 2 s . c o m */ public static RebindResult execImpl(TreeLogger logger, GeneratorContext context, JClassType type) throws ClassNotFoundException { JClassType targetType = type; InstanceOverride winningOverride = null; JClassType winningType = null; // Step one: determine what platform we are targeting. Set<Class<? extends Annotation>> allowedPlatforms = getPlatforms(context); boolean trace = logger.isLoggable(Type.TRACE); if (trace) { logger.log(Type.TRACE, "Allowed platforms: " + allowedPlatforms); logger.log(Type.TRACE, "All Subtypes: " + Arrays.asList(type.getSubtypes())); } for (JClassType subtype : type.getSubtypes()) { if (trace) logger.log(Type.TRACE, "Type " + subtype.getJNISignature()); InstanceDefault def = subtype.getAnnotation(InstanceDefault.class); if (def != null) { if (winningType != null) continue; // a default cannot possibly override anything. // Make sure this type is not excluded by being part of a disallowed platform boolean useType = true; for (Annotation anno : def.annotationType().getAnnotations()) { if (anno.annotationType().getAnnotation(Platform.class) != null) { if (allowedPlatforms.contains(anno.annotationType())) { winningType = subtype; continue; } useType = false; } } // If we made it through without continue, or setting useType to false, // then there is no platform specified, and this is a global default type. if (useType) winningType = subtype; } InstanceOverride override = subtype.getAnnotation(InstanceOverride.class); if (override != null) { // Prefer GwtPlatform or GwtDevPlatform, // and blacklist any types that are of a foreign platform type (non-gwt). boolean hasGwt = false, hasOther = false; for (Annotation annotation : subtype.getAnnotations()) { // check each annotation to see if it is qualified with @Platform. Platform platform = annotation.annotationType().getAnnotation(Platform.class); if (platform != null) { // When platform is non-null, we only want to use it if it's in our allowed list. if (allowedPlatforms.contains(annotation.annotationType())) { hasGwt = true; break; } else { hasOther = true; } } } // if hasOther is false, or hasGwt is true, we want to use this type. if (hasOther && !hasGwt) { continue; } if (trace) logger.log(Type.DEBUG, "Test subtype match " + subtype + " - prodMode: " + context.isProdMode()); if (winningOverride != null) { if (winningOverride.priority() > override.priority()) continue; } winningOverride = override; winningType = subtype; } } if (winningType == null) { winningType = targetType;// no matches, resort to instantiate the class sent. if (trace) logger.log(Type.TRACE, "No match made; resorting to GWT.create() on " + winningType + " : "); } String packageName = type.getPackage().getName(); ensureProviderClass(logger, packageName, type.getSimpleSourceName(), type.getQualifiedSourceName(), SourceUtil.toSourceName(winningType.getQualifiedSourceName()), context); logger.log(Type.INFO, "Instance injection: " + type.getQualifiedSourceName() + " -> " + winningType.getQualifiedSourceName()); return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, winningType.getQualifiedSourceName()); }