Skip to content

Commit 6d76a8e

Browse files
committed
Merge branch '4.7.x' into 4.8.x
2 parents e23ed6a + 4531b5e commit 6d76a8e

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

inject-java/src/main/java/io/micronaut/annotation/processing/BeanDefinitionInjectProcessor.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.micronaut.inject.processing.JavaModelUtils;
3131
import io.micronaut.inject.processing.ProcessingException;
3232
import io.micronaut.inject.visitor.BeanElementVisitor;
33-
import io.micronaut.inject.visitor.ElementPostponedToNextRoundException;
3433
import io.micronaut.inject.writer.AbstractBeanDefinitionBuilder;
3534
import io.micronaut.inject.writer.BeanDefinitionVisitor;
3635
import io.micronaut.inject.writer.BeanDefinitionWriter;
@@ -92,7 +91,7 @@ public class BeanDefinitionInjectProcessor extends AbstractInjectAnnotationProce
9291

9392
private Set<String> beanDefinitions;
9493
private final Set<String> processed = new HashSet<>();
95-
private final Map<String, Element> postponed = new HashMap<>();
94+
private final Map<String, PostponeToNextRoundException> postponed = new HashMap<>();
9695

9796
@Override
9897
public final synchronized void init(ProcessingEnvironment processingEnv) {
@@ -198,10 +197,7 @@ public final boolean process(Set<? extends TypeElement> annotations, RoundEnviro
198197
error(((JavaNativeElement) ex.getOriginatingElement()).element(), ex.getMessage());
199198
} catch (PostponeToNextRoundException e) {
200199
processed.remove(className);
201-
postponed.put(className, (Element) e.getErrorElement());
202-
} catch (ElementPostponedToNextRoundException e) {
203-
processed.remove(className);
204-
postponed.put(className, ((JavaNativeElement) e.getOriginatingElement().getNativeType()).element());
200+
postponed.put(className, e);
205201
}
206202
}
207203
}
@@ -213,9 +209,9 @@ public final boolean process(Set<? extends TypeElement> annotations, RoundEnviro
213209
processing round.
214210
*/
215211
if (processingOver) {
216-
for (Map.Entry<String, Element> e : postponed.entrySet()) {
217-
javaVisitorContext.warn("Bean definition generation [" + e.getKey() + "] skipped from processing because of prior error." +
218-
" This error is normally due to missing classes on the classpath. Verify the compilation classpath is correct to resolve the problem.", e.getValue());
212+
for (Map.Entry<String, PostponeToNextRoundException> e : postponed.entrySet()) {
213+
javaVisitorContext.warn("Bean definition generation [" + e.getKey() + "] skipped from processing because of prior error: [" + e.getValue().getPath() + "]." +
214+
" This error is normally due to missing classes on the classpath. Verify the compilation classpath is correct to resolve the problem.", (Element) e.getValue().getErrorElement());
219215
}
220216

221217
try {

inject-java/src/main/java/io/micronaut/annotation/processing/visitor/JavaClassElement.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import io.micronaut.inject.ast.utils.AstBeanPropertiesUtils;
4343
import io.micronaut.inject.ast.utils.EnclosedElementsQuery;
4444
import io.micronaut.inject.processing.JavaModelUtils;
45-
import io.micronaut.inject.visitor.ElementPostponedToNextRoundException;
4645

4746
import javax.lang.model.element.Element;
4847
import javax.lang.model.element.ElementKind;
@@ -272,27 +271,22 @@ public boolean isPrimitive() {
272271
@Override
273272
public Collection<ClassElement> getInterfaces() {
274273
if (resolvedInterfaces == null) {
275-
resolvedInterfaces = classElement.getInterfaces().stream()
276-
.map(mirror -> {
277-
if (mirror.getKind() == TypeKind.ERROR) {
278-
throw new ElementPostponedToNextRoundException(this);
279-
}
280-
return newClassElement(mirror, getTypeArguments());
281-
}).toList();
274+
resolvedInterfaces = classElement.getInterfaces().stream().filter(this::onlyAvailable).map(mirror -> newClassElement(mirror, getTypeArguments())).toList();
282275
}
283276
return resolvedInterfaces;
284277
}
285278

279+
private boolean onlyAvailable(TypeMirror mirror) {
280+
return !(mirror instanceof DeclaredType declaredType) || declaredType.getKind() != TypeKind.ERROR;
281+
}
282+
286283
@Override
287284
public Optional<ClassElement> getSuperType() {
288285
if (resolvedSuperType == null) {
289286
final TypeMirror superclass = classElement.getSuperclass();
290287
if (superclass == null) {
291288
return Optional.empty();
292289
}
293-
if (superclass.getKind() == TypeKind.ERROR) {
294-
throw new ElementPostponedToNextRoundException(this);
295-
}
296290
final Element element = visitorContext.getTypes().asElement(superclass);
297291
if (element instanceof TypeElement superElement) {
298292
if (Object.class.getName().equals(superElement.getQualifiedName().toString())) {

inject-java/src/test/groovy/io/micronaut/visitors/PostponedVisitorsSpec.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.micronaut.visitors
33

44
import io.micronaut.annotation.processing.test.AbstractTypeElementSpec
55
import io.micronaut.inject.writer.BeanDefinitionVisitor
6+
import spock.lang.PendingFeature
67

78
class PostponedVisitorsSpec extends AbstractTypeElementSpec {
89

@@ -30,6 +31,7 @@ public record Walrus (
3031
definition
3132
}
3233

34+
@PendingFeature(reason = "It is currently not possible to implement a generated interface")
3335
void 'test postpone introduction generation implementing generated interface'() {
3436
when:
3537
def context = buildContext('test.MyIntroduction' + BeanDefinitionVisitor.PROXY_SUFFIX, '''

0 commit comments

Comments
 (0)