Java Code Examples for org.jboss.jandex.ClassInfo#interfaceNames()
The following examples show how to use
org.jboss.jandex.ClassInfo#interfaceNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringDataJPAProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private List<ClassInfo> getAllInterfacesExtending(Collection<DotName> targets, IndexView index) { List<ClassInfo> result = new ArrayList<>(); Collection<ClassInfo> knownClasses = index.getKnownClasses(); for (ClassInfo clazz : knownClasses) { if (!Modifier.isInterface(clazz.flags())) { continue; } List<DotName> interfaceNames = clazz.interfaceNames(); boolean found = false; for (DotName interfaceName : interfaceNames) { if (targets.contains(interfaceName)) { found = true; break; } } if (found) { result.add(clazz); } } return result; }
Example 2
Source File: JpaSecurityDefinition.java From quarkus with Apache License 2.0 | 6 votes |
private static MethodInfo findGetter(Index index, ClassInfo annotatedClass, String methodName) { MethodInfo method = annotatedClass.method(methodName); if (method != null) { return method; } DotName superName = annotatedClass.superName(); if (superName != null && !superName.equals(QuarkusSecurityJpaProcessor.DOTNAME_OBJECT)) { ClassInfo superClass = index.getClassByName(superName); if (superClass != null) { method = findGetter(index, superClass, methodName); if (method != null) { return method; } } } for (DotName interfaceName : annotatedClass.interfaceNames()) { ClassInfo interf = index.getClassByName(interfaceName); if (interf != null) { method = findGetter(index, interf, methodName); if (method != null) { return method; } } } return null; }
Example 3
Source File: TypeCreator.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private void addInterfaces(Type type, ClassInfo classInfo) { List<DotName> interfaceNames = classInfo.interfaceNames(); for (DotName interfaceName : interfaceNames) { // Ignore java interfaces (like Serializable) if (!interfaceName.toString().startsWith(JAVA_DOT)) { ClassInfo interfaceInfo = ScanningContext.getIndex().getClassByName(interfaceName); if (interfaceInfo != null) { Reference interfaceRef = referenceCreator.createReference(Direction.OUT, interfaceInfo); type.addInterface(interfaceRef); } } } }
Example 4
Source File: InterfaceCreator.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private void addInterfaces(InterfaceType interfaceType, ClassInfo classInfo) { List<DotName> interfaceNames = classInfo.interfaceNames(); for (DotName interfaceName : interfaceNames) { // Ignore java interfaces (like Serializable) if (!interfaceName.toString().startsWith(JAVA_DOT)) { ClassInfo c = ScanningContext.getIndex().getClassByName(interfaceName); if (c != null) { Reference interfaceRef = referenceCreator.createReference(Direction.OUT, classInfo); interfaceType.addInterface(interfaceRef); } } } }
Example 5
Source File: InterfaceConfigPropertiesUtil.java From quarkus with Apache License 2.0 | 5 votes |
private static void collectInterfacesRec(ClassInfo current, IndexView index, Set<DotName> result) { List<DotName> interfaces = current.interfaceNames(); if (interfaces.isEmpty()) { return; } for (DotName iface : interfaces) { ClassInfo classByName = index.getClassByName(iface); if (classByName == null) { throw new IllegalStateException("Unable to collect interfaces of " + iface + " because it was not indexed. Consider adding it to Jandex index"); } result.add(iface); collectInterfacesRec(classByName, index, result); } }
Example 6
Source File: GenerationUtil.java From quarkus with Apache License 2.0 | 5 votes |
static List<DotName> extendedSpringDataRepos(ClassInfo repositoryToImplement) { List<DotName> result = new ArrayList<>(); for (DotName interfaceName : repositoryToImplement.interfaceNames()) { if (DotNames.SUPPORTED_REPOSITORIES.contains(interfaceName)) { result.add(interfaceName); } } return result; }
Example 7
Source File: GenerationUtil.java From quarkus with Apache License 2.0 | 5 votes |
static Set<MethodInfo> interfaceMethods(Collection<DotName> interfaces, IndexView index) { Set<MethodInfo> result = new HashSet<>(); for (DotName dotName : interfaces) { ClassInfo classInfo = index.getClassByName(dotName); result.addAll(classInfo.methods()); List<DotName> extendedInterfaces = classInfo.interfaceNames(); if (!extendedInterfaces.isEmpty()) { result.addAll(interfaceMethods(extendedInterfaces, index)); } } return result; }
Example 8
Source File: Serianalyzer.java From serianalyzer with GNU General Public License v3.0 | 5 votes |
/** * @param ref * @param retType */ public void instantiable ( MethodReference ref, Type retType ) { if ( this.input.getConfig().isWhitelisted(ref) ) { return; } if ( retType.getSort() == Type.OBJECT ) { String className = retType.getClassName(); DotName typeName = DotName.createSimple(className); ClassInfo classByName = this.input.getIndex().getClassByName(typeName); if ( classByName != null ) { if ( !"java.lang.Object".equals(className) && !this.isTypeSerializable(this.getIndex(), className) ) { //$NON-NLS-1$ if ( ( Modifier.isInterface(classByName.flags()) || Modifier.isAbstract(classByName.flags()) ) && this.input.getConfig().isNastyBase(className) ) { return; } for ( DotName ifname : classByName.interfaceNames() ) { String ifStr = ifname.toString(); if ( !this.input.getConfig().isNastyBase(ifStr) ) { this.state.trackInstantiable(ifStr, ref, this.input.getConfig(), false); } } this.state.trackInstantiable(className, ref, this.input.getConfig(), false); } } } }
Example 9
Source File: SpringDataRepositoryCreator.java From quarkus with Apache License 2.0 | 4 votes |
public void implementCrudRepository(ClassInfo repositoryToImplement) { Map.Entry<DotName, DotName> extraTypesResult = extractIdAndEntityTypes(repositoryToImplement); String idTypeStr = extraTypesResult.getKey().toString(); DotName entityDotName = extraTypesResult.getValue(); String entityTypeStr = entityDotName.toString(); ClassInfo entityClassInfo = index.getClassByName(entityDotName); if (entityClassInfo == null) { throw new IllegalStateException("Entity " + entityDotName + " was not part of the Quarkus index"); } // handle the fragment repositories // Spring Data allows users to define (and implement their own interfaces containing data access related methods) // that can then be used along with any of the typical Spring Data repository interfaces in the final // repository in order to compose functionality List<DotName> interfaceNames = repositoryToImplement.interfaceNames(); List<DotName> fragmentNamesToImplement = new ArrayList<>(interfaceNames.size()); for (DotName interfaceName : interfaceNames) { if (!DotNames.SUPPORTED_REPOSITORIES.contains(interfaceName)) { fragmentNamesToImplement.add(interfaceName); } } Map<String, FieldDescriptor> fragmentImplNameToFieldDescriptor = new HashMap<>(); String repositoryToImplementStr = repositoryToImplement.name().toString(); String generatedClassName = repositoryToImplementStr + "_" + HashUtil.sha1(repositoryToImplementStr) + "Impl"; try (ClassCreator classCreator = ClassCreator.builder().classOutput(classOutput) .className(generatedClassName) .interfaces(repositoryToImplementStr) .build()) { classCreator.addAnnotation(ApplicationScoped.class); FieldCreator entityClassFieldCreator = classCreator.getFieldCreator("entityClass", Class.class.getName()) .setModifiers(Modifier.PRIVATE | Modifier.FINAL); // create an instance field of type Class for each one of the implementations of the custom interfaces createCustomImplFields(classCreator, fragmentNamesToImplement, index, fragmentImplNameToFieldDescriptor); // initialize all class fields in the constructor try (MethodCreator ctor = classCreator.getMethodCreator("<init>", "V")) { ctor.invokeSpecialMethod(MethodDescriptor.ofMethod(Object.class, "<init>", void.class), ctor.getThis()); // initialize the entityClass field ctor.writeInstanceField(entityClassFieldCreator.getFieldDescriptor(), ctor.getThis(), ctor.loadClass(entityTypeStr)); ctor.returnValue(null); } // for every method we add we need to make sure that we only haven't added it before // we first add custom methods (as per Spring Data implementation) thus ensuring that user provided methods // always override stock methods from the Spring Data repository interfaces fragmentMethodsAdder.add(classCreator, generatedClassName, fragmentNamesToImplement, fragmentImplNameToFieldDescriptor); stockMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(), generatedClassName, repositoryToImplement, entityDotName, idTypeStr); derivedMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(), generatedClassName, repositoryToImplement, entityClassInfo); customQueryMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(), repositoryToImplement, entityClassInfo); } }
Example 10
Source File: JpaJandexScavenger.java From quarkus with Apache License 2.0 | 4 votes |
/** * Add the class to the reflective list with full method and field access. * Add the superclasses recursively as well as the interfaces. * Un-indexed classes/interfaces are accumulated to be thrown as a configuration error in the top level caller method * <p> * TODO should we also return the return types of all methods and fields? It could contain Enums for example. */ private static void addClassHierarchyToReflectiveList(IndexView index, JpaEntitiesBuildItem domainObjectCollector, Set<String> enumTypeCollector, Set<String> javaTypeCollector, DotName className, Set<DotName> unindexedClasses) { if (className == null || isIgnored(className)) { // bail out if java.lang.Object or a class we want to ignore return; } // if the class is in the java. package and is not ignored, we want to register it for reflection if (isInJavaPackage(className)) { javaTypeCollector.add(className.toString()); return; } ClassInfo classInfo = index.getClassByName(className); if (classInfo == null) { unindexedClasses.add(className); return; } // we need to check for enums for (FieldInfo fieldInfo : classInfo.fields()) { DotName fieldType = fieldInfo.type().name(); ClassInfo fieldTypeClassInfo = index.getClassByName(fieldType); if (fieldTypeClassInfo != null && ENUM.equals(fieldTypeClassInfo.superName())) { enumTypeCollector.add(fieldType.toString()); } } //Capture this one (for various needs: Reflective access enablement, Hibernate enhancement, JPA Template) collectDomainObject(domainObjectCollector, classInfo); // add superclass recursively addClassHierarchyToReflectiveList(index, domainObjectCollector, enumTypeCollector, javaTypeCollector, classInfo.superName(), unindexedClasses); // add interfaces recursively for (DotName interfaceDotName : classInfo.interfaceNames()) { addClassHierarchyToReflectiveList(index, domainObjectCollector, enumTypeCollector, javaTypeCollector, interfaceDotName, unindexedClasses); } }