Skip to content

Commit

Permalink
Add a flag to configure the default nullness annotation
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 386953444
  • Loading branch information
cushon authored and Error Prone Team committed Jul 26, 2021
1 parent c5218ed commit de0b017
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit de0b017

Please sign in to comment.