Title: Theory / Unimportant / CS / Programming / Java / Android / Annotation
Tags: declaration todo_declaration seen_description automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://developer.android.com/studio/write/annotations
Page: https://developer.android.com/studio/write/annotations

Instruction: @NonNull type var;
Effect: Warns if a Nullable value is assigned to var
Language: java

Instruction: @Nullable type var;
Effect: All access to var should consider that it may be `null`
Language: java

Instruction: @StringRes int var;
Meaning: Declare that var is an id of a string ressource
Language: java

Instruction: @DrawableRes int var;
Meaning: Declare that var is an id of a drawable ressource
Language: java

Instruction: @DimenRes int var;
Meaning: Declare that var is an id of a dimension ressource
Language: java

Instruction: @ColorRes int var;
Meaning: Declare that var is an id of a color ressource
Language: java

Instruction: @InterpolateRes int var;
Meaning: Declare that var is an id of a interpolate ressource
Language: java

Instruction: @AnyRes int var;
Meaning: Declare that var is an id of an android ressource of any type
Language: java

Instruction: @Int/FloatRange(from=min) int/float var;
Effect: Warns if var get a value less than min
Language: java

Instruction: @Int/FloatRange(from=max) int/float var;
Effect: Warns if var get a value greater than max
Language: java

Instruction: @Size(min=m) SizableType var;
Effect: Warns if var gets a value whose .size() is less than m
Language: java

Instruction: @Size(max=M) SizableType var;
Effect: Warns if var gets a value whose .size() is greater than M
Language: java

Instruction: @Size(s) SizableType var;
Effect: Warns if var gets a value whose .size() is not s
Language: java

Instruction: @RequiresPermission(foo)
methodDeclaration
Meaning: Indicates that method requires the android permission foo
Language: java

Instruction: @RequiresPermission(
  anyOf={foo_1,
  ...,
  foo_n}
)
methodDeclaration
Meaning: Indicates that method requires one of the android permission foo_i
Language: java

Instruction: @RequiresPermission(
  allOf={foo_1,
  ...,
  foo_n}
)
methodDeclaration
Meaning: Indicates that method requires all of the android permission foo_i
Language: java
Extra: more details?

Instruction: @CheckResult
methodDeclaration
Meaning: Warns if a call to the declared method ignores its result
Language: java

Instruction: @CallSuper
methodDeclaration
Effect: Warns if current method is overriden without call to super.
Language: java

Instruction: @Retention(
  RetentionPolicy.SOURCE
)
@Int/StringDef(
  {CONST_1, ..., CONST_N}
)
public @interface Name {}
Effect: Indicate that annotation `@Name int/String` represents one of int/String CONST_i
Language: java

Instruction: @Retention(
  RetentionPolicy.SOURCE
)
@IntDef(
  flag=true,
  {CONST_1, ..., CONST_N}
)
public @interface Name {}
Effect: Indicate that annotation `@Name int` represents a boolean combination of CONST_I
Language: java

Instruction: @Keep declaration
Effect: declaration is not removed when code is minified
Language: java

Instruction: @VisibleForTesting
declaration
Effect: Outside of Test, consider that declaration is private
Language: java

Instruction: @VisibleForTesting(otherwise = VisibleForTesting.Protected)
declaration
Effect: Outside of Test, consider that declaration is protected
Language: java

Instruction: @VisibleForTesting(
otherwise = VisibleForTesting.NONE
)
declaration
Meaning: Warns if the declared value is used outside of tests
Language: java
Abbreviation: @RestrictTo(TEST)
declaration

Instruction: @RestrictTo(SUBCLASSES)
declaration
Meaning: Warns if the declared value is used outside of subclasses
Language: java
Intuition: (More restricted than protected)

Instruction: @RestrictTo(GROUP_ID)
declaration
Meaning: Warns if the declared value is used outside of the library where it is defined
Language: java