Skip to content

Commit

Permalink
Support incremental annotation processing with Gradle
Browse files Browse the repository at this point in the history
Closes gh-22150
  • Loading branch information
wilkinsona committed Jun 30, 2020
1 parent 27c458c commit 62aa8ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.autoconfigureprocessor.AutoConfigureAnnotationProcessor,aggregating
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -38,10 +39,21 @@ Tree getTree(Element element) throws Exception {
}

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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor,aggregating

0 comments on commit 62aa8ce

Please sign in to comment.