Java Code Examples for org.jboss.jandex.Type#name()
The following examples show how to use
org.jboss.jandex.Type#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: CustomQueryMethodsAdder.java From quarkus with Apache License 2.0 | 6 votes |
private Type verifyQueryResultType(Type t) { if (isIntLongOrBoolean(t.name())) { return t; } if (t.kind() == Kind.ARRAY) { return verifyQueryResultType(t.asArrayType().component()); } else if (t.kind() == Kind.PARAMETERIZED_TYPE) { List<Type> list = t.asParameterizedType().arguments(); if (list.size() == 1) { return verifyQueryResultType(list.get(0)); } else { for (Type x : list) { verifyQueryResultType(x); } return t; } } else if (!DotNames.OBJECT.equals(t.name())) { ClassInfo typeClassInfo = index.getClassByName(t.name()); if (typeClassInfo == null) { throw new IllegalStateException(t.name() + " was not part of the Quarkus index"); } } return t; }
Example 2
Source File: JandexUtil.java From quarkus with Apache License 2.0 | 6 votes |
/** * Returns true if the given Jandex ClassInfo is a subclass of the given <tt>parentName</tt>. Note that this will * not check interfaces. * * @param index the index to use to look up super classes. * @param info the ClassInfo we want to check. * @param parentName the name of the superclass we want to find. * @return true if the given ClassInfo has <tt>parentName</tt> as a superclass. * @throws BuildException if one of the superclasses is not indexed. */ public static boolean isSubclassOf(IndexView index, ClassInfo info, DotName parentName) throws BuildException { if (info.superName().equals(DOTNAME_OBJECT)) { return false; } if (info.superName().equals(parentName)) { return true; } // climb up the hierarchy of classes Type superType = info.superClassType(); ClassInfo superClass = index.getClassByName(superType.name()); if (superClass == null) { // this can happens if the parent is not inside the Jandex index throw new BuildException("The class " + superType.name() + " is not inside the Jandex index", Collections.emptyList()); } return isSubclassOf(index, superClass, parentName); }
Example 3
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 5 votes |
public static DotName getName(Type type) { if (type.kind() == Type.Kind.ARRAY) { return type.asArrayType().component().name(); } if (type.kind() == Type.Kind.WILDCARD_TYPE) { return getBound(type.asWildcardType()).name(); } return type.name(); }
Example 4
Source File: AnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
default void processResponse(final AnnotationScannerContext context, final MethodInfo method, Operation operation, Map<DotName, AnnotationInstance> exceptionAnnotationMap) { List<AnnotationInstance> apiResponseAnnotations = ResponseReader.getResponseAnnotations(method); for (AnnotationInstance annotation : apiResponseAnnotations) { addApiReponseFromAnnotation(context, annotation, operation); } AnnotationInstance responseSchemaAnnotation = ResponseReader.getResponseSchemaAnnotation(method); addApiReponseSchemaFromAnnotation(context, responseSchemaAnnotation, method, operation); /* * If there is no response from annotations, try to create one from the method return value. * Do not generate a response if the app has used an empty @ApiResponses annotation. This * provides a way for the application to indicate that responses will be supplied some other * way (i.e. static file). */ AnnotationInstance apiResponses = ResponseReader.getResponsesAnnotation(method); if (apiResponses == null || !JandexUtil.isEmpty(apiResponses)) { createResponseFromRestMethod(context, method, operation); } //Add api response using list of exceptions in the methods and exception mappers List<Type> methodExceptions = method.exceptions(); for (Type type : methodExceptions) { DotName exceptionDotName = type.name(); if (exceptionAnnotationMap != null && !exceptionAnnotationMap.isEmpty() && exceptionAnnotationMap.keySet().contains(exceptionDotName)) { AnnotationInstance exMapperApiResponseAnnotation = exceptionAnnotationMap.get(exceptionDotName); if (!this.responseCodeExistInMethodAnnotations(exMapperApiResponseAnnotation, apiResponseAnnotations)) { addApiReponseFromAnnotation(context, exMapperApiResponseAnnotation, operation); } } } }
Example 5
Source File: Methods.java From quarkus with Apache License 2.0 | 5 votes |
static DotName toRawType(Type a) { switch (a.kind()) { case CLASS: case PRIMITIVE: case ARRAY: return a.name(); case PARAMETERIZED_TYPE: return a.asParameterizedType().name(); case TYPE_VARIABLE: case UNRESOLVED_TYPE_VARIABLE: case WILDCARD_TYPE: default: return DotNames.OBJECT; } }
Example 6
Source File: HibernateValidatorProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private static DotName getClassName(Type type) { switch (type.kind()) { case CLASS: case PARAMETERIZED_TYPE: return type.name(); case ARRAY: return getClassName(type.asArrayType().component()); default: return null; } }
Example 7
Source File: StringPropertyAccessorData.java From quarkus with Apache License 2.0 | 5 votes |
/** * Called with data parsed from a Spring expression like #person.name that is places inside a Spring security annotation on * a method */ static StringPropertyAccessorData from(MethodInfo methodInfo, int matchingParameterIndex, String propertyName, IndexView index, String expression) { Type matchingParameterType = methodInfo.parameters().get(matchingParameterIndex); ClassInfo matchingParameterClassInfo = index.getClassByName(matchingParameterType.name()); if (matchingParameterClassInfo == null) { throw new IllegalArgumentException( "Expression: '" + expression + "' in the @PreAuthorize annotation on method '" + methodInfo.name() + "' of class '" + methodInfo.declaringClass() + "' references class " + matchingParameterType.name() + " which could not be in Jandex"); } FieldInfo matchingParameterFieldInfo = matchingParameterClassInfo.field(propertyName); if (matchingParameterFieldInfo == null) { throw new IllegalArgumentException( "Expression: '" + expression + "' in the @PreAuthorize annotation on method '" + methodInfo.name() + "' of class '" + methodInfo.declaringClass() + "' references unknown property '" + propertyName + "' of class " + matchingParameterClassInfo); } if (!DotNames.STRING.equals(matchingParameterFieldInfo.type().name())) { throw new IllegalArgumentException( "Expression: '" + expression + "' in the @PreAuthorize annotation on method '" + methodInfo.name() + "' of class '" + methodInfo.declaringClass() + "' references property '" + propertyName + "' which is not a string"); } return new StringPropertyAccessorData(matchingParameterClassInfo, matchingParameterFieldInfo); }
Example 8
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 9
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; }