1414import java .util .Collection ;
1515import java .util .HashSet ;
1616import java .util .List ;
17+ import java .util .Optional ;
1718import java .util .Set ;
1819import java .util .stream .Collectors ;
1920import java .util .stream .Stream ;
4142import org .springframework .ide .vscode .boot .java .utils .ASTUtils ;
4243import org .springframework .ide .vscode .boot .java .utils .CachedSymbol ;
4344import org .springframework .ide .vscode .boot .java .utils .SpringIndexerJavaContext ;
45+ import org .springframework .ide .vscode .commons .protocol .spring .AnnotationAttributeValue ;
4446import org .springframework .ide .vscode .commons .protocol .spring .AnnotationMetadata ;
4547import org .springframework .ide .vscode .commons .protocol .spring .Bean ;
4648import org .springframework .ide .vscode .commons .protocol .spring .InjectionPoint ;
@@ -84,7 +86,7 @@ protected void createSymbolForType(AbstractTypeDeclaration type, Annotation node
8486 if (!isComponentAnnotated ) {
8587 String beanName = BeanUtils .getBeanNameFromType (type .getName ().getFullyQualifiedName ());
8688
87- Location location = new Location (doc .getUri (), doc .toRange (type .getStartPosition (), type .getLength ()));
89+ Location location = new Location (doc .getUri (), doc .toRange (node .getStartPosition (), node .getLength ()));
8890
8991 WorkspaceSymbol symbol = new WorkspaceSymbol (
9092 ComponentSymbolProvider .beanLabel ("+" , annotationTypeName , metaAnnotationNames , beanName , typeBinding .getName ()), SymbolKind .Interface ,
@@ -107,7 +109,7 @@ protected void createSymbolForType(AbstractTypeDeclaration type, Annotation node
107109 .toArray (AnnotationMetadata []::new );
108110
109111 Bean beanDefinition = new Bean (beanName , typeBinding .getQualifiedName (), location , injectionPoints , supertypes , annotations , isConfiguration , symbol .getName ());
110-
112+
111113 indexConfigurationProperties (beanDefinition , type , context , doc );
112114
113115 context .getGeneratedSymbols ().add (new CachedSymbol (context .getDocURI (), context .getLastModified (), symbol ));
@@ -116,15 +118,38 @@ protected void createSymbolForType(AbstractTypeDeclaration type, Annotation node
116118 }
117119
118120 public static void indexConfigurationProperties (Bean beanDefinition , AbstractTypeDeclaration abstractType , SpringIndexerJavaContext context , TextDocument doc ) {
121+ Optional <String > prefixValue = Arrays .stream (beanDefinition .getAnnotations ())
122+ .filter (annotation -> Annotations .CONFIGURATION_PROPERTIES .equals (annotation .getAnnotationType ()))
123+ .flatMap (annotation -> Arrays .stream (getPrefix (annotation )))
124+ .map (attribute -> attribute .getName ())
125+ .findFirst ();
126+
127+ String prefix = "" ;
128+ if (prefixValue .isPresent ()) {
129+ prefix = prefixValue .get () + "." ;
130+ }
131+
119132 if (abstractType instanceof TypeDeclaration type ) {
120- indexConfigurationPropertiesForType (beanDefinition , type , context , doc );
133+ indexConfigurationPropertiesForType (beanDefinition , type , context , doc , prefix );
121134 }
122135 else if (abstractType instanceof RecordDeclaration record ) {
123- indexConfigurationPropertiesForRecord (beanDefinition , record , context , doc );
136+ indexConfigurationPropertiesForRecord (beanDefinition , record , context , doc , prefix );
137+ }
138+ }
139+
140+ private static AnnotationAttributeValue [] getPrefix (AnnotationMetadata annotation ) {
141+ if (annotation .getAttributes ().containsKey ("prefix" )) {
142+ return annotation .getAttributes ().get ("prefix" );
143+ }
144+ else if (annotation .getAttributes ().containsKey ("value" )) {
145+ return annotation .getAttributes ().get ("value" );
146+ }
147+ else {
148+ return new AnnotationAttributeValue [0 ];
124149 }
125150 }
126151
127- public static void indexConfigurationPropertiesForType (Bean beanDefinition , TypeDeclaration type , SpringIndexerJavaContext context , TextDocument doc ) {
152+ public static void indexConfigurationPropertiesForType (Bean beanDefinition , TypeDeclaration type , SpringIndexerJavaContext context , TextDocument doc , String prefix ) {
128153
129154 FieldDeclaration [] fields = type .getFields ();
130155 if (fields != null ) {
@@ -143,7 +168,7 @@ public static void indexConfigurationPropertiesForType(Bean beanDefinition, Type
143168
144169 DocumentRegion nodeRegion = ASTUtils .nodeRegion (doc , field );
145170 Range range = doc .toRange (nodeRegion );
146- ConfigPropertyIndexElement configPropElement = new ConfigPropertyIndexElement (name .getFullyQualifiedName (), fieldType .resolveBinding ().getQualifiedName (), range );
171+ ConfigPropertyIndexElement configPropElement = new ConfigPropertyIndexElement (prefix + name .getFullyQualifiedName (), fieldType .resolveBinding ().getQualifiedName (), range );
147172
148173 beanDefinition .addChild (configPropElement );
149174 }
@@ -157,7 +182,7 @@ public static void indexConfigurationPropertiesForType(Bean beanDefinition, Type
157182
158183 }
159184
160- public static void indexConfigurationPropertiesForRecord (Bean beanDefinition , RecordDeclaration record , SpringIndexerJavaContext context , TextDocument doc ) {
185+ public static void indexConfigurationPropertiesForRecord (Bean beanDefinition , RecordDeclaration record , SpringIndexerJavaContext context , TextDocument doc , String prefix ) {
161186
162187 @ SuppressWarnings ("unchecked" )
163188 List <SingleVariableDeclaration > fields = record .recordComponents ();
@@ -173,7 +198,7 @@ public static void indexConfigurationPropertiesForRecord(Bean beanDefinition, Re
173198
174199 DocumentRegion nodeRegion = ASTUtils .nodeRegion (doc , field );
175200 Range range = doc .toRange (nodeRegion );
176- ConfigPropertyIndexElement configPropElement = new ConfigPropertyIndexElement (name .getFullyQualifiedName (), fieldType .resolveBinding ().getQualifiedName (), range );
201+ ConfigPropertyIndexElement configPropElement = new ConfigPropertyIndexElement (prefix + name .getFullyQualifiedName (), fieldType .resolveBinding ().getQualifiedName (), range );
177202
178203 beanDefinition .addChild (configPropElement );
179204 }
0 commit comments