@Override public void process() { Collection<AnnotationInstance> annos = index.getAnnotations(DotName.createSimple(Advertise.class.getName())); Collection<AnnotationInstance> repeatingAnnos = index.getAnnotations(DotName.createSimple(Advertises.class.getName())); Stream.concat(annos.stream(), repeatingAnnos .stream() .flatMap(anno -> Stream.of(anno.value().asNestedArray()))) .forEach(anno -> advertise(archive, anno)); }
private boolean isVetoedTypeOrPackage() { if (isAnnotationDeclared(classInfo, DOT_NAME_VETOED)) { return true; } final DotName packageInfoName = DotName.createComponentized(getPackageName(classInfo.name()), PACKAGE_INFO_NAME); ClassInfo packageInfo = index.getClassByName(packageInfoName); if (packageInfo != null && isAnnotationDeclared(packageInfo, DOT_NAME_VETOED)) { return true; } return false; }
/** * Extract the package information from the given {@code ClassInfo} object. * * @param classInfo the class metadata. * @param packages the collection to which we need to add the package information. */ private static void extractAndAddPackageInfo(ClassInfo classInfo, Set<String> packages, IndexView indexView) { if (classInfo == null) { return; } // Check if we were given an abstract class / interface, in which case we need to check the IndexView to see if there // is an implementation or not. String className = classInfo.name().toString(); if (indexView != null) { DotName dotName = DotName.createSimple(className); if (Modifier.isInterface(classInfo.flags())) { indexView.getAllKnownImplementors(dotName).forEach(ci -> extractAndAddPackageInfo(ci, packages, indexView)); } else if (Modifier.isAbstract(classInfo.flags())) { indexView.getAllKnownSubclasses(dotName).forEach(ci -> extractAndAddPackageInfo(ci, packages, indexView)); } } StringBuilder builder = new StringBuilder(className).reverse(); int idx = builder.indexOf("."); if (idx != -1) { builder.delete(0, idx + 1); } packages.add(builder.reverse().toString()); }
private List<Tuple2<IJavaModuleData, ClassInfo>> getAllKnownSubclasses(ModuleJandexIndex module, DotName name, boolean isInterface) { ImmutableList.Builder<Tuple2<IJavaModuleData, ClassInfo>> builder = ImmutableList.builder(); IndexView indexView = module.getIndex().get(); if (indexView != null) { Collection<ClassInfo> subTypes = isInterface ? indexView.getAllKnownImplementors(name) : indexView.getAllKnownSubclasses(name); if (subTypes != null) { for (ClassInfo info : subTypes) { builder.add(Tuples.of(module, info)); } } } return builder.build(); }
private boolean containsAnnotation(ClassInfo classInfo, DotName requiredAnnotationName, Class<? extends Annotation> requiredAnnotation) { if (classInfo.annotations().containsKey(requiredAnnotationName)) { return true; for (DotName annotation : classInfo.annotations().keySet()) { if (annotationClassAnnotationsCache.getValue(annotation).contains(requiredAnnotationName.toString())) { return true; final DotName superName = classInfo.superName(); if (superName != null && !OBJECT_NAME.equals(superName)) { final ClassInfo superClassInfo = index.getClassByName(superName); if (superClassInfo == null) { return Reflections.containsAnnotation(loadClass(superName.toString()), requiredAnnotation); for (DotName interfaceName : classInfo.interfaceNames()) { final ClassInfo interfaceInfo = index.getClassByName(interfaceName); if (interfaceInfo == null) {
if (to.getName().equals(name.toString())) { return true; if (OBJECT_NAME.equals(name)) { return false; // there's nothing assignable from Object.class except for Object.class ClassInfo fromClassInfo = index.getClassByName(name); if (fromClassInfo == null) { final Class<?> clazz = loadClass(name.toString()); return to.isAssignableFrom(clazz); DotName superName = fromClassInfo.superName(); if (fromClassInfo.interfaceNames() != null) { for (DotName interfaceName : fromClassInfo.interfaceNames()) { if (isAssignableTo(interfaceName, to)) { return true;
@Override public Set<String> apply(DotName name) { ClassInfo annotationClassInfo = index.getClassByName(name); ImmutableSet.Builder<String> builder = ImmutableSet.builder(); if (annotationClassInfo != null) { for (DotName annotationName : annotationClassInfo.annotations().keySet()) { builder.add(annotationName.toString()); } } else { try { Class<?> annotationClass = classLoader.loadClass(name.toString()); for (Annotation annotation : annotationClass.getDeclaredAnnotations()) { builder.add(annotation.annotationType().getName()); } } catch (ClassNotFoundException e) { throw CommonLogger.LOG.unableToLoadAnnotation(name.toString()); } } return builder.build(); } }
public JandexClassFileInfo(String className, IndexView index, ComputingCache<DotName, Set<String>> annotationClassAnnotationsCache, ClassLoader classLoader) { this.index = index; this.annotationClassAnnotationsCache = annotationClassAnnotationsCache; this.classInfo = index.getClassByName(DotName.createSimple(className)); if (this.classInfo == null) { throw CommonLogger.LOG.indexForNameNotFound(className); } this.isVetoed = isVetoedTypeOrPackage(); this.hasCdiConstructor = this.classInfo.hasNoArgsConstructor() || hasInjectConstructor(); this.classLoader = classLoader; }
private Collection<String> getKnownPackages(ModuleJandexIndex module) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); IndexView indexView = module.getIndex().get(); if (indexView != null) { indexView.getKnownClasses(); Collection<ClassInfo> knownClasses = indexView.getKnownClasses(); if (knownClasses != null) { for (ClassInfo info : knownClasses) { String name = info.name().toString(); String pkg = name.substring(0, name.lastIndexOf('.')); builder.add(pkg); } } } return builder.build(); }
private boolean containsAnnotation(ClassInfo classInfo, DotName requiredAnnotationName, Class<? extends Annotation> requiredAnnotation) { // Type and members if (classInfo.annotations().containsKey(requiredAnnotationName)) { return true; } // Meta-annotations for (DotName annotation : classInfo.annotations().keySet()) { if (annotationClassAnnotationsCache.getValue(annotation).contains(requiredAnnotationName.toString())) { return true; } } // Superclass final DotName superName = classInfo.superName(); if (superName != null && !OBJECT_NAME.equals(superName)) { final ClassInfo superClassInfo = index.getClassByName(superName); if (superClassInfo == null) { // we are accessing a class that is outside of the jandex index // fallback to using reflection return Reflections.containsAnnotation(loadClass(superName.toString()), requiredAnnotation); } if (containsAnnotation(superClassInfo, requiredAnnotationName, requiredAnnotation)) { return true; } } return false; }
if (to.getName().equals(name.toString())) { return true; if (OBJECT_NAME.equals(name)) { return false; // there's nothing assignable from Object.class except for Object.class ClassInfo fromClassInfo = index.getClassByName(name); if (fromClassInfo == null) { final Class<?> clazz = loadClass(name.toString()); return to.isAssignableFrom(clazz); DotName superName = fromClassInfo.superName(); if (fromClassInfo.interfaces() != null) { for (DotName interfaceName : fromClassInfo.interfaces()) { if (isAssignableTo(interfaceName, to)) { return true;
private void getKnownImplementors(DotName name, Set<ClassInfo> allKnown, Set<DotName> subInterfacesToProcess, Set<DotName> processedClasses) { for (IndexView index : indexes) { final Collection<ClassInfo> list = index.getKnownDirectImplementors(name); if (list != null) { for (final ClassInfo clazz : list) { final DotName className = clazz.name(); if (!processedClasses.contains(className)) { if (Modifier.isInterface(clazz.flags())) { subInterfacesToProcess.add(className); } else { if (!allKnown.contains(clazz)) { allKnown.add(clazz); processedClasses.add(className); getAllKnownSubClasses(className, allKnown, processedClasses); } } } } } } }
Collection<AnnotationInstance> appPathAnnotations = index.getAnnotations(APP_PATH); for (AnnotationInstance annotation : appPathAnnotations) { if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { Collection<AnnotationInstance> pathAnnotations = index.getAnnotations(PATH); for (AnnotationInstance annotation : pathAnnotations) { if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { ClassInfo classInfo = annotation.target().asClass(); for (MethodInfo methodInfo : classInfo.methods()) { if (methodInfo.hasAnnotation(HEALTH)) { StringBuilder sb = new StringBuilder(); for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) { if (classAnnotation.name().equals(PATH)) { String methodPathValue = classAnnotation.value().asString(); if (!methodPathValue.equals("/")) {
ClassInfo definition = index.getClassByName(this.name); if (definition == null) { throw new IllegalArgumentException("Index did not contain annotation definition: " + this.name); List<MethodInfo> methods = definition.methods(); ArrayList<AnnotationValue> result = new ArrayList<AnnotationValue>(methods.size()); for (MethodInfo method : methods) {
ClassInfo definition = index.getClassByName(this.name); if (definition == null) { throw new IllegalArgumentException("Index did not contain annotation definition: " + this.name); MethodInfo method = definition.method(name); return method == null ? null : method.defaultValue();
/** * {@inheritDoc} */ public ClassInfo getClassByName(final DotName className) { for (IndexView index : indexes) { final ClassInfo info = index.getClassByName(className); if (info != null) { return info; } } return null; }
/** * {@inheritDoc} */ public List<AnnotationInstance> getAnnotations(final DotName annotationName) { final List<AnnotationInstance> allInstances = new ArrayList<AnnotationInstance>(); for (IndexView index : indexes) { final Collection<AnnotationInstance> list = index.getAnnotations(annotationName); if (list != null) { allInstances.addAll(list); } } return Collections.unmodifiableList(allInstances); }
/** * {@inheritDoc} */ public Collection<ClassInfo> getKnownClasses() { final List<ClassInfo> allKnown = new ArrayList<ClassInfo>(); for (IndexView index : indexes) { final Collection<ClassInfo> list = index.getKnownClasses(); if (list != null) { allKnown.addAll(list); } } return Collections.unmodifiableCollection(allKnown); } }
/** * {@inheritDoc} */ public Collection<ClassInfo> getKnownDirectImplementors(final DotName className) { final Set<ClassInfo> allKnown = new HashSet<ClassInfo>(); for (IndexView index : indexes) { final Collection<ClassInfo> list = index.getKnownDirectImplementors(className); if (list != null) { allKnown.addAll(list); } } return Collections.unmodifiableSet(allKnown); }
private boolean containsAnnotation(ClassInfo classInfo, DotName requiredAnnotationName, Class<? extends Annotation> requiredAnnotation) { if (classInfo.annotations().containsKey(requiredAnnotationName)) { return true; for (DotName annotation : classInfo.annotations().keySet()) { if (annotationClassAnnotationsCache.getValue(annotation).contains(requiredAnnotationName.toString())) { return true; final DotName superName = classInfo.superName(); if (superName != null && !OBJECT_NAME.equals(superName)) { final ClassInfo superClassInfo = index.getClassByName(superName); if (superClassInfo == null) { return Reflections.containsAnnotation(loadClass(superName.toString()), requiredAnnotation); for (DotName interfaceName : classInfo.interfaceNames()) { final ClassInfo interfaceInfo = index.getClassByName(interfaceName); if (interfaceInfo == null) {