From de0b0178d9131207399077767939a31c1aa67398 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 26 Jul 2021 14:00:11 -0700 Subject: [PATCH] Add a flag to configure the default nullness annotation PiperOrigin-RevId: 386953444 --- .../errorprone/bugpatterns/nullness/NullnessFixes.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessFixes.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessFixes.java index e07f438a5ae..44acbe04f1f 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessFixes.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessFixes.java @@ -16,6 +16,7 @@ package com.google.errorprone.bugpatterns.nullness; +import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.VisitorState; import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.util.FindIdentifiers; @@ -63,8 +64,14 @@ private static String getQualifiedName(VisitorState state, SuggestedFix.Builder */ // TODO(cpovirk): Suggest @NullableDecl if the code uses that. Symbol sym = FindIdentifiers.findIdent("Nullable", state, KindSelector.VAL_TYP); + ErrorProneFlags flags = state.errorProneOptions().getFlags(); String defaultType = - state.isAndroidCompatible() ? "androidx.annotation.Nullable" : "javax.annotation.Nullable"; + flags + .get("Nullness:DefaultNullnessAnnotation") + .orElse( + state.isAndroidCompatible() + ? "androidx.annotation.Nullable" + : "javax.annotation.Nullable"); if (sym != null) { ClassSymbol classSym = (ClassSymbol) sym; if (classSym.isAnnotationType()) {