Java Code Examples for org.jboss.jandex.ClassInfo#name()
The following examples show how to use
org.jboss.jandex.ClassInfo#name() .
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: BeanArchives.java From quarkus with Apache License 2.0 | 6 votes |
private void getKnownImplementors(DotName name, Set<ClassInfo> allKnown, Set<DotName> subInterfacesToProcess, Set<DotName> processedClasses) { final Collection<ClassInfo> list = 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); } } } } } }
Example 2
Source File: FragmentMethodsUtil.java From quarkus with Apache License 2.0 | 6 votes |
/** * Returns the simple expected implementation of a Fragment interface or throws an * exception indicating the problem */ static DotName getImplementationDotName(DotName customInterfaceToImplement, IndexView index) { Collection<ClassInfo> knownImplementors = index.getAllKnownImplementors(customInterfaceToImplement); if (knownImplementors.size() > 1) { DotName previouslyFound = null; for (ClassInfo knownImplementor : knownImplementors) { if (knownImplementor.name().toString().endsWith("Impl")) { // the default suffix that Spring Data JPA looks for is 'Impl' if (previouslyFound != null) { // make sure we don't have multiple implementations suffixed with 'Impl' throw new IllegalArgumentException( "Interface " + customInterfaceToImplement + " must contain a single implementation whose name ends with 'Impl'. Multiple implementations were found: " + previouslyFound + "," + knownImplementor); } previouslyFound = knownImplementor.name(); } } return previouslyFound; } else if (knownImplementors.size() == 1) { return knownImplementors.iterator().next().name(); } else { throw new IllegalArgumentException( "No implementation of interface " + customInterfaceToImplement + " was found"); } }
Example 3
Source File: JpaJandexScavenger.java From quarkus with Apache License 2.0 | 6 votes |
private void enlistJPAModelClasses(IndexView index, JpaEntitiesBuildItem domainObjectCollector, Set<String> enumTypeCollector, Set<String> javaTypeCollector, DotName dotName, Set<DotName> unindexedClasses) { Collection<AnnotationInstance> jpaAnnotations = index.getAnnotations(dotName); if (jpaAnnotations == null) { return; } for (AnnotationInstance annotation : jpaAnnotations) { ClassInfo klass = annotation.target().asClass(); DotName targetDotName = klass.name(); // ignore non-jpa model classes that we think belong to JPA if (nonJpaModelClasses.contains(targetDotName.toString())) { continue; } addClassHierarchyToReflectiveList(index, domainObjectCollector, enumTypeCollector, javaTypeCollector, targetDotName, unindexedClasses); collectDomainObject(domainObjectCollector, klass); } }
Example 4
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 6 votes |
/** * Get a single scope from the available options or throw a {@link DefinitionException} explaining * where the annotations conflict. * * @param clazz The class annotated with the scopes * @param scopes The scopes from the class and its stereotypes * @param scopeStereotypes The stereotype annotations that declared the conflicting scopes * @return The scope for the target class */ private DotName validateScope(final ClassInfo clazz, final Set<DotName> scopes, final Set<DotName> scopeStereotypes) { final int size = scopes.size(); switch (size) { case 0: // Spring default return CDI_SINGLETON_ANNOTATION; case 1: return scopes.iterator().next(); default: throw new DefinitionException( "Components annotated with multiple conflicting scopes must declare an explicit @Scope. " + clazz.name() + " declares scopes: " + scopes.stream().map(DotName::toString).collect(Collectors.joining(", ")) + " through the stereotypes: " + scopeStereotypes.stream().map(DotName::toString) .collect(Collectors.joining(", "))); } }
Example 5
Source File: SmallRyeMetricsProcessor.java From quarkus with Apache License 2.0 | 6 votes |
/** * Obtains the MetricType from a bean that is a producer method or field, * or null if no MetricType can be detected. */ private MetricType getMetricType(ClassInfo clazz) { DotName name = clazz.name(); if (name.equals(GAUGE_INTERFACE)) { return MetricType.GAUGE; } if (name.equals(COUNTER_INTERFACE)) { return MetricType.COUNTER; } if (name.equals(CONCURRENT_GAUGE_INTERFACE)) { return MetricType.CONCURRENT_GAUGE; } if (name.equals(HISTOGRAM_INTERFACE)) { return MetricType.HISTOGRAM; } if (name.equals(SIMPLE_TIMER_INTERFACE)) { return MetricType.SIMPLE_TIMER; } if (name.equals(TIMER_INTERFACE)) { return MetricType.TIMER; } if (name.equals(METER_INTERFACE)) { return MetricType.METERED; } return null; }
Example 6
Source File: PanacheHibernateResourceProcessor.java From quarkus with Apache License 2.0 | 6 votes |
@BuildStep ValidationPhaseBuildItem.ValidationErrorBuildItem validate(ValidationPhaseBuildItem validationPhase, CombinedIndexBuildItem index) throws BuildException { // we verify that no ID fields are defined (via @Id) when extending PanacheEntity for (AnnotationInstance annotationInstance : index.getIndex().getAnnotations(DOTNAME_ID)) { ClassInfo info = JandexUtil.getEnclosingClass(annotationInstance); if (JandexUtil.isSubclassOf(index.getIndex(), info, DOTNAME_PANACHE_ENTITY)) { BuildException be = new BuildException("You provide a JPA identifier via @Id inside '" + info.name() + "' but one is already provided by PanacheEntity, " + "your class should extend PanacheEntityBase instead, or use the id provided by PanacheEntity", Collections.emptyList()); return new ValidationPhaseBuildItem.ValidationErrorBuildItem(be); } } return null; }
Example 7
Source File: CompositeIndex.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void getKnownImplementors(DotName name, Set<ClassInfo> allKnown, Set<DotName> subInterfacesToProcess, Set<DotName> processedClasses) { for (Index index : indexes) { final List<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); } } } } } } }
Example 8
Source File: BeanArchives.java From quarkus with Apache License 2.0 | 5 votes |
private void getAllKnownSubClasses(DotName name, Set<ClassInfo> allKnown, Set<DotName> subClassesToProcess, Set<DotName> processedClasses) { final Collection<ClassInfo> directSubclasses = getKnownDirectSubclasses(name); if (directSubclasses != null) { for (final ClassInfo clazz : directSubclasses) { final DotName className = clazz.name(); if (!processedClasses.contains(className)) { allKnown.add(clazz); subClassesToProcess.add(className); } } } }
Example 9
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 5 votes |
/** * @param index An index view of the archive including all the spring classes * @return A map of any spring annotations extending @Component which will function like * CDI stereotypes to any scopes it, or any of its stereotypes declared. */ Map<DotName, Set<DotName>> getStereotypeScopes(final IndexView index) { final Map<DotName, Set<DotName>> scopes = new HashMap<>(); scopes.put(SPRING_COMPONENT, Collections.emptySet()); scopes.put(SPRING_REPOSITORY, Collections.emptySet()); scopes.put(SPRING_SERVICE, Collections.emptySet()); final List<ClassInfo> allAnnotations = getOrderedAnnotations(index); final Set<DotName> stereotypeClasses = new HashSet<>(SPRING_STEREOTYPE_ANNOTATIONS); for (final ClassInfo clazz : allAnnotations) { final Set<DotName> clazzAnnotations = clazz.annotations().keySet(); final Set<DotName> clazzStereotypes = new HashSet<>(); final Set<DotName> clazzScopes = new HashSet<>(); for (final DotName stereotypeName : stereotypeClasses) { if (clazzAnnotations.contains(stereotypeName)) { clazzStereotypes.add(stereotypeName); } } if (clazzStereotypes.isEmpty()) { continue; } final DotName name = clazz.name(); stereotypeClasses.add(name); for (final DotName stereotype : clazzStereotypes) { final Set<DotName> vals = scopes.get(stereotype); if (vals != null) { clazzScopes.addAll(vals); } } final DotName scope = getScope(clazz); if (scope != null) { clazzScopes.add(scope); } scopes.put(name, clazzScopes); } return scopes; }
Example 10
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 5 votes |
/** * Get the name of a bean or throw a {@link DefinitionException} if it has more than one name * * @param clazz The class annotated with the names * @param names The names * @return The bane name */ private String validateName(final ClassInfo clazz, final Set<String> names) { final int size = names.size(); switch (size) { case 0: return null; case 1: return names.iterator().next(); default: throw new DefinitionException( "Component " + clazz.name() + " is annotated with multiple conflicting names: " + String.join(", ", names)); } }
Example 11
Source File: BeanMethodInvocationGenerator.java From quarkus with Apache License 2.0 | 5 votes |
private MethodInfo determineMatchingBeanMethod(String methodName, int methodParametersSize, ClassInfo beanClassInfo, MethodInfo securedMethodInfo, String expression, String beanName) { MethodInfo matchingBeanClassMethod = null; for (MethodInfo candidateMethod : beanClassInfo.methods()) { if (candidateMethod.name().equals(methodName) && Modifier.isPublic(candidateMethod.flags()) && DotNames.PRIMITIVE_BOOLEAN.equals(candidateMethod.returnType().name()) && candidateMethod.parameters().size() == methodParametersSize) { if (matchingBeanClassMethod == null) { matchingBeanClassMethod = candidateMethod; } else { throw new IllegalArgumentException( "Could not match a unique method name '" + methodName + "' for bean named " + beanName + " with class " + beanClassInfo.name() + " Offending expression is " + expression + " of @PreAuthorize on method '" + methodName + "' of class " + securedMethodInfo.declaringClass()); } } } if (matchingBeanClassMethod == null) { throw new IllegalArgumentException( "Could not find a public, boolean returning method named '" + methodName + "' for bean named " + beanName + " with class " + beanClassInfo.name() + " Offending expression is " + expression + " of @PreAuthorize on method '" + methodName + "' of class " + securedMethodInfo.declaringClass()); } return matchingBeanClassMethod; }
Example 12
Source File: HibernateOrmPanacheRestProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private void validateResource(IndexView index, ClassInfo classInfo) { if (!Modifier.isInterface(classInfo.flags())) { throw new RuntimeException(classInfo.name() + " has to be an interface"); } if (classInfo.interfaceNames().size() > 1) { throw new RuntimeException(classInfo.name() + " should only extend REST Data Panache interface"); } if (!index.getKnownDirectImplementors(classInfo.name()).isEmpty()) { throw new RuntimeException(classInfo.name() + " should not be extended or implemented"); } }
Example 13
Source File: Serianalyzer.java From serianalyzer with GNU General Public License v3.0 | 5 votes |
/** * @param ci * @throws SerianalyzerException */ private void checkClass ( ClassInfo ci ) throws SerianalyzerException { DotName dname = ci.name(); String dnameString = dname.toString(); try ( InputStream data = this.input.getClassData(dnameString) ) { if ( data == null ) { log.error("No class data for " + dname); //$NON-NLS-1$ return; } boolean serializable = this.isTypeSerializable(this.getIndex(), dnameString); ClassReader cr = new ClassReader(data); if ( log.isTraceEnabled() ) { log.trace("Adding " + dnameString); //$NON-NLS-1$ } SerianalyzerClassSerializationVisitor visitor = new SerianalyzerClassSerializationVisitor(this, dnameString, serializable); cr.accept(visitor, 0); if ( serializable ) { ClassInfo classByName = this.input.getIndex().getClassByName(ci.superName()); if ( classByName == null ) { log.error("Failed to locate super class " + ci.superName()); //$NON-NLS-1$ return; } checkClass(classByName); } else if ( !visitor.isFoundDefaultConstructor() && log.isTraceEnabled() ) { log.trace("No default constructor found in first non-serializable parent " + dname); //$NON-NLS-1$ } } catch ( IOException e ) { throw new SerianalyzerException("Failed to read class data" + dname, e); //$NON-NLS-1$ } }
Example 14
Source File: CompositeIndex.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void getAllKnownSubClasses(DotName name, Set<ClassInfo> allKnown, Set<DotName> subClassesToProcess, Set<DotName> processedClasses) { for (Index index : indexes) { final List<ClassInfo> list = index.getKnownDirectSubclasses(name); if (list != null) { for (final ClassInfo clazz : list) { final DotName className = clazz.name(); if (!processedClasses.contains(className)) { allKnown.add(clazz); subClassesToProcess.add(className); } } } } }
Example 15
Source File: ResponseStatusOnExceptionGenerator.java From quarkus with Apache License 2.0 | 4 votes |
ResponseStatusOnExceptionGenerator(ClassInfo exceptionClassInfo, ClassOutput classOutput) { super(exceptionClassInfo.name(), classOutput); this.exceptionClassInfo = exceptionClassInfo; }
Example 16
Source File: AmazonLambdaProcessor.java From quarkus with Apache License 2.0 | 4 votes |
@BuildStep List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildItem, Optional<ProvidedAmazonLambdaHandlerBuildItem> providedLambda, BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer, BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy, BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer) throws BuildException { Collection<ClassInfo> allKnownImplementors = combinedIndexBuildItem.getIndex().getAllKnownImplementors(REQUEST_HANDLER); allKnownImplementors.addAll(combinedIndexBuildItem.getIndex() .getAllKnownImplementors(REQUEST_STREAM_HANDLER)); allKnownImplementors.addAll(combinedIndexBuildItem.getIndex() .getAllKnownSubclasses(SKILL_STREAM_HANDLER)); if (allKnownImplementors.size() > 0 && providedLambda.isPresent()) { throw new BuildException( "Multiple handler classes. You have a custom handler class and the " + providedLambda.get().getProvider() + " extension. Please remove one of them from your deployment.", Collections.emptyList()); } AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable(); List<AmazonLambdaBuildItem> ret = new ArrayList<>(); for (ClassInfo info : allKnownImplementors) { if (Modifier.isAbstract(info.flags())) { continue; } final DotName name = info.name(); final String lambda = name.toString(); builder.addBeanClass(lambda); reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(true, false, lambda)); String cdiName = null; AnnotationInstance named = info.classAnnotation(NAMED); if (named != null) { cdiName = named.value().asString(); } ClassInfo current = info; boolean done = false; boolean streamHandler = info.superName().equals(SKILL_STREAM_HANDLER) ? true : false; while (current != null && !done) { for (MethodInfo method : current.methods()) { if (method.name().equals("handleRequest")) { if (method.parameters().size() == 3) { streamHandler = true; done = true; break; } else if (method.parameters().size() == 2 && !method.parameters().get(0).name().equals(DotName.createSimple(Object.class.getName()))) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.parameters().get(0))); reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.returnType())); done = true; break; } } } current = combinedIndexBuildItem.getIndex().getClassByName(current.superName()); } ret.add(new AmazonLambdaBuildItem(lambda, cdiName, streamHandler)); } additionalBeanBuildItemBuildProducer.produce(builder.build()); reflectiveClassBuildItemBuildProducer .produce(new ReflectiveClassBuildItem(true, true, true, FunctionError.class)); return ret; }