Skip to content

Commit

Permalink
Don't run RootProcessingStep#postProcess if no root element was detec…
Browse files Browse the repository at this point in the history
…ted.

RELNOTES=n/a
PiperOrigin-RevId: 560887928
  • Loading branch information
wanyingd1996 authored and Dagger Team committed Aug 29, 2023
1 parent f5d686d commit b90b416
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
public final class RootProcessingStep extends BaseProcessingStep {

private boolean processed;
// TODO(b/297889547) do not run preProcess and postProcess if supported annotation isn't present
// in the environment.
private boolean hasElementsToProcess = false;
private GeneratesRootInputs generatesRootInputs;

public RootProcessingStep(XProcessingEnv env) {
Expand All @@ -75,6 +78,7 @@ protected ImmutableSet<ClassName> annotationClassNames() {

@Override
public void processEach(ClassName annotation, XElement element) throws Exception {
hasElementsToProcess = true;
XTypeElement rootElement = XElements.asTypeElement(element);
// TODO(bcorso): Move this logic into a separate isolating processor to avoid regenerating it
// for unrelated changes in Gradle.
Expand All @@ -93,6 +97,9 @@ rootElement, originatingRootElement, processingEnv().requireTypeElement(annotati

@Override
protected void postProcess(XProcessingEnv env, XRoundEnv roundEnv) throws Exception {
if (!hasElementsToProcess) {
return;
}
if (!useAggregatingRootProcessor(processingEnv())) {
return;
}
Expand Down

0 comments on commit b90b416

Please sign in to comment.