Skip to content

Commit

Permalink
Respect dagger.formatGeneratedSource in AndroidProcessor
Browse files Browse the repository at this point in the history
Resolves google#3531
  • Loading branch information
ZacSweers committed Aug 12, 2022
1 parent 4048f51 commit 8269fce
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion java/dagger/android/processor/AndroidProcessor.java
Expand Up @@ -53,10 +53,17 @@
public final class AndroidProcessor extends BasicAnnotationProcessor {
private static final String FLAG_EXPERIMENTAL_USE_STRING_KEYS =
"dagger.android.experimentalUseStringKeys";
private static final String FLAG_FORMAT_GENERATED_SOURCES =
"dagger.formatGeneratedSource";

@Override
protected Iterable<? extends Step> steps() {
Filer filer = new FormattingFiler(processingEnv.getFiler());
Filer filer;
if (formatGeneratedSources()) {
filer = new FormattingFiler(processingEnv.getFiler());
} else {
filer = processingEnv.getFiler();
}
Messager messager = processingEnv.getMessager();
Elements elements = processingEnv.getElementUtils();
Types types = processingEnv.getTypeUtils();
Expand Down Expand Up @@ -92,6 +99,27 @@ private boolean useStringKeys() {
}
}

private boolean formatGeneratedSources() {
if (!processingEnv.getOptions().containsKey(FLAG_FORMAT_GENERATED_SOURCES)) {
return false;
}
String flagValue = processingEnv.getOptions().get(FLAG_FORMAT_GENERATED_SOURCES);
if (Ascii.equalsIgnoreCase(flagValue, "enabled")) {
return true;
} else if (flagValue == null || Ascii.equalsIgnoreCase(flagValue, "disabled")) {
return false;
} else {
processingEnv
.getMessager()
.printMessage(
ERROR,
String.format(
"Unknown flag value: %s. %s must be set to either 'enabled' or 'disabled'.",
flagValue, FLAG_FORMAT_GENERATED_SOURCES));
return false;
}
}

@Override
public Set<String> getSupportedOptions() {
return ImmutableSet.of(FLAG_EXPERIMENTAL_USE_STRING_KEYS);
Expand Down

0 comments on commit 8269fce

Please sign in to comment.