1010 *******************************************************************************/
1111package org .springframework .ide .vscode .boot .java .beans ;
1212
13+ import java .util .ArrayList ;
1314import java .util .Collection ;
1415import java .util .List ;
1516import java .util .Map ;
@@ -71,26 +72,27 @@ public static String createBeanLabel(List<AnnotationMetadata> annotations, Strin
7172 symbolLabel .append ('\'' );
7273
7374 if (annotations != null ) {
74- List <AnnotationMetadata > directAnnotations = annotations .stream ()
75+ List <String > directAnnotations = annotations .stream ()
7576 .filter (annotation -> ANNOTATIONS_TO_INCLUDE_IN_LABEL .contains (annotation .getAnnotationType ()))
76- .filter (annotation -> !annotation .isMetaAnnotation ()).toList ();
77+ .filter (annotation -> !annotation .isMetaAnnotation ())
78+ .map (annotation -> "@" + annotation .getAnnotationName ())
79+ .toList ();
7780
78- List <AnnotationMetadata > metaAnnotations = annotations .stream ()
81+ List <String > metaAnnotationNames = annotations .stream ()
7982 .filter (annotation -> ANNOTATIONS_TO_INCLUDE_IN_LABEL .contains (annotation .getAnnotationType ()))
80- .filter (annotation -> annotation .isMetaAnnotation ()).toList ();
83+ .filter (annotation -> annotation .isMetaAnnotation ())
84+ .map (annotation -> "@" + annotation .getAnnotationName ())
85+ .distinct ()
86+ .toList ();
8187
8288 if (directAnnotations .size () > 0 ) {
8389 symbolLabel .append (' ' );
8490 symbolLabel .append ('(' );
85- symbolLabel .append (String .join (", " , directAnnotations .stream ()
86- .map (annotation -> "@" + annotation .getAnnotationName ())
87- .toList ()));
91+ symbolLabel .append (String .join (", " , directAnnotations ));
8892
89- if (metaAnnotations .size () > 0 ) {
93+ if (metaAnnotationNames .size () > 0 ) {
9094 symbolLabel .append (" <: " );
91- symbolLabel .append (String .join (", " , metaAnnotations .stream ()
92- .map (annotation -> "@" + annotation .getAnnotationName ())
93- .toList ()));
95+ symbolLabel .append (String .join (", " , metaAnnotationNames ));
9496 }
9597
9698 symbolLabel .append (')' );
@@ -102,7 +104,8 @@ public static String createBeanLabel(List<AnnotationMetadata> annotations, Strin
102104 return symbolLabel .toString ();
103105 }
104106
105- public static String getBeanNameFromType (AbstractTypeDeclaration type , List <AnnotationMetadata > annotationMetadata ) {
107+ public static List <String > getBeanNamesFromType (AbstractTypeDeclaration type , List <AnnotationMetadata > annotationMetadata ) {
108+ List <String > result = new ArrayList <>();
106109
107110 // annotation-defined names
108111 if (annotationMetadata != null ) {
@@ -112,17 +115,33 @@ public static String getBeanNameFromType(AbstractTypeDeclaration type, List<Anno
112115 Map <String , AnnotationAttributeValue []> attributes = annotation .getAttributes ();
113116 if (attributes != null ) {
114117 AnnotationAttributeValue [] values = attributes .get ("value" );
115- if (values != null && values .length > 0 ) {
116- return values [0 ].getName ();
118+ if (values != null ) {
119+ for (int i = 0 ; i < values .length ; i ++) {
120+ result .add (values [i ].getName ());
121+ }
117122 }
118123 }
119124 }
120125 }
121126 }
122127
123128 // otherwise fall back to type name;
124- String beanType = type .getName ().toString ();
125- return BeanUtils .getBeanNameFromType (beanType );
129+ if (result .size () == 0 && type .getName () != null ) {
130+ String beanType = type .getName ().toString ();
131+ result .add (BeanUtils .getBeanNameFromType (beanType ));
132+ }
133+
134+ return result ;
135+ }
136+
137+ public static String getBeanNameFromType (AbstractTypeDeclaration type , List <AnnotationMetadata > annotationMetadata ) {
138+ List <String > beanNames = getBeanNamesFromType (type , annotationMetadata );
139+ if (beanNames .size () == 1 ) {
140+ return beanNames .get (0 );
141+ }
142+ else {
143+ return "(" + String .join (", " , beanNames ) + ")" ;
144+ }
126145 }
127146
128147 public static String getBeanNameFromComponentAnnotation (Annotation annotation , AbstractTypeDeclaration type ) {
0 commit comments