30
30
import org .eclipse .jdt .core .dom .MethodDeclaration ;
31
31
import org .eclipse .jdt .core .dom .MethodInvocation ;
32
32
import org .eclipse .jdt .core .dom .RecordDeclaration ;
33
+ import org .eclipse .jdt .core .dom .SimpleName ;
33
34
import org .eclipse .jdt .core .dom .TypeDeclaration ;
34
35
import org .eclipse .lsp4j .Location ;
35
36
import org .eclipse .lsp4j .SymbolKind ;
51
52
import org .springframework .ide .vscode .boot .java .utils .SpringIndexerJavaContext ;
52
53
import org .springframework .ide .vscode .commons .protocol .spring .AnnotationMetadata ;
53
54
import org .springframework .ide .vscode .commons .protocol .spring .Bean ;
55
+ import org .springframework .ide .vscode .commons .protocol .spring .BeanRegistrarElement ;
54
56
import org .springframework .ide .vscode .commons .protocol .spring .DefaultValues ;
55
57
import org .springframework .ide .vscode .commons .protocol .spring .InjectionPoint ;
56
58
import org .springframework .ide .vscode .commons .protocol .spring .SimpleSymbolElement ;
59
+ import org .springframework .ide .vscode .commons .protocol .spring .SpringIndexElement ;
57
60
import org .springframework .ide .vscode .commons .util .BadLocationException ;
58
61
import org .springframework .ide .vscode .commons .util .text .DocumentRegion ;
59
62
import org .springframework .ide .vscode .commons .util .text .TextDocument ;
@@ -401,7 +404,7 @@ private MethodDeclaration findRegisterMethod(TypeDeclaration type, ITypeBinding
401
404
return null ;
402
405
}
403
406
404
- private void indexBeanRegistrarImplementation (Bean bean , TypeDeclaration typeDeclaration , SpringIndexerJavaContext context , TextDocument doc ) {
407
+ private void indexBeanRegistrarImplementation (SpringIndexElement parentNode , TypeDeclaration typeDeclaration , SpringIndexerJavaContext context , TextDocument doc ) {
405
408
try {
406
409
ITypeBinding typeBinding = typeDeclaration .resolveBinding ();
407
410
if (typeBinding == null ) return ;
@@ -416,39 +419,32 @@ private void indexBeanRegistrarImplementation(Bean bean, TypeDeclaration typeDec
416
419
throw new RequiredCompleteAstException ();
417
420
}
418
421
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 ( );
422
425
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 ()));
424
428
425
429
WorkspaceSymbol symbol = new WorkspaceSymbol (
426
- beanLabel ( "+" , null , null , beanName , beanType ) ,
427
- SymbolKind .Class ,
430
+ name + " (Bean Registrar)" ,
431
+ SymbolKind .Interface ,
428
432
Either .forLeft (location ));
429
433
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 );
439
435
440
436
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 ));
442
438
}
443
439
444
- scanBeanRegistryInvocations (bean , registerMethod .getBody (), context , doc );
440
+ scanBeanRegistryInvocations (parentNode , registerMethod .getBody (), context , doc );
445
441
446
442
} catch (BadLocationException e ) {
447
443
log .error ("" , e );
448
444
}
449
445
}
450
446
451
- private void scanBeanRegistryInvocations (Bean component , Block body , SpringIndexerJavaContext context , TextDocument doc ) {
447
+ private void scanBeanRegistryInvocations (SpringIndexElement parent , Block body , SpringIndexerJavaContext context , TextDocument doc ) {
452
448
if (body == null ) {
453
449
return ;
454
450
}
@@ -491,7 +487,7 @@ public boolean visit(MethodInvocation methodInvocation) {
491
487
String beanName = BeanUtils .getBeanNameFromType (typeParameters [0 ].getName ());
492
488
String beanType = typeParamName ;
493
489
494
- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
490
+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
495
491
}
496
492
}
497
493
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
505
501
String typeParamName = typeParameters [0 ].getBinaryName ();
506
502
String beanType = typeParamName ;
507
503
508
- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
504
+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
509
505
}
510
506
}
511
507
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
519
515
String beanName = BeanUtils .getBeanNameFromType (typeParameters [0 ].getName ());
520
516
String beanType = typeParamName ;
521
517
522
- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
518
+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
523
519
}
524
520
}
525
521
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
534
530
String typeParamName = typeParameters [0 ].getBinaryName ();
535
531
String beanType = typeParamName ;
536
532
537
- createBean (component , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
533
+ createBean (parent , beanName , beanType , typeParameters [0 ], methodInvocation , context , doc );
538
534
}
539
535
}
540
536
}
@@ -548,7 +544,7 @@ else if (arguments.size() == 3 && "java.lang.String".equals(types.get(0).getQual
548
544
});
549
545
}
550
546
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 {
552
548
Location location = new Location (doc .getUri (), doc .toRange (node .getStartPosition (), node .getLength ()));
553
549
554
550
WorkspaceSymbol symbol = new WorkspaceSymbol (
@@ -564,7 +560,7 @@ public void createBean(Bean parentBean, String beanName, String beanType, ITypeB
564
560
AnnotationMetadata [] annotations = DefaultValues .EMPTY_ANNOTATIONS ;
565
561
566
562
Bean bean = new Bean (beanName , beanType , location , injectionPoints , supertypes , annotations , false , symbol .getName ());
567
- parentBean .addChild (bean );
563
+ parentNode .addChild (bean );
568
564
}
569
565
570
566
public static String beanLabel (String searchPrefix , String annotationTypeName , Collection <String > metaAnnotationNames , String beanName , String beanType ) {
0 commit comments