Skip to content

Commit

Permalink
GH-1041: bean now knows whether it is a configuration bean or not
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlippert committed Jan 8, 2025
1 parent 8491efa commit 02e3ede
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ public class Bean {
private final InjectionPoint[] injectionPoints;
private final Set<String> supertypes;
private final AnnotationMetadata[] annotations;
private final boolean isConfiguration;

public Bean(
String name,
String type,
Location location,
InjectionPoint[] injectionPoints,
Set<String> supertypes,
AnnotationMetadata[] annotations, boolean isConfiguration) {

public Bean(String name, String type, Location location, InjectionPoint[] injectionPoints, Set<String> supertypes, AnnotationMetadata[] annotations) {
this.name = name;
this.type = type;
this.location = location;
this.isConfiguration = isConfiguration;

if (injectionPoints != null && injectionPoints.length == 0) {
this.injectionPoints = DefaultValues.EMPTY_INJECTION_POINTS;
Expand Down Expand Up @@ -79,6 +88,10 @@ public AnnotationMetadata[] getAnnotations() {
return annotations;
}

public boolean isConfiguration() {
return isConfiguration;
}

@Override
public String toString() {
Gson gson = new Gson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,11 @@ public Bean deserialize(JsonElement json, Type type, JsonDeserializationContext

JsonElement annotationsObject = parsedObject.get("annotations");
AnnotationMetadata[] annotations = annotationsObject == null ? DefaultValues.EMPTY_ANNOTATIONS : context.deserialize(annotationsObject, AnnotationMetadata[].class);

JsonElement isConfigurationObject = parsedObject.get("isConfiguration");
boolean isConfiguration = context.deserialize(isConfigurationObject, boolean.class);

return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations);
return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,10 @@ public Bean deserialize(JsonElement json, Type type, JsonDeserializationContext
JsonElement annotationsObject = parsedObject.get("annotations");
AnnotationMetadata[] annotations = annotationsObject == null ? DefaultValues.EMPTY_ANNOTATIONS : context.deserialize(annotationsObject, AnnotationMetadata[].class);

return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations);
JsonElement isConfigurationObject = parsedObject.get("isConfiguration");
boolean isConfiguration = context.deserialize(isConfigurationObject, boolean.class);

return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col
Collection<Annotation> annotationsOnMethod = ASTUtils.getAnnotations(method);
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnMethod, doc);

Bean beanDefinition = new Bean(nameAndRegion.getT1(), beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations);
Bean beanDefinition = new Bean(nameAndRegion.getT1(), beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);

context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ protected Tuple.Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation nod
beanLabel("+", annotationTypeName, metaAnnotationNames, beanName, beanType.getName()), SymbolKind.Interface,
Either.forLeft(location));

boolean isConfiguration = false;
SymbolAddOnInformation[] addon = new SymbolAddOnInformation[0];
if (Annotations.CONFIGURATION.equals(annotationType.getQualifiedName())
|| metaAnnotations.stream().anyMatch(t -> Annotations.CONFIGURATION.equals(t.getQualifiedName()))) {
addon = new SymbolAddOnInformation[] {new ConfigBeanSymbolAddOnInformation(beanName, beanType.getQualifiedName())};
isConfiguration = true;
} else {
addon = new SymbolAddOnInformation[] {new BeansSymbolAddOnInformation(beanName, beanType.getQualifiedName())};
}
Expand All @@ -112,7 +114,7 @@ protected Tuple.Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation nod
.map(an -> new AnnotationMetadata(an.getQualifiedName(), true, null, null)))
.toArray(AnnotationMetadata[]::new);

Bean beanDefinition = new Bean(beanName, beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations);
Bean beanDefinition = new Bean(beanName, beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, isConfiguration);

return Tuple.two(new EnhancedSymbolInformation(symbol, addon), beanDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private Two<EnhancedSymbolInformation, Bean> createSymbol(Annotation node, IType
.map(an -> new AnnotationMetadata(an.getQualifiedName(), true, null, null)))
.toArray(AnnotationMetadata[]::new);

Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations);
Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);

return Tuple.two(new EnhancedSymbolInformation(symbol, addon), beanDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
Collection<Annotation> annotationsOnMethod = ASTUtils.getAnnotations(typeDeclaration);
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnMethod, doc);

Bean beanDefinition = new Bean(beanName, concreteRepoType, location, injectionPoints, supertypes, annotations);
Bean beanDefinition = new Bean(beanName, concreteRepoType, location, injectionPoints, supertypes, annotations, false);

context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), enhancedSymbol));
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static enum SCAN_PASS {

// whenever the implementation of the indexer changes in a way that the stored data in the cache is no longer valid,
// we need to change the generation - this will result in a re-indexing due to no up-to-date cache data being found
private static final String GENERATION = "GEN-9";
private static final String GENERATION = "GEN-10";
private static final String INDEX_FILES_TASK_ID = "index-java-source-files-task-";

private static final String SYMBOL_KEY = "symbols";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ else if (name != null && name.equals("class")) {
generatedSymbols.add(cachedSymbol);

// TODO: bean index
generatedBeans.add(new CachedBean(docURI, new Bean(beanID, fqBeanClass, location, null, null, null)));
generatedBeans.add(new CachedBean(docURI, new Bean(beanID, fqBeanClass, location, null, null, null, false)));
}
}

Expand Down
Loading

0 comments on commit 02e3ede

Please sign in to comment.