@Test public void getDeclaredRepeatableAnnotationsDeclaredOnClass() { final List<String> expectedValuesJava = asList("A", "B", "C"); final List<String> expectedValuesSpring = asList("A", "B", "C", "meta1"); // Java 8 MyRepeatable[] array = MyRepeatableClass.class.getDeclaredAnnotationsByType(MyRepeatable.class); assertNotNull(array); List<String> values = stream(array).map(MyRepeatable::value).collect(toList()); assertThat(values, is(expectedValuesJava)); // Spring Set<MyRepeatable> set = getDeclaredRepeatableAnnotations(MyRepeatableClass.class, MyRepeatable.class, MyRepeatableContainer.class); assertNotNull(set); values = set.stream().map(MyRepeatable::value).collect(toList()); assertThat(values, is(expectedValuesSpring)); // When container type is omitted and therefore inferred from @Repeatable set = getDeclaredRepeatableAnnotations(MyRepeatableClass.class, MyRepeatable.class); assertNotNull(set); values = set.stream().map(MyRepeatable::value).collect(toList()); assertThat(values, is(expectedValuesSpring)); }
@Test public void getDeclaredRepeatableAnnotationsDeclaredOnSuperclass() { final Class<?> clazz = SubMyRepeatableClass.class; // Java 8 MyRepeatable[] array = clazz.getDeclaredAnnotationsByType(MyRepeatable.class); assertNotNull(array); assertThat(array.length, is(0)); // Spring Set<MyRepeatable> set = getDeclaredRepeatableAnnotations(clazz, MyRepeatable.class, MyRepeatableContainer.class); assertNotNull(set); assertThat(set.size(), is(0)); // When container type is omitted and therefore inferred from @Repeatable set = getDeclaredRepeatableAnnotations(clazz, MyRepeatable.class); assertNotNull(set); assertThat(set.size(), is(0)); }
/** * Attempts to find the @Jsii annotation from a type. * @param type The type. * @param inherited If 'true' will look for the annotation up the class hierarchy. * @return The annotation or null. */ static Jsii tryGetJsiiAnnotation(final Class<?> type, final boolean inherited) { Jsii[] ann; if (inherited) { ann = (Jsii[]) type.getAnnotationsByType(Jsii.class); } else { ann = (Jsii[]) type.getDeclaredAnnotationsByType(Jsii.class); } if (ann.length == 0) { return null; } return ann[0]; }
public void real(Set<FieldDescriptor> fieldDescriptors) { Class<?> testClass = context.getTestClass(); of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); locator.reload(); testReifier.reifyTest(fieldDescriptors); }
public void real(Set<FieldDescriptor> fieldDescriptors) { Class<?> testClass = context.getTestClass(); of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); locator.reload(); testReifier.reifyTest(fieldDescriptors); }
public void real(Set<FieldDescriptor> fieldDescriptors) { Class<?> testClass = context.getTestClass(); of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); locator.reload(); testReifier.reifyTest(fieldDescriptors); }
public void real(Set<FieldDescriptor> fieldDescriptors) { Class<?> testClass = context.getTestClass(); of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); locator.reload(); testReifier.reifyTest(fieldDescriptors); }
private <E extends Extension> List<ExtensionWrapper<E>> processSingleEeExtensions(List<E> extensions, List<EeComponentWrapper> wrappedComponents) { List<ExtensionWrapper<E>> extensionWrappers = new ArrayList<>(); for (E e : extensions) { EeExtensionDef def = e.getClass().getDeclaredAnnotation(EeExtensionDef.class); if (def != null) { EeComponentDependency[] dependencies = e.getClass().getDeclaredAnnotationsByType(EeComponentDependency.class); EeComponentOptional[] optionals = e.getClass().getDeclaredAnnotationsByType(EeComponentOptional.class); extensionWrappers.add(new ExtensionWrapper<>(e, def.name(), def.group(), dependencies, optionals)); } } log.info("Processing EE single extensions dependencies"); processEeExtensionDependencies(extensionWrappers, wrappedComponents); return extensionWrappers; }
@Override public void preMappingEntity(MetadataContext context, EntityMappingBuilder emb) throws MetadataException { Class<?> sourceClass = emb.getSourceClass(); if(null != sourceClass){ mappingEntityByAnnotation(context, emb, sourceClass.getAnnotation(Entity.class)); mappingEntityByAnnotation(context, emb, sourceClass.getAnnotation(Table.class)); mappingEntityByAnnotation(context, emb, sourceClass.getAnnotation(AutoCreateTable.class)); mappingEntityByAnnotation(context, emb, sourceClass.getAnnotation(AutoGenerateColumns.class)); mappingListenerByAnnotations(context, emb, sourceClass.getDeclaredAnnotationsByType(Entity.Listener.class)); mappingManyToOneByClassAnnotation(context, emb, sourceClass.getDeclaredAnnotationsByType(ManyToOne.class)); mappingManyToManyByClassAnnotation(context, emb, sourceClass.getDeclaredAnnotationsByType(ManyToMany.class)); } }
of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); of(testClass.getDeclaredAnnotationsByType(Scan.class)) .map(Scan::value) .distinct()
of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); of(testClass.getDeclaredAnnotationsByType(Scan.class)) .map(Scan::value) .distinct()
of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); of(testClass.getDeclaredAnnotationsByType(Scan.class)) .map(Scan::value) .distinct()
of(testClass.getDeclaredAnnotationsByType(Module.class)) .map(Module::value) .distinct() .forEachOrdered(locator::addModule); of(testClass.getDeclaredAnnotationsByType(Scan.class)) .map(Scan::value) .distinct()
private synchronized Collection<CompositeIndex> initCompositeIndexFields() { // init property fields to be able to check existence of properties propertyFields(); if (cls == null) { try { cls = Class.forName(className, false, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not get annotation info for class " + className, e); } } CompositeIndex[] annotations = cls.getDeclaredAnnotationsByType(CompositeIndex.class); ArrayList<CompositeIndex> result = new ArrayList<>(annotations.length); for (CompositeIndex annotation : annotations) { String[] properties = annotation.value().length > 0 ? annotation.value() : annotation.properties(); if (properties.length < 1) { throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Provide at least 1 property"); } for (String property : properties) { FieldInfo fieldInfo = propertyFields.get(property); if (fieldInfo == null) { throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Property " + property + " does not exists."); } } result.add(annotation); } return result; }
private <E extends Extension> List<ExtensionWrapper<E>> processGroupEeExtensions(List<E> extensions, List<EeComponentWrapper> wrappedComponents) { Map<String, ExtensionWrapper<E>> eeExt = new HashMap<>(); // Wrap extensions with their metadata and check for duplicates for (E e : extensions) { EeExtensionDef def = e.getClass().getDeclaredAnnotation(EeExtensionDef.class); if (def != null) { if (eeExt.containsKey(def.group())) { String msg = "Found multiple implementations (" + eeExt.get(def.group()).getName() + ", " + def.name() + ") of the same EE extension group (" + def.group() + "). " + "Please check to make sure you only include a single implementation of a specific " + "EE extension group."; log.severe(msg); throw new KumuluzServerException(msg); } EeComponentDependency[] dependencies = e.getClass().getDeclaredAnnotationsByType (EeComponentDependency.class); EeComponentOptional[] optionals = e.getClass().getDeclaredAnnotationsByType(EeComponentOptional.class); eeExt.put(def.group(), new ExtensionWrapper<>(e, def.name(), def.group(), dependencies, optionals)); } } List<ExtensionWrapper<E>> extensionWrappers = new ArrayList<>(eeExt.values()); log.info("Processing EE extension dependencies"); processEeExtensionDependencies(extensionWrappers, wrappedComponents); return extensionWrappers; }
&& klass.getDeclaredAnnotationsByType(Jsii.class).length == 0 && klass != Object.class) {
/** * Resolves all {@link MavenLibrary} annotations on the given class. * * @param clazz the class to load libraries for. */ public static void loadAll(Class<?> clazz) { MavenLibrary[] libs = clazz.getDeclaredAnnotationsByType(MavenLibrary.class); if (libs == null) { return; } for (MavenLibrary lib : libs) { load(lib.groupId(), lib.artifactId(), lib.version(), lib.repo().url()); } }
/** * Resolves all {@link MavenLibrary} annotations on the given class. * * @param clazz the class to load libraries for. */ public static void loadAll(Class<?> clazz) { MavenLibrary[] libs = clazz.getDeclaredAnnotationsByType(MavenLibrary.class); if (libs == null) { return; } for (MavenLibrary lib : libs) { load(lib.groupId(), lib.artifactId(), lib.version(), lib.repo().url()); } }
/** * Get all the annotations of the given type. * * @param <A> annotation type * @param annotationType the annotation type * @return optional with annotation, empty optional otherwise */ default <A extends Annotation> List<A> getAnnotations(Class<A> annotationType) { T type = getAnnotatedElement(); A[] declaredAnnotations = type.getDeclaredAnnotationsByType(annotationType); ImmutableList.Builder<A> listBuilder = ImmutableList.builder(); listBuilder.add(declaredAnnotations); for (Annotation annotation : type.getDeclaredAnnotations()) { Class<? extends Annotation> declaredAnnotationType = annotation.annotationType(); Bundle bundle = declaredAnnotationType.getDeclaredAnnotation(Bundle.class); if (bundle != null) { A[] bundleAnnotations = declaredAnnotationType.getDeclaredAnnotationsByType(annotationType); listBuilder.add(bundleAnnotations); } } return listBuilder.build(); }
EeComponentDependency[] dependencies = c.getClass().getDeclaredAnnotationsByType (EeComponentDependency.class); EeComponentOptional[] optionals = c.getClass().getDeclaredAnnotationsByType(EeComponentOptional.class);