1515 * limitations under the License.
1616 */
1717
18- package io .microsphere .annotation .processor . model . util ;
18+ package io .microsphere .annotation .processor ;
1919
2020import io .microsphere .annotation .ConfigurationProperty ;
2121import io .microsphere .beans .ConfigurationProperty .Metadata ;
22+ import io .microsphere .lang .model .util .AnnotatedElementJSONElementVisitor ;
2223import io .microsphere .metadata .ConfigurationPropertyGenerator ;
2324
2425import javax .annotation .processing .ProcessingEnvironment ;
2526import javax .lang .model .element .AnnotationMirror ;
2627import javax .lang .model .element .AnnotationValue ;
2728import javax .lang .model .element .Element ;
2829import javax .lang .model .element .ExecutableElement ;
30+ import javax .lang .model .element .TypeElement ;
2931import javax .lang .model .element .VariableElement ;
3032import javax .lang .model .type .TypeMirror ;
3133import java .util .List ;
3234import java .util .Map ;
3335
34- import static io .microsphere .annotation .processor .util .AnnotationUtils .getAnnotation ;
35- import static io .microsphere .annotation .processor .util .AnnotationUtils .getAttributeName ;
36- import static io .microsphere .annotation .processor .util .AnnotationUtils .getElementValues ;
37- import static io .microsphere .annotation .processor .util .AnnotationUtils .matchesDefaultAttributeValue ;
38- import static io .microsphere .annotation .processor .util .ClassUtils .getClassName ;
39- import static io .microsphere .annotation .processor .util .TypeUtils .getTypeName ;
4036import static io .microsphere .constants .SymbolConstants .COMMA_CHAR ;
37+ import static io .microsphere .lang .model .util .AnnotationUtils .getAnnotation ;
38+ import static io .microsphere .lang .model .util .AnnotationUtils .getAttributeName ;
39+ import static io .microsphere .lang .model .util .AnnotationUtils .getElementValues ;
40+ import static io .microsphere .lang .model .util .AnnotationUtils .matchesDefaultAttributeValue ;
41+ import static io .microsphere .lang .model .util .ClassUtils .getClassName ;
42+ import static io .microsphere .lang .model .util .TypeUtils .getTypeName ;
4143import static io .microsphere .util .ServiceLoaderUtils .loadFirstService ;
4244import static io .microsphere .util .StringUtils .isBlank ;
4345
5153 * @see io.microsphere.beans.ConfigurationProperty
5254 * @since 1.0.0
5355 */
54- public class ConfigurationPropertyJSONElementVisitor extends AnnotatedElementJSONElementVisitor {
56+ class ConfigurationPropertyJSONElementVisitor extends AnnotatedElementJSONElementVisitor {
5557
56- public static final String CONFIGURATION_PROPERTY_ANNOTATION_CLASS_NAME = "io.microsphere.annotation.ConfigurationProperty" ;
58+ static final String CONFIGURATION_PROPERTY_ANNOTATION_CLASS_NAME = "io.microsphere.annotation.ConfigurationProperty" ;
5759
5860 private final ConfigurationPropertyGenerator generator ;
5961
60- public ConfigurationPropertyJSONElementVisitor (ProcessingEnvironment processingEnv ) {
62+ ConfigurationPropertyJSONElementVisitor (ProcessingEnvironment processingEnv ) {
6163 super (processingEnv , CONFIGURATION_PROPERTY_ANNOTATION_CLASS_NAME );
6264 this .generator = loadFirstService (ConfigurationPropertyGenerator .class );
6365 }
@@ -87,8 +89,8 @@ public Boolean visitVariableAsField(VariableElement field, StringBuilder jsonBui
8789 } else if ("description" .equals (attributeName )) {
8890 String description = resolveDescription (field , attributeMethod , annotationValue );
8991 configurationProperty .setDescription (description );
90- } else if ( "source" . equals ( attributeName )) {
91- setSources (configurationProperty , annotationValue );
92+ } else {
93+ setSources (configurationProperty , attributeName , annotationValue );
9294 }
9395 }
9496 setDeclaredClass (configurationProperty , field );
@@ -102,6 +104,11 @@ public Boolean visitVariableAsField(VariableElement field, StringBuilder jsonBui
102104 return false ;
103105 }
104106
107+ @ Override
108+ protected boolean supportsType (TypeElement e ) {
109+ return true ;
110+ }
111+
105112 public ConfigurationPropertyGenerator getGenerator () {
106113 return generator ;
107114 }
@@ -130,12 +137,14 @@ private String resolveStringValue(ExecutableElement attributeMethod, AnnotationV
130137 return (String ) value ;
131138 }
132139
133- private void setSources (io .microsphere .beans .ConfigurationProperty configurationProperty , AnnotationValue annotationValue ) {
134- List <? extends AnnotationValue > sources = (List <? extends AnnotationValue >) annotationValue .getValue ();
135- Metadata metadata = configurationProperty .getMetadata ();
136- for (AnnotationValue source : sources ) {
137- String sourceValue = (String ) source .getValue ();
138- metadata .getSources ().add (sourceValue );
140+ void setSources (io .microsphere .beans .ConfigurationProperty configurationProperty , String attributeName , AnnotationValue annotationValue ) {
141+ if ("source" .equals (attributeName )) {
142+ List <? extends AnnotationValue > sources = (List <? extends AnnotationValue >) annotationValue .getValue ();
143+ Metadata metadata = configurationProperty .getMetadata ();
144+ for (AnnotationValue source : sources ) {
145+ String sourceValue = (String ) source .getValue ();
146+ metadata .getSources ().add (sourceValue );
147+ }
139148 }
140149 }
141150
@@ -149,5 +158,4 @@ private void setDeclaredField(io.microsphere.beans.ConfigurationProperty configu
149158 String declaredFieldName = field .getSimpleName ().toString ();
150159 configurationProperty .getMetadata ().setDeclaredField (declaredFieldName );
151160 }
152-
153- }
161+ }
0 commit comments