Java Code Examples for org.jboss.jandex.DotName#equals()
The following examples show how to use
org.jboss.jandex.DotName#equals() .
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 |
@Override public Collection<ClassInfo> getKnownDirectImplementors(DotName className) { if (additionalClasses.isEmpty()) { return index.getKnownDirectImplementors(className); } Set<ClassInfo> directImplementors = new HashSet<ClassInfo>(index.getKnownDirectImplementors(className)); for (Optional<ClassInfo> additional : additionalClasses.values()) { if (!additional.isPresent()) { continue; } for (Type interfaceType : additional.get().interfaceTypes()) { if (className.equals(interfaceType.name())) { directImplementors.add(additional.get()); break; } } } return directImplementors; }
Example 2
Source File: Beans.java From quarkus with Apache License 2.0 | 6 votes |
private static ScopeInfo inheritScope(ClassInfo beanClass, BeanDeployment beanDeployment) { DotName superClassName = beanClass.superName(); while (!superClassName.equals(DotNames.OBJECT)) { ClassInfo classFromIndex = getClassByName(beanDeployment.getIndex(), superClassName); if (classFromIndex == null) { // class not in index LOGGER.warnf("Unable to determine scope for bean %s using inheritance because its super class " + "%s is not part of Jandex index. Dependent scope will be used instead.", beanClass, superClassName); return null; } for (AnnotationInstance annotation : beanDeployment.getAnnotationStore().getAnnotations(classFromIndex)) { ScopeInfo scopeAnnotation = beanDeployment.getScope(annotation.name()); if (scopeAnnotation != null && scopeAnnotation.declaresInherited()) { // found some scope, return return scopeAnnotation; } } superClassName = classFromIndex.superName(); } // none found return null; }
Example 3
Source File: ResteasyCommonProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private static boolean collectDeclaredProvidersForMethodAndMediaTypeAnnotation(Set<String> providersToRegister, MediaTypeMap<String> categorizedProviders, MethodInfo methodTarget, DotName mediaTypeAnnotation, boolean defaultsToAll) { AnnotationInstance mediaTypeAnnotationInstance = methodTarget.annotation(mediaTypeAnnotation); if (mediaTypeAnnotationInstance == null) { // let's consider the class Collection<AnnotationInstance> classAnnotations = methodTarget.declaringClass().classAnnotations(); for (AnnotationInstance classAnnotation : classAnnotations) { if (mediaTypeAnnotation.equals(classAnnotation.name())) { if (collectDeclaredProvidersForMediaTypeAnnotationInstance(providersToRegister, categorizedProviders, classAnnotation, methodTarget)) { return true; } return false; } } return defaultsToAll; } if (collectDeclaredProvidersForMediaTypeAnnotationInstance(providersToRegister, categorizedProviders, mediaTypeAnnotationInstance, methodTarget)) { return true; } return false; }
Example 4
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 5
Source File: Types.java From quarkus with Apache License 2.0 | 6 votes |
static boolean isAssignableFrom(DotName class1, DotName class2, IndexView index) { // java.lang.Object is assignable from any type if (class1.equals(DotNames.OBJECT)) { return true; } // type1 is the same as type2 if (class1.equals(class2)) { return true; } // type1 is a superclass Set<DotName> assignables = new HashSet<>(); Collection<ClassInfo> subclasses = index.getAllKnownSubclasses(class1); for (ClassInfo subclass : subclasses) { assignables.add(subclass.name()); } Collection<ClassInfo> implementors = index.getAllKnownImplementors(class1); for (ClassInfo implementor : implementors) { assignables.add(implementor.name()); } return assignables.contains(class2); }
Example 6
Source File: PanacheRepositoryEnhancer.java From quarkus with Apache License 2.0 | 6 votes |
public static String[] recursivelyFindEntityTypeArgumentsFromClass(IndexView indexView, DotName clazz, DotName repositoryDotName) { if (clazz.equals(JandexUtil.DOTNAME_OBJECT)) { return null; } List<org.jboss.jandex.Type> typeParameters = JandexUtil .resolveTypeParameters(clazz, repositoryDotName, indexView); if (typeParameters.isEmpty()) throw new IllegalStateException( "Failed to find supertype " + repositoryDotName + " from entity class " + clazz); org.jboss.jandex.Type entityType = typeParameters.get(0); org.jboss.jandex.Type idType = typeParameters.get(1); return new String[] { entityType.name().toString().replace('.', '/'), idType.name().toString().replace('.', '/') }; }
Example 7
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 8
Source File: VertxWebProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private void validateRouteMethod(BeanInfo bean, MethodInfo method, DotName[] validParamTypes) { if (!method.returnType().kind().equals(Type.Kind.VOID)) { throw new IllegalStateException( String.format("Route handler business method must return void [method: %s, bean: %s]", method, bean)); } List<Type> params = method.parameters(); boolean hasInvalidParam = true; if (params.size() == 1) { DotName paramTypeName = params.get(0).name(); for (DotName type : validParamTypes) { if (type.equals(paramTypeName)) { hasInvalidParam = false; } } } if (hasInvalidParam) { throw new IllegalStateException(String.format( "Route business method must accept exactly one parameter of type %s: %s [method: %s, bean: %s]", validParamTypes, params, method, bean)); } }
Example 9
Source File: JandexBeanInfoAdapter.java From quarkus with Apache License 2.0 | 5 votes |
@Override public BeanInfo convert(ClassInfo input) { BeanInfo superClassInfo = null; DotName superName = input.superName(); if (superName != null && indexView.getClassByName(superName) != null && !superName.equals(OBJECT)) { superClassInfo = this.convert(indexView.getClassByName(superName)); } JandexAnnotationInfoAdapter annotationInfoAdapter = new JandexAnnotationInfoAdapter(indexView); // add all class-level annotations, including inherited - SmallRye expects them here List<AnnotationInfo> annotations = new ArrayList<>(); ClassInfo clazz = input; while (clazz != null && clazz.superName() != null) { List<AnnotationInfo> annotationsSuper = clazz.classAnnotations() .stream() .filter(SmallRyeMetricsDotNames::isMetricAnnotation) .map(annotationInfoAdapter::convert) .collect(Collectors.toList()); annotations.addAll(annotationsSuper); // a metric annotation can also be added through a CDI stereotype, so look into stereotypes List<AnnotationInfo> annotationsThroughStereotypes = clazz.classAnnotations() .stream() .flatMap(a -> getMetricAnnotationsThroughStereotype(a, indexView)) .collect(Collectors.toList()); annotations.addAll(annotationsThroughStereotypes); clazz = indexView.getClassByName(clazz.superName()); } return new RawBeanInfo(input.simpleName(), input.name().prefix().toString(), annotations, superClassInfo); }
Example 10
Source File: ResteasyCommonProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private Set<String> getUserSuppliedJsonProducerBeans(IndexView index, DotName jsonImplementation) { Set<String> result = new HashSet<>(); for (AnnotationInstance annotation : index.getAnnotations(DotNames.PRODUCES)) { if (annotation.target().kind() != AnnotationTarget.Kind.METHOD) { continue; } if (jsonImplementation.equals(annotation.target().asMethod().returnType().name())) { result.add(annotation.target().asMethod().declaringClass().name().toString()); } } return result; }
Example 11
Source File: BeanArchives.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Collection<ClassInfo> getKnownDirectSubclasses(DotName className) { if (additionalClasses.isEmpty()) { return index.getKnownDirectSubclasses(className); } Set<ClassInfo> directSubclasses = new HashSet<ClassInfo>(index.getKnownDirectSubclasses(className)); for (Optional<ClassInfo> additional : additionalClasses.values()) { if (additional.isPresent() && className.equals(additional.get().superName())) { directSubclasses.add(additional.get()); } } return directSubclasses; }
Example 12
Source File: SmallRyeFaultToleranceProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private boolean hasFTAnnotations(IndexView index, AnnotationStore annotationStore, ClassInfo info) { if (info == null) { //should not happen, but guard against it //happens in this case due to a bug involving array types return false; } // first check annotations on type if (annotationStore.hasAnyAnnotation(info, FT_ANNOTATIONS)) { return true; } // then check on the methods for (MethodInfo method : info.methods()) { if (annotationStore.hasAnyAnnotation(method, FT_ANNOTATIONS)) { return true; } } // then check on the parent DotName parentClassName = info.superName(); if (parentClassName == null || parentClassName.equals(DotNames.OBJECT)) { return false; } ClassInfo parentClassInfo = index.getClassByName(parentClassName); if (parentClassInfo == null) { return false; } return hasFTAnnotations(index, annotationStore, parentClassInfo); }
Example 13
Source File: SpringDataRepositoryCreator.java From quarkus with Apache License 2.0 | 5 votes |
private Map.Entry<DotName, DotName> extractIdAndEntityTypes(ClassInfo repositoryToImplement) { DotName entityDotName = null; DotName idDotName = null; // we need to pull the entity and ID types for the Spring Data generic types // we also need to make sure that the user didn't try to specify multiple different types // in the same interface (which is possible if only Repository is used) for (DotName extendedSpringDataRepo : GenerationUtil.extendedSpringDataRepos(repositoryToImplement)) { List<Type> types = JandexUtil.resolveTypeParameters(repositoryToImplement.name(), extendedSpringDataRepo, index); if (!(types.get(0) instanceof ClassType)) { throw new IllegalArgumentException( "Entity generic argument of " + repositoryToImplement + " is not a regular class type"); } DotName newEntityDotName = types.get(0).name(); if ((entityDotName != null) && !newEntityDotName.equals(entityDotName)) { throw new IllegalArgumentException("Repository " + repositoryToImplement + " specifies multiple Entity types"); } entityDotName = newEntityDotName; DotName newIdDotName = types.get(1).name(); if ((idDotName != null) && !newIdDotName.equals(idDotName)) { throw new IllegalArgumentException("Repository " + repositoryToImplement + " specifies multiple ID types"); } idDotName = newIdDotName; } if (idDotName == null || entityDotName == null) { throw new IllegalArgumentException( "Repository " + repositoryToImplement + " does not specify ID and/or Entity type"); } return new AbstractMap.SimpleEntry<>(idDotName, entityDotName); }
Example 14
Source File: BuiltinBean.java From quarkus with Apache License 2.0 | 5 votes |
private static boolean isCdiAndRawTypeMatches(InjectionPointInfo injectionPoint, DotName... rawTypeDotNames) { if (injectionPoint.getKind() != InjectionPointKind.CDI) { return false; } for (DotName rawTypeDotName : rawTypeDotNames) { if (rawTypeDotName.equals(injectionPoint.getRequiredType().name())) { return true; } } return false; }
Example 15
Source File: QuarkusSecurityJpaProcessor.java From quarkus with Apache License 2.0 | 4 votes |
private void setupRoles(Index index, JpaSecurityDefinition jpaSecurityDefinition, Set<String> panacheClasses, String name, MethodCreator methodCreator, AssignableResultHandle userVar, AssignableResultHandle builderVar) { ResultHandle role = jpaSecurityDefinition.roles.readValue(methodCreator, userVar); // role: user.getRole() boolean handledRole = false; Type rolesType = jpaSecurityDefinition.roles.type(); switch (rolesType.kind()) { case ARRAY: // FIXME: support non-JPA-backed array roles? break; case CLASS: if (rolesType.name().equals(DOTNAME_STRING)) { // addRoles(builder, :role) methodCreator.invokeVirtualMethod( MethodDescriptor.ofMethod(name, "addRoles", void.class, QuarkusSecurityIdentity.Builder.class, String.class), methodCreator.getThis(), builderVar, role); handledRole = true; } break; case PARAMETERIZED_TYPE: DotName roleType = rolesType.name(); if (roleType.equals(DOTNAME_LIST) || roleType.equals(DOTNAME_COLLECTION) || roleType.equals(DOTNAME_SET)) { Type elementType = rolesType.asParameterizedType().arguments().get(0); String elementClassName = elementType.name().toString(); String elementClassTypeDescriptor = "L" + elementClassName.replace('.', '/') + ";"; FieldOrMethod rolesFieldOrMethod; if (!elementType.name().equals(DOTNAME_STRING)) { ClassInfo roleClass = index.getClassByName(elementType.name()); if (roleClass == null) { throw new RuntimeException( "The role element type must be indexed by Jandex: " + elementType); } AnnotationTarget annotatedRolesValue = getSingleAnnotatedElement(index, DOTNAME_ROLES_VALUE); rolesFieldOrMethod = JpaSecurityDefinition.getFieldOrMethod(index, roleClass, annotatedRolesValue, isPanache(roleClass, panacheClasses)); if (rolesFieldOrMethod == null) { throw new RuntimeException( "Missing @RoleValue annotation on (non-String) role element type: " + elementType); } } else { rolesFieldOrMethod = null; } // for(:elementType roleElement : :role){ // ret.addRoles(:role.roleField); // // or for String collections: // ret.addRoles(:role); // } foreach(methodCreator, role, elementClassTypeDescriptor, (creator, var) -> { ResultHandle roleElement; if (rolesFieldOrMethod != null) { roleElement = rolesFieldOrMethod.readValue(creator, var); } else { roleElement = var; } creator.invokeVirtualMethod( MethodDescriptor.ofMethod(name, "addRoles", void.class, QuarkusSecurityIdentity.Builder.class, String.class), methodCreator.getThis(), builderVar, roleElement); }); handledRole = true; } break; } if (!handledRole) { throw new RuntimeException("Unsupported @Roles field/getter type: " + rolesType); } // return builder.build() methodCreator.returnValue(methodCreator.invokeVirtualMethod( MethodDescriptor.ofMethod(QuarkusSecurityIdentity.Builder.class, "build", QuarkusSecurityIdentity.class), builderVar)); }
Example 16
Source File: ValueResolverGenerator.java From quarkus with Apache License 2.0 | 4 votes |
public void generate(ClassInfo clazz) { Objects.requireNonNull(clazz); String clazzName = clazz.name().toString(); if (analyzedTypes.contains(clazzName)) { return; } analyzedTypes.add(clazzName); boolean ignoreSuperclasses = false; // @TemplateData declared on class takes precedence AnnotationInstance templateData = clazz.classAnnotation(TEMPLATE_DATA); if (templateData == null) { // Try to find @TemplateData declared on other classes templateData = uncontrolled.get(clazz.name()); } else { AnnotationValue ignoreSuperclassesValue = templateData.value(IGNORE_SUPERCLASSES); if (ignoreSuperclassesValue != null) { ignoreSuperclasses = ignoreSuperclassesValue.asBoolean(); } } Predicate<AnnotationTarget> filters = initFilters(templateData); LOGGER.debugf("Analyzing %s", clazzName); String baseName; if (clazz.enclosingClass() != null) { baseName = simpleName(clazz.enclosingClass()) + NESTED_SEPARATOR + simpleName(clazz); } else { baseName = simpleName(clazz); } String targetPackage = packageName(clazz.name()); String generatedName = generatedNameFromTarget(targetPackage, baseName, SUFFIX); generatedTypes.add(generatedName.replace('/', '.')); ClassCreator valueResolver = ClassCreator.builder().classOutput(classOutput).className(generatedName) .interfaces(ValueResolver.class).build(); implementGetPriority(valueResolver); implementAppliesTo(valueResolver, clazz); implementResolve(valueResolver, clazzName, clazz, filters); valueResolver.close(); DotName superName = clazz.superName(); if (!ignoreSuperclasses && (superName != null && !superName.equals(OBJECT))) { ClassInfo superClass = index.getClassByName(clazz.superClassType().name()); if (superClass != null) { generate(superClass); } else { LOGGER.warnf("Skipping super class %s - not found in the index", clazz.superClassType()); } } }
Example 17
Source File: ResteasyServerCommonProcessor.java From quarkus with Apache License 2.0 | 4 votes |
private Set<DotName> findSubresources(IndexView index, Map<DotName, ClassInfo> scannedResources) { // First identify sub-resource candidates Set<DotName> subresources = new HashSet<>(); for (DotName annotation : METHOD_ANNOTATIONS) { Collection<AnnotationInstance> annotationInstances = index.getAnnotations(annotation); for (AnnotationInstance annotationInstance : annotationInstances) { DotName declaringClassName = annotationInstance.target().asMethod().declaringClass().name(); if (scannedResources.containsKey(declaringClassName)) { // Skip resource classes continue; } subresources.add(declaringClassName); } } if (!subresources.isEmpty()) { // Collect sub-resource locator return types Set<DotName> subresourceLocatorTypes = new HashSet<>(); for (ClassInfo resourceClass : scannedResources.values()) { ClassInfo clazz = resourceClass; while (clazz != null) { for (MethodInfo method : clazz.methods()) { if (method.hasAnnotation(ResteasyDotNames.PATH)) { subresourceLocatorTypes.add(method.returnType().name()); } } if (clazz.superName().equals(DotNames.OBJECT)) { clazz = null; } else { clazz = index.getClassByName(clazz.superName()); } } } // Remove false positives for (Iterator<DotName> iterator = subresources.iterator(); iterator.hasNext();) { DotName subresource = iterator.next(); for (DotName type : subresourceLocatorTypes) { // Sub-resource may be a subclass of a locator return type if (!subresource.equals(type) && index.getAllKnownSubclasses(type).stream().noneMatch(c -> c.name().equals(subresource))) { iterator.remove(); break; } } } } log.trace("Sub-resources found: " + subresources); return subresources; }
Example 18
Source File: ReflectiveHierarchyIgnoreWarningBuildItem.java From quarkus with Apache License 2.0 | 4 votes |
@Override public boolean test(DotName input) { return input.equals(dotName); }
Example 19
Source File: JandexUtil.java From quarkus with Apache License 2.0 | 4 votes |
/** * Finds the type arguments passed from the starting type to the given target type, mapping * generics when found, on the way down. Returns null if not found. */ private static List<Type> findParametersRecursively(Type type, DotName target, Set<DotName> visitedTypes, IndexView index) { DotName name = type.name(); // cache results first if (!visitedTypes.add(name)) { return null; } // always end at Object if (DOTNAME_OBJECT.equals(name)) { return null; } final ClassInfo inputClassInfo = fetchFromIndex(name, index); // look at the current type if (target.equals(name)) { Type thisType = getType(inputClassInfo, index); if (thisType.kind() == Kind.CLASS) return Collections.emptyList(); else return thisType.asParameterizedType().arguments(); } // superclasses first Type superClassType = inputClassInfo.superClassType(); List<Type> superResult = findParametersRecursively(superClassType, target, visitedTypes, index); if (superResult != null) { // map any returned type parameters to our type arguments on the way down return mapTypeArguments(superClassType, superResult, index); } // interfaces second for (Type interfaceType : inputClassInfo.interfaceTypes()) { List<Type> ret = findParametersRecursively(interfaceType, target, visitedTypes, index); if (ret != null) { // map any returned type parameters to our type arguments on the way down return mapTypeArguments(interfaceType, ret, index); } } // not found return null; }