Support incremental annotation processing with Gradle

Closes gh-22150
This commit is contained in:
Andy Wilkinson 2020-06-30 11:27:32 +01:00
parent 27c458ca26
commit 62aa8ce107
3 changed files with 19 additions and 5 deletions

View File

@ -0,0 +1 @@
org.springframework.boot.autoconfigureprocessor.AutoConfigureAnnotationProcessor,aggregating

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -16,6 +16,7 @@
package org.springframework.boot.configurationprocessor.fieldvalues.javac;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.annotation.processing.ProcessingEnvironment;
@ -38,10 +39,21 @@ final class Trees extends ReflectionWrapper {
}
static Trees instance(ProcessingEnvironment env) throws Exception {
ClassLoader classLoader = env.getClass().getClassLoader();
Class<?> type = findClass(classLoader, "com.sun.source.util.Trees");
Method method = findMethod(type, "instance", ProcessingEnvironment.class);
return new Trees(method.invoke(null, env));
try {
ClassLoader classLoader = env.getClass().getClassLoader();
Class<?> type = findClass(classLoader, "com.sun.source.util.Trees");
Method method = findMethod(type, "instance", ProcessingEnvironment.class);
return new Trees(method.invoke(null, env));
}
catch (Exception ex) {
return instance(unwrap(env));
}
}
private static ProcessingEnvironment unwrap(ProcessingEnvironment wrapper) throws Exception {
Field delegateField = wrapper.getClass().getDeclaredField("delegate");
delegateField.setAccessible(true);
return (ProcessingEnvironment) delegateField.get(wrapper);
}
}

View File

@ -0,0 +1 @@
org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor,aggregating