3030import org .eclipse .jdt .core .dom .MethodDeclaration ;
3131import org .eclipse .jdt .core .dom .MethodInvocation ;
3232import org .eclipse .jdt .core .dom .RecordDeclaration ;
33+ import org .eclipse .jdt .core .dom .SimpleName ;
3334import org .eclipse .jdt .core .dom .TypeDeclaration ;
3435import org .eclipse .lsp4j .Location ;
3536import org .eclipse .lsp4j .SymbolKind ;
5152import org .springframework .ide .vscode .boot .java .utils .SpringIndexerJavaContext ;
5253import org .springframework .ide .vscode .commons .protocol .spring .AnnotationMetadata ;
5354import org .springframework .ide .vscode .commons .protocol .spring .Bean ;
55+ import org .springframework .ide .vscode .commons .protocol .spring .BeanRegistrarElement ;
5456import org .springframework .ide .vscode .commons .protocol .spring .DefaultValues ;
5557import org .springframework .ide .vscode .commons .protocol .spring .InjectionPoint ;
5658import org .springframework .ide .vscode .commons .protocol .spring .SimpleSymbolElement ;
59+ import org .springframework .ide .vscode .commons .protocol .spring .SpringIndexElement ;
5760import org .springframework .ide .vscode .commons .util .BadLocationException ;
5861import org .springframework .ide .vscode .commons .util .text .DocumentRegion ;
5962import org .springframework .ide .vscode .commons .util .text .TextDocument ;
@@ -401,7 +404,7 @@ private MethodDeclaration findRegisterMethod(TypeDeclaration type, ITypeBinding
401404 return null ;
402405 }
403406
404- private void indexBeanRegistrarImplementation (Bean bean , TypeDeclaration typeDeclaration , SpringIndexerJavaContext context , TextDocument doc ) {
407+ private void indexBeanRegistrarImplementation (SpringIndexElement parentNode , TypeDeclaration typeDeclaration , SpringIndexerJavaContext context , TextDocument doc ) {
405408 try {
406409 ITypeBinding typeBinding = typeDeclaration .resolveBinding ();
407410 if (typeBinding == null ) return ;
@@ -416,39 +419,32 @@ private void indexBeanRegistrarImplementation(Bean bean, TypeDeclaration typeDec
416419 throw new RequiredCompleteAstException ();
417420 }
418421
419- if (bean == null ) { // need to create and register bean element
420- String beanType = typeBinding .getQualifiedName ();
421- String beanName = BeanUtils . getBeanNameFromType ( typeBinding .getName () );
422+ if (parentNode == null ) { // need to create and register bean element
423+ String name = typeBinding .getName ();
424+ String type = typeBinding .getQualifiedName ( );
422425
423- Location location = new Location (doc .getUri (), doc .toRange (typeDeclaration .getStartPosition (), typeDeclaration .getLength ()));
426+ SimpleName typeNameNode = typeDeclaration .getName ();
427+ Location location = new Location (doc .getUri (), doc .toRange (typeNameNode .getStartPosition (), typeNameNode .getLength ()));
424428
425429 WorkspaceSymbol symbol = new WorkspaceSymbol (
426- beanLabel ( "+" , null , null , beanName , beanType ) ,
427- SymbolKind .Class ,
430+ name + " (Bean Registrar)" ,
431+ SymbolKind .Interface ,
428432 Either .forLeft (location ));
429433
430- InjectionPoint [] injectionPoints = ASTUtils .findInjectionPoints (typeDeclaration , doc );
431-
432- Set <String > supertypes = new HashSet <>();
433- ASTUtils .findSupertypes (typeBinding , supertypes );
434-
435- Collection <Annotation > annotationsOnMethod = ASTUtils .getAnnotations (typeDeclaration );
436- AnnotationMetadata [] annotations = ASTUtils .getAnnotationsMetadata (annotationsOnMethod , doc );
437-
438- bean = new Bean (beanName , beanType , location , injectionPoints , supertypes , annotations , false , symbol .getName ());
434+ parentNode = new BeanRegistrarElement (name , type , location );
439435
440436 context .getGeneratedSymbols ().add (new CachedSymbol (context .getDocURI (), context .getLastModified (), symbol ));
441- context .getBeans ().add (new CachedBean (context .getDocURI (), bean ));
437+ context .getBeans ().add (new CachedBean (context .getDocURI (), parentNode ));
442438 }
443439
444- scanBeanRegistryInvocations (bean , registerMethod .getBody (), context , doc );
440+ scanBeanRegistryInvocations (parentNode , registerMethod .getBody (), context , doc );
445441
446442 } catch (BadLocationException e ) {
447443 log .error ("" , e );
448444 }
449445 }
450446
451- private void scanBeanRegistryInvocations (Bean component , Block body , SpringIndexerJavaContext context , TextDocument doc ) {
447+ private void scanBeanRegistryInvocations (SpringIndexElement parent , Block body , SpringIndexerJavaContext context , TextDocument doc ) {
452448 if (body == null ) {
453449 return ;
454450 }
@@ -491,7 +487,7 @@ public boolean visit(MethodInvocation methodInvocation) {
491487 String beanName = BeanUtils .getBeanNameFromType (typeParameters [0 ].getName ());
492488 String beanType = typeParamName ;
493489
494- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
490+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
495491 }
496492 }
497493 else if (arguments .size () == 2 && "java.lang.String" .equals (types .get (0 ).getQualifiedName ()) && "java.lang.Class" .equals (types .get (1 ).getBinaryName ())) {
@@ -505,7 +501,7 @@ else if (arguments.size() == 2 && "java.lang.String".equals(types.get(0).getQual
505501 String typeParamName = typeParameters [0 ].getBinaryName ();
506502 String beanType = typeParamName ;
507503
508- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
504+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
509505 }
510506 }
511507 else if (arguments .size () == 2 && "java.lang.Class" .equals (types .get (0 ).getBinaryName ()) && "java.util.function.Consumer" .equals (types .get (1 ).getBinaryName ())) {
@@ -519,7 +515,7 @@ else if (arguments.size() == 2 && "java.lang.Class".equals(types.get(0).getBinar
519515 String beanName = BeanUtils .getBeanNameFromType (typeParameters [0 ].getName ());
520516 String beanType = typeParamName ;
521517
522- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
518+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
523519 }
524520 }
525521 else if (arguments .size () == 3 && "java.lang.String" .equals (types .get (0 ).getQualifiedName ())
@@ -534,7 +530,7 @@ else if (arguments.size() == 3 && "java.lang.String".equals(types.get(0).getQual
534530 String typeParamName = typeParameters [0 ].getBinaryName ();
535531 String beanType = typeParamName ;
536532
537- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
533+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
538534 }
539535 }
540536 }
@@ -548,7 +544,7 @@ else if (arguments.size() == 3 && "java.lang.String".equals(types.get(0).getQual
548544 });
549545 }
550546
551- public void createBean (Bean parentBean , String beanName , String beanType , ITypeBinding beanTypeBinding , ASTNode node , SpringIndexerJavaContext context , TextDocument doc ) throws BadLocationException {
547+ public void createBean (SpringIndexElement parentNode , String beanName , String beanType , ITypeBinding beanTypeBinding , ASTNode node , SpringIndexerJavaContext context , TextDocument doc ) throws BadLocationException {
552548 Location location = new Location (doc .getUri (), doc .toRange (node .getStartPosition (), node .getLength ()));
553549
554550 WorkspaceSymbol symbol = new WorkspaceSymbol (
@@ -564,7 +560,7 @@ public void createBean(Bean parentBean, String beanName, String beanType, ITypeB
564560 AnnotationMetadata [] annotations = DefaultValues .EMPTY_ANNOTATIONS ;
565561
566562 Bean bean = new Bean (beanName , beanType , location , injectionPoints , supertypes , annotations , false , symbol .getName ());
567- parentBean .addChild (bean );
563+ parentNode .addChild (bean );
568564 }
569565
570566 public static String beanLabel (String searchPrefix , String annotationTypeName , Collection <String > metaAnnotationNames , String beanName , String beanType ) {
0 commit comments