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; }
/** * 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); }
private void enrich(BaseDeclaration declaration, WithParameters methodWrapper) { final List<ExtensionParameter> configParameters = methodWrapper.getParametersAnnotatedWith(Config.class); if (!configParameters.isEmpty()) { configParameters.get(0).getType().getDeclaringClass() .ifPresent(declaringClass -> declaration.addModelProperty(new ConfigTypeModelProperty(declaringClass))); } } }
declaration.setDisplayModel(DisplayModel.builder() .displayName(displayName) .summary(summary)
/** * @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 <T extends BaseDeclaration & WithParametersDeclaration> void registerRequiredParametersForMetadata(T declaration) { List<String> parametersRequiredForMetadata = getParametersNameRequiredForMetadata(declaration); if (!parametersRequiredForMetadata.isEmpty()) { declaration.addModelProperty(new RequiredForMetadataModelProperty(getParametersNameRequiredForMetadata(declaration))); } }
declaration.setDisplayModel(DisplayModel.builder() .displayName(displayName) .summary(summary)
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 <P extends ModelProperty> void enrich(BaseDeclaration declaration, Class<P> propertyType, BiConsumer<BaseDeclaration, P> consumer) { declaration.getModelProperty(propertyType).ifPresent(p -> consumer.accept(declaration, (P) p)); }
/** * Enriches the {@link ParameterDeclarer} with a {@link MetadataKeyPartModelProperty} * if the parsedParameter is annotated either as {@link MetadataKeyId} or {@link MetadataKeyPart} * * @param element the method annotated parameter parsed * @param baseDeclaration the {@link ParameterDeclarer} associated to the parsed parameter */ private void parseMetadataKeyAnnotations(ExtensionParameter element, BaseDeclaration baseDeclaration, TypeKeysResolver keysResolver) { element.getValueFromAnnotation(MetadataKeyId.class) .ifPresent(valueFetcher -> { boolean hasKeyResolver = !(keysResolver instanceof NullMetadataResolver); baseDeclaration.addModelProperty(new MetadataKeyPartModelProperty(1, hasKeyResolver)); }); element.getValueFromAnnotation(MetadataKeyPart.class) .ifPresent(valueFetcher -> baseDeclaration .addModelProperty(new MetadataKeyPartModelProperty(valueFetcher.getNumberValue(MetadataKeyPart::order), valueFetcher .getBooleanValue(MetadataKeyPart::providedByKeyResolver)))); }
private void doEnrich(BaseDeclaration declaration) { declaration.getModelProperty(ImplementingTypeModelProperty.class).ifPresent(p -> { ImplementingTypeModelProperty typeProperty = (ImplementingTypeModelProperty) p; Collection<Field> fields = getAllFields(typeProperty.getType(), withAnnotation(DefaultEncoding.class)); declaration.addModelProperty(new DefaultEncodingModelProperty(defaultEncodingField)); });
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(); } }
private void assertModelPropertyAdded(BaseDeclaration declaration, Field injectionField) { ArgumentCaptor<RequireNameField> captor = ArgumentCaptor.forClass(RequireNameField.class); verify(declaration).addModelProperty(captor.capture()); RequireNameField property = captor.getValue(); assertThat(property, is(notNullValue())); assertThat(property.getField(), equalTo(injectionField)); }
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; }
public static String getMemberName(BaseDeclaration<?> declaration, String defaultName) { return declaration.getModelProperty(DeclaringMemberModelProperty.class).map(p -> p.getDeclaringField().getName()) .orElse(defaultName); }
protected void resolveStereotype() { if (validatorAnnotation != null || stereotypeAnnotation != null) { if (declaration instanceof BaseDeclaration) { ((BaseDeclaration) declaration).addModelProperty(new CustomStereotypeModelProperty()); } if (validatorAnnotation != null) { addValidationStereotype(); } else { declaration.withStereotype(createCustomStereotype()); } } else { addFallbackStereotype(); } }
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)); }); } }
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); }
/** * Enriches a parameter that has an associated {@link ValueProvider} * * @param resolverClass the class of the {@link ValueProvider} * @param paramDeclaration {@link ParameterDeclaration} or {@link ParameterGroupDeclaration} paramDeclaration * @param containerParameterNames parameters container's names */ private void enrichParameter(OfValues resolverClass, BaseDeclaration paramDeclaration, Consumer<ValueProviderModel> valueProviderModelConsumer, Integer partOrder, Map<String, String> containerParameterNames, String name) { ValueProviderFactoryModelPropertyBuilder propertyBuilder = ValueProviderFactoryModelProperty.builder(resolverClass.value()); ParameterizableTypeWrapper resolverClassWrapper = new ParameterizableTypeWrapper(resolverClass.value(), new DefaultExtensionsTypeLoaderFactory().createTypeLoader()); List<ExtensionParameter> resolverParameters = resolverClassWrapper.getParametersAnnotatedWith(Parameter.class); resolverParameters.forEach(param -> propertyBuilder .withInjectableParameter(param.getName(), param.getType().asMetadataType(), param.isRequired())); Reference<Boolean> requiresConfiguration = new Reference<>(false); Reference<Boolean> requiresConnection = new Reference<>(false); enrichWithConnection(propertyBuilder, resolverClassWrapper) .ifPresent(field -> requiresConnection.set(true)); enrichWithConfiguration(propertyBuilder, resolverClassWrapper) .ifPresent(field -> requiresConfiguration.set(true)); paramDeclaration.addModelProperty(propertyBuilder.build()); valueProviderModelConsumer .accept(new ValueProviderModel(getRequiredParametersAliases(resolverParameters, containerParameterNames), requiresConfiguration.get(), requiresConnection.get(), resolverClass.open(), partOrder, name)); }
private void doEnrich(BaseDeclaration declaration) { declaration.getModelProperty(ImplementingTypeModelProperty.class).ifPresent(p -> { ImplementingTypeModelProperty typeProperty = (ImplementingTypeModelProperty) p; Collection<Field> fields = getAllFields(typeProperty.getType(), withAnnotation(DefaultEncoding.class)); declaration.addModelProperty(new DefaultEncodingModelProperty(defaultEncodingField)); });