From 4164fc63b1a6bb546e95659f6c8f0472121e363b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 May 2021 15:49:15 +0200 Subject: [PATCH] CandidateComponentsIndexer introspects any kind of class (including records) Closes gh-26909 --- .../index/processor/CandidateComponentsIndexer.java | 9 +++------ .../index/processor/IndexedStereotypesProvider.java | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/CandidateComponentsIndexer.java b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/CandidateComponentsIndexer.java index fcd0d63e12f..6db5627ebcf 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/CandidateComponentsIndexer.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/CandidateComponentsIndexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.context.index.processor; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.EnumSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -46,9 +45,6 @@ import javax.lang.model.element.TypeElement; */ public class CandidateComponentsIndexer implements Processor { - private static final Set TYPE_KINDS = - Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS, ElementKind.INTERFACE)); - private MetadataStore metadataStore; private MetadataCollector metadataCollector; @@ -136,7 +132,8 @@ public class CandidateComponentsIndexer implements Processor { private static List staticTypesIn(Iterable elements) { List list = new ArrayList<>(); for (Element element : elements) { - if (TYPE_KINDS.contains(element.getKind()) && element.getModifiers().contains(Modifier.STATIC)) { + if ((element.getKind().isClass() || element.getKind() == ElementKind.INTERFACE) && + element.getModifiers().contains(Modifier.STATIC) && element instanceof TypeElement) { list.add((TypeElement) element); } } diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/IndexedStereotypesProvider.java b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/IndexedStereotypesProvider.java index c8ef2b75185..dd244470621 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/IndexedStereotypesProvider.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/IndexedStereotypesProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ class IndexedStereotypesProvider implements StereotypesProvider { public Set getStereotypes(Element element) { Set stereotypes = new LinkedHashSet<>(); ElementKind kind = element.getKind(); - if (kind != ElementKind.CLASS && kind != ElementKind.INTERFACE) { + if (!kind.isClass() && kind != ElementKind.INTERFACE) { return stereotypes; } Set seen = new HashSet<>();