@Override public Type getValidatedValueType(final Type type) { return resolver.resolve(type) .typeParametersFor(AbstractParam.class).get(0) .getErasedType(); } }
boolean isMethodCorrect(ResolvedMethod m) { if (m.getReturnType()!=null) { log.error("The method {} is annotated with @SelfValidation but does not return void. It is ignored", m.getRawMember()); return false; } else if (m.getArgumentCount() != 1 || !m.getArgumentType(0).getErasedType().equals(ViolationCollector.class)) { log.error("The method {} is annotated with @SelfValidation but does not have a single parameter of type {}", m.getRawMember(), ViolationCollector.class); return false; } else if (!m.isPublic()) { log.error("The method {} is annotated with @SelfValidation but is not public", m.getRawMember()); return false; } return true; }
/** * This method generates <code>ValidationCaller</code>s for each method annotated * with <code>@SelfValidation</code> that adheres to required signature. */ @SuppressWarnings({ "rawtypes" }) private <T> List<ValidationCaller> findMethods(Class<T> annotated) { ResolvedTypeWithMembers annotatedType = memberResolver.resolve(typeResolver.resolve(annotated), annotationConfiguration, null); final List<ValidationCaller> callers = Arrays.stream(annotatedType.getMemberMethods()) .filter(this::isValidationMethod) .filter(this::isMethodCorrect) .map(m -> new ProxyValidationCaller<>(annotated, m)) .collect(Collectors.toList()); if (callers.isEmpty()) { log.warn("The class {} is annotated with @SelfValidating but contains no valid methods that are annotated " + "with @SelfValidation", annotated); } return callers; }
ResolvedType resolvedSubType = typeResolver.resolve(subTypeMethod.getDeclaringClass()); MemberResolver memberResolver = new MemberResolver(typeResolver); memberResolver.setMethodFilter(new SimpleMethodFilter(subTypeMethod, superTypeMethod)); final ResolvedTypeWithMembers typeWithMembers = memberResolver.resolve(resolvedSubType, null, null); ResolvedMethod[] resolvedMethods = new ResolvedMethod[0]; try { if (System.getSecurityManager() == null) { resolvedMethods = typeWithMembers.getMemberMethods(); } else { resolvedMethods = AccessController.doPrivileged(new PrivilegedExceptionAction<ResolvedMethod[]>() { for (int i = 0; i < resolvedMethods[0].getArgumentCount(); i++) if (!resolvedMethods[0].getArgumentType(i).equals(resolvedMethods[1].getArgumentType(i)))
final ReflectionManager reflectionManager = buildingContext.getBootstrapContext().getReflectionManager(); final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve( reflectionManager.toClass( xProperty.getDeclaringClass() ) ); final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve( declaringClassType, null, for ( ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods() ) { if ( resolvedMember.getName().equals( member.getName() ) ) { return resolvedMember; for ( ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields() ) { if ( resolvedMember.getName().equals( member.getName() ) ) { return resolvedMember;
case SUB_RESOURCE_LOCATOR: final ResolvedType responseType = TYPE_RESOLVER .resolve(method.getInvocable().getResponseType()); final Class<?> erasedType = !responseType.getTypeBindings().isEmpty() ? responseType.getTypeBindings().getBoundType(0).getErasedType() : responseType.getErasedType();
public class OptionalValidatedValueUnwrapper extends ValidatedValueUnwrapper<Optional<?>> { private final TypeResolver resolver = new TypeResolver(); @Override public Object handleValidatedValue(final Optional<?> optional) { return optional.orNull(); } @Override public Type getValidatedValueType(final Type type) { ResolvedType resolvedType = resolver.resolve(type); return resolvedType.typeParametersFor(Optional.class).get(0).getErasedType(); } }
@SuppressWarnings("WeakerAccess") public AbstractConverterDescriptor( Class<? extends AttributeConverter> converterClass, Boolean forceAutoApply, ClassmateContext classmateContext) { this.converterClass = converterClass; final ResolvedType converterType = classmateContext.getTypeResolver().resolve( converterClass ); final List<ResolvedType> converterParamTypes = converterType.typeParametersFor( AttributeConverter.class ); if ( converterParamTypes == null ) { throw new AnnotationException( "Could not extract type parameter information from AttributeConverter implementation [" + converterClass.getName() + "]" ); } else if ( converterParamTypes.size() != 2 ) { throw new AnnotationException( "Unexpected type parameter information for AttributeConverter implementation [" + converterClass.getName() + "]; expected 2 parameter types, but found " + converterParamTypes.size() ); } this.domainType = converterParamTypes.get( 0 ); this.jdbcType = converterParamTypes.get( 1 ); this.autoApplicableDescriptor = resolveAutoApplicableDescriptor( converterClass, forceAutoApply ); }
@Bean public Docket configure(SwaggerApiInfo info, TypeResolver typeResolver) { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.github.prontera")) .paths(PathSelectors.any()) .build() .pathMapping("/") .useDefaultResponseMessages(false) .globalResponseMessage(RequestMethod.OPTIONS, info.getStatusList()) .apiInfo(new ApiInfo(info.getTitle(), DESCRIPTION, info.getVersion(), info.getServiceUrl(), new Contact(null, null, null), null, null)) .alternateTypeRules( AlternateTypeRules.newRule( typeResolver.resolve(PageInfo.class, WildcardType.class), typeResolver.resolve(SwaggerPaginationResponse.class, WildcardType.class)), AlternateTypeRules.newRule( typeResolver.resolve(Collection.class, WildcardType.class), typeResolver.resolve(List.class, WildcardType.class)) ) //.enableUrlTemplating(true) .forCodeGeneration(false); }
@Override public ConverterDescriptor getAutoAppliedConverterDescriptorForCollectionElement( XProperty xProperty, MetadataBuildingContext context) { final ResolvedMember collectionMember = resolveMember( xProperty, context ); final ResolvedType elementType; if ( Map.class.isAssignableFrom( collectionMember.getType().getErasedType() ) ) { elementType = collectionMember.getType().typeParametersFor( Map.class ).get( 1 ); } else if ( Collection.class.isAssignableFrom( collectionMember.getType().getErasedType() ) ) { elementType = collectionMember.getType().typeParametersFor( Collection.class ).get( 0 ); } else { throw new HibernateException( "Attribute was neither a Collection nor a Map : " + collectionMember.getType().getErasedType() ); } return typesMatch( linkedConverterDescriptor.getDomainValueResolvedType(), elementType ) ? linkedConverterDescriptor : null; }
private boolean typesMatch(ResolvedType converterDefinedType, ResolvedType checkType) { if ( !converterDefinedType.getErasedType().isAssignableFrom( checkType.getErasedType() ) ) { return false; if ( converterDefinedType.getTypeParameters().isEmpty() ) { return true; if ( checkType.getTypeParameters().isEmpty() ) { if ( converterDefinedType.getTypeParameters().size() != checkType.getTypeParameters().size() ) { for ( int i = 0; i < converterDefinedType.getTypeParameters().size(); i++ ) { if ( !typesMatch( converterDefinedType.getTypeParameters().get( i ), checkType.getTypeParameters().get( i ) ) ) { return false;
@Override @SuppressWarnings("unchecked") public JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { return new JpaAttributeConverterImpl( createManagedBean( context ), context.getJavaTypeDescriptorRegistry().getDescriptor( getAttributeConverterClass() ), context.getJavaTypeDescriptorRegistry().getDescriptor( getDomainValueResolvedType().getErasedType() ), context.getJavaTypeDescriptorRegistry().getDescriptor( getRelationalValueResolvedType().getErasedType() ) ); }
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }
@Override public ResolvedMethod[] run() throws Exception { return typeWithMembers.getMemberMethods(); } });
"Checking auto-apply AttributeConverter [%s] (domain-type=%s) for match against %s : %s.%s (type=%s)", descriptor.getAttributeConverterClass().getName(), descriptor.getDomainValueResolvedType().getSignature(), conversionSite.getSiteDescriptor(), xProperty.getDeclaringClass().getName(),
@Override public Type getValidatedValueType(final Type type) { final ResolvedType resolvedType = resolver.resolve(type); return resolvedType.typeParametersFor(Optional.class).get(0).getErasedType(); } }
@Bean public Docket swaggerSpringMvcPlugin() { return new Docket(DocumentationType.SWAGGER_2) .groupName("business-api") .select() .apis(RequestHandlerSelectors.basePackage(App.class.getPackage().getName())) .paths(PathSelectors.any()) .build() .pathMapping("/") .genericModelSubstitutes(ResponseEntity.class) .alternateTypeRules(newRule(typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)), typeResolver.resolve(WildcardType.class))) // .enableUrlTemplating(true) .useDefaultResponseMessages(true) .forCodeGeneration(false) .host(host()) .apiInfo(apiInfo()); }
@Override public ConverterDescriptor getAutoAppliedConverterDescriptorForMapKey( XProperty xProperty, MetadataBuildingContext context) { final ResolvedMember collectionMember = resolveMember( xProperty, context ); final ResolvedType keyType; if ( Map.class.isAssignableFrom( collectionMember.getType().getErasedType() ) ) { keyType = collectionMember.getType().typeParametersFor( Map.class ).get( 0 ); } else { throw new HibernateException( "Attribute was not a Map : " + collectionMember.getType().getErasedType() ); } return typesMatch( linkedConverterDescriptor.getDomainValueResolvedType(), keyType ) ? linkedConverterDescriptor : null; }
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }
private static boolean typeBindingsAreOfSameSize(ResolvedType toMatch, ResolvedType wildcardType) { TypeBindings wildcardTypeBindings = wildcardType.getTypeBindings(); TypeBindings bindingsToMatch = toMatch.getTypeBindings(); return bindingsToMatch.size() == wildcardTypeBindings.size(); }