Replace Actuator @Nullable with @OptionalParameter
Closes gh-45389
This commit is contained in:
@@ -106,6 +106,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
static final String READ_OPERATION_ANNOTATION = "org.springframework.boot.actuate.endpoint.annotation.ReadOperation";
|
||||
|
||||
static final String OPTIONAL_PARAMETER_ANNOTATION = "org.springframework.boot.actuate.endpoint.annotation.OptionalParameter";
|
||||
|
||||
static final String NAME_ANNOTATION = "org.springframework.boot.context.properties.bind.Name";
|
||||
|
||||
static final String ENDPOINT_ACCESS_ENUM = "org.springframework.boot.actuate.endpoint.Access";
|
||||
@@ -155,6 +157,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
return NAME_ANNOTATION;
|
||||
}
|
||||
|
||||
protected String optionalParameterAnnotation() {
|
||||
return OPTIONAL_PARAMETER_ANNOTATION;
|
||||
}
|
||||
|
||||
protected String endpointAccessEnum() {
|
||||
return ENDPOINT_ACCESS_ENUM;
|
||||
}
|
||||
@@ -177,7 +183,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
this.metadataEnv = new MetadataGenerationEnvironment(env, configurationPropertiesAnnotation(),
|
||||
nestedConfigurationPropertyAnnotation(), deprecatedConfigurationPropertyAnnotation(),
|
||||
constructorBindingAnnotation(), autowiredAnnotation(), defaultValueAnnotation(), endpointAnnotations(),
|
||||
readOperationAnnotation(), nameAnnotation());
|
||||
readOperationAnnotation(), optionalParameterAnnotation(), nameAnnotation());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -355,13 +361,18 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
|
||||
private boolean hasNoOrOptionalParameters(ExecutableElement method) {
|
||||
for (VariableElement parameter : method.getParameters()) {
|
||||
if (!this.metadataEnv.hasNullableAnnotation(parameter)) {
|
||||
if (!isOptionalParameter(parameter)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isOptionalParameter(VariableElement parameter) {
|
||||
return this.metadataEnv.hasNullableAnnotation(parameter)
|
||||
|| this.metadataEnv.hasOptionalParameterAnnotation(parameter);
|
||||
}
|
||||
|
||||
private String getPrefix(AnnotationMirror annotation) {
|
||||
String prefix = this.metadataEnv.getAnnotationElementStringValue(annotation, "prefix");
|
||||
if (prefix != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -91,6 +91,8 @@ class MetadataGenerationEnvironment {
|
||||
|
||||
private final String readOperationAnnotation;
|
||||
|
||||
private final String optionalParameterAnnotation;
|
||||
|
||||
private final String nameAnnotation;
|
||||
|
||||
private final String autowiredAnnotation;
|
||||
@@ -98,7 +100,8 @@ class MetadataGenerationEnvironment {
|
||||
MetadataGenerationEnvironment(ProcessingEnvironment environment, String configurationPropertiesAnnotation,
|
||||
String nestedConfigurationPropertyAnnotation, String deprecatedConfigurationPropertyAnnotation,
|
||||
String constructorBindingAnnotation, String autowiredAnnotation, String defaultValueAnnotation,
|
||||
Set<String> endpointAnnotations, String readOperationAnnotation, String nameAnnotation) {
|
||||
Set<String> endpointAnnotations, String readOperationAnnotation, String optionalParameterAnnotation,
|
||||
String nameAnnotation) {
|
||||
this.typeUtils = new TypeUtils(environment);
|
||||
this.elements = environment.getElementUtils();
|
||||
this.messager = environment.getMessager();
|
||||
@@ -111,6 +114,7 @@ class MetadataGenerationEnvironment {
|
||||
this.defaultValueAnnotation = defaultValueAnnotation;
|
||||
this.endpointAnnotations = endpointAnnotations;
|
||||
this.readOperationAnnotation = readOperationAnnotation;
|
||||
this.optionalParameterAnnotation = optionalParameterAnnotation;
|
||||
this.nameAnnotation = nameAnnotation;
|
||||
}
|
||||
|
||||
@@ -337,6 +341,10 @@ class MetadataGenerationEnvironment {
|
||||
return getAnnotation(element, NULLABLE_ANNOTATION) != null;
|
||||
}
|
||||
|
||||
boolean hasOptionalParameterAnnotation(Element element) {
|
||||
return getAnnotation(element, this.optionalParameterAnnotation) != null;
|
||||
}
|
||||
|
||||
private boolean isElementDeprecated(Element element) {
|
||||
return hasAnnotation(element, "java.lang.Deprecated")
|
||||
|| hasAnnotation(element, this.deprecatedConfigurationPropertyAnnotation);
|
||||
|
||||
Reference in New Issue
Block a user