/** * Returns the annotated {@link Class} that was used to construct the {@code declaration}. * <p/> * The annotated type is determined by querying the {@code declaration} for the {@link ImplementingTypeModelProperty} model * property * * @param declaration a {@link BaseDeclaration} to be enriched * @return a {@link Class} or {@code null} if the model doesn't have a {@link ImplementingTypeModelProperty} */ protected Optional<ImplementingTypeModelProperty> extractImplementingTypeProperty( BaseDeclaration<? extends BaseDeclaration> declaration) { return declaration.getModelProperty(ImplementingTypeModelProperty.class); }
/** * @param declaration a {@link BaseDeclaration} * @return The type from which the {@code declaration} was derived or {@link Optional#empty()} if it couldn't * be determined or the declaration is synthetic */ protected Optional<Type> extractType(BaseDeclaration<? extends BaseDeclaration> declaration) { return declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class) .map(ExtensionTypeDescriptorModelProperty::getType); } }
private <P extends ModelProperty> void enrich(BaseDeclaration declaration, Class<P> propertyType, BiConsumer<BaseDeclaration, P> consumer) { declaration.getModelProperty(propertyType).ifPresent(p -> consumer.accept(declaration, (P) p)); }
private Optional<Deprecated> getDeprecatedAnnotation(BaseDeclaration<?> declaration, Class<? extends ModelProperty> modelPropertyClass) { Optional<? extends ModelProperty> modelProperty = declaration.getModelProperty(modelPropertyClass); if (modelProperty.isPresent()) { return modelPropertiesClasses.get(modelPropertyClass).apply(modelProperty.get()); } else { return empty(); } }
public static String getMemberName(BaseDeclaration<?> declaration, String defaultName) { return declaration.getModelProperty(DeclaringMemberModelProperty.class).map(p -> p.getDeclaringField().getName()) .orElse(defaultName); }
public static java.util.Optional<AnnotatedElement> getAnnotatedElement(BaseDeclaration<?> declaration) { final java.util.Optional<DeclaringMemberModelProperty> declaringMember = declaration.getModelProperty(DeclaringMemberModelProperty.class); final java.util.Optional<ImplementingParameterModelProperty> implementingParameter = declaration.getModelProperty(ImplementingParameterModelProperty.class); AnnotatedElement annotatedElement = null; if (declaringMember.isPresent()) { annotatedElement = declaringMember.get().getDeclaringField(); } if (implementingParameter.isPresent()) { annotatedElement = implementingParameter.get().getParameter(); } return java.util.Optional.ofNullable(annotatedElement); }
private static InterceptorsModelProperty getOrCreateInterceptorModelProperty(BaseDeclaration declaration) { InterceptorsModelProperty property = (InterceptorsModelProperty) declaration.getModelProperty(InterceptorsModelProperty.class).orElse(null); if (property == null) { property = new InterceptorsModelProperty(emptyList()); declaration.addModelProperty(property); } return property; }
private void doEnrich(BaseDeclaration<?> declaration) { declaration.getModelProperty(ImplementingTypeModelProperty.class).ifPresent(typeProperty -> { Collection<Field> fields = getAllFields(typeProperty.getType(), withAnnotation(RefName.class)); if (isEmpty(fields)) { return; } if (fields.size() > 1) { throw new IllegalConfigurationModelDefinitionException(String .format("Only one field is allowed to be annotated with @%s, but class '%s' has %d fields " + "with such annotation. Offending fields are: [%s]", RefName.class.getSimpleName(), typeProperty.getType() .getName(), fields.size(), Joiner.on(", ").join(fields.stream().map(Field::getName).collect(toList())))); } final Field configNameField = fields.iterator().next(); if (!String.class.equals(configNameField.getType())) { throw new IllegalConfigurationModelDefinitionException(String .format("Class '%s' declares the field '%s' which is annotated with @%s and is of type '%s'. Only " + "fields of type String are allowed to carry such annotation", typeProperty.getType().getName(), configNameField.getName(), RefName.class.getSimpleName(), configNameField.getType().getName())); } declaration.addModelProperty(new RequireNameField(configNameField)); }); } }
private void doEnrich(BaseDeclaration declaration) { declaration.getModelProperty(ImplementingTypeModelProperty.class).ifPresent(p -> { ImplementingTypeModelProperty typeProperty = (ImplementingTypeModelProperty) p; Collection<Field> fields = getAllFields(typeProperty.getType(), withAnnotation(DefaultEncoding.class));
private void mockMediaType(BaseDeclaration declaration, boolean strict) { when(declaration.getModelProperty(MediaTypeModelProperty.class)).thenReturn(of( new MediaTypeModelProperty(TEXT_PLAIN, strict))); }
static <T extends ModelProperty> T checkIsPresent(BaseDeclaration declaration, Class<T> modelProperty) { final Optional<T> property = declaration.getModelProperty(modelProperty); assertThat(property.isPresent(), is(true)); return property.get(); }
private void mockImplementingProperty(BaseDeclaration declaration, Class<?> type) { ImplementingTypeModelProperty property = type != null ? new ImplementingTypeModelProperty(type) : null; when(declaration.getModelProperty(ImplementingTypeModelProperty.class)).thenReturn(Optional.ofNullable(property)); }
private void enrichTypes(BaseDeclaration declaration) { final Optional<ImplementingTypeModelProperty> modelProperty = declaration.getModelProperty(ImplementingTypeModelProperty.class); if (modelProperty.isPresent()) { final Class<?> annotatedType = modelProperty.get().getType(); final Summary summaryAnnotation = getAnnotation(annotatedType, Summary.class); final DisplayName displayNameAnnotation = getAnnotation(annotatedType, DisplayName.class); final Example exampleAnnotation = getAnnotation(annotatedType, Example.class); final Path pathAnnotation = getAnnotation(annotatedType, Path.class); final ClassValue classAnnotation = getAnnotation(annotatedType, ClassValue.class); createDisplayModelProperty(declaration, summaryAnnotation, displayNameAnnotation, exampleAnnotation, pathAnnotation, classAnnotation); } }
if (declarer.getDeclaration().getModelProperty(ParameterGroupModelProperty.class).isPresent()) { throw new IllegalParameterModelDefinitionException(format("Parameter group '%s' has already been declared on %s '%s'", groupName,
/** * Returns the annotated {@link Class} that was used to construct the {@code declaration}. * <p/> * The annotated type is determined by querying the {@code declaration} for the {@link ImplementingTypeModelProperty} model * property * * @param declaration a {@link BaseDeclaration} to be enriched * @return a {@link Class} or {@code null} if the model doesn't have a {@link ImplementingTypeModelProperty} */ protected Optional<ImplementingTypeModelProperty> extractImplementingTypeProperty( BaseDeclaration<? extends BaseDeclaration> declaration) { return declaration.getModelProperty(ImplementingTypeModelProperty.class); }
/** * @param declaration a {@link BaseDeclaration} * @return The type from which the {@code declaration} was derived or {@link Optional#empty()} if it couldn't * be determined or the declaration is synthetic */ protected Optional<Type> extractType(BaseDeclaration<? extends BaseDeclaration> declaration) { return declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class) .map(ExtensionTypeDescriptorModelProperty::getType); } }
private <P extends ModelProperty> void enrich(BaseDeclaration declaration, Class<P> propertyType, BiConsumer<BaseDeclaration, P> consumer) { declaration.getModelProperty(propertyType).ifPresent(p -> consumer.accept(declaration, (P) p)); }
public static String getMemberName(BaseDeclaration<?> declaration, String defaultName) { return declaration.getModelProperty(DeclaringMemberModelProperty.class).map(p -> p.getDeclaringField().getName()) .orElse(defaultName); }
private static InterceptorsModelProperty getOrCreateInterceptorModelProperty(BaseDeclaration declaration) { InterceptorsModelProperty property = (InterceptorsModelProperty) declaration.getModelProperty(InterceptorsModelProperty.class).orElse(null); if (property == null) { property = new InterceptorsModelProperty(emptyList()); declaration.addModelProperty(property); } return property; }
private void enrichTypes(BaseDeclaration declaration) { final Optional<ImplementingTypeModelProperty> modelProperty = declaration.getModelProperty(ImplementingTypeModelProperty.class); if (modelProperty.isPresent()) { final Class<?> annotatedType = modelProperty.get().getType(); final Summary summaryAnnotation = getAnnotation(annotatedType, Summary.class); final DisplayName displayNameAnnotation = getAnnotation(annotatedType, DisplayName.class); final Example exampleAnnotation = getAnnotation(annotatedType, Example.class); final Path pathAnnotation = getAnnotation(annotatedType, Path.class); final ClassValue classAnnotation = getAnnotation(annotatedType, ClassValue.class); createDisplayModelProperty(declaration, summaryAnnotation, displayNameAnnotation, exampleAnnotation, pathAnnotation, classAnnotation); } }