Skip to content

Refactor Error Prone bug patterns to use annotation mirrors and AnnotationNames - #6229

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_975171319
Oct 22, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_975171319

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Refactor Error Prone bug patterns to use annotation mirrors and AnnotationNames

Avoids reflective class-literal-based annotation lookups (getAnnotation(Class<T>)) in Error Prone bug patterns by reading AnnotationMirror and using MoreAnnotations helpers.

Replaces duplicate string literal occurrences across bug patterns with AnnotationNames constants.

Key changes:

  • DoNotCallChecker: updated getDoNotCallValue to use MoreAnnotations.getStringValue(symbol, DO_NOT_CALL_ANNOTATION).
  • IncompatibleModifiersChecker & RequiredModifiersChecker: updated to use MoreAnnotations.getEnumValues(symbol, ...).
  • GuardedByUtils: updated getGuardValues to use sym.getAnnotationMirrors() and MoreAnnotations.getStrings.
  • UnnecessaryAssignment: updated isOptionalInject to use MoreAnnotations.getBooleanValue.
  • AbstractMockChecker, FieldCanBeFinal, ThreadSafety, AssistedParameters: migrated to AnnotationMirror and MoreAnnotations.asElement.
  • BadImport, DifferentNameButSame, NullableOnContainingClass, QualifierWithTypeUse, InvalidTargetingOnScopingAnnotation, RecordComponentAccessorAnnotationConflict, NullablePrimitiveArray, FieldCanBeLocal: updated to use MoreAnnotations.targetsElement / MoreAnnotations.getTargetElementTypes / MoreAnnotations.isTypeAnnotation.
  • ElementPredicates, MissingRuntimeRetention: updated to use MoreAnnotations.hasRuntimeRetention / MoreAnnotations.getRetentionPolicy / ASTHelpers.hasAnnotation.
  • NonOverridingEquals, BanClassLoader: updated to use ASTHelpers.hasAnnotation with string literal.
  • IncompatibleArgumentType: updated to use MoreAnnotations.getStringValue(symbol, ...).
  • InlineMeData, Inliner: updated to use MoreAnnotations.getAnnotationWithSimpleName and MoreAnnotations.getStrings.
  • RestrictedApiChecker: updated to use MoreAnnotations.getTypeValue, MoreAnnotations.getTypes, and MoreAnnotations.getBooleanValue.
  • Replaced annotation string literals with AnnotationNames constants across bug patterns.

@copybara-service
copybara-service Bot force-pushed the test_975171319 branch 4 times, most recently from b9aa241 to 9c1b211 Compare October 22, 2026 18:09
…ationNames

Avoids reflective class-literal-based annotation lookups (`getAnnotation(Class<T>)`) in Error Prone bug patterns by reading `AnnotationMirror` and using `MoreAnnotations` helpers.

Replaces duplicate string literal occurrences across bug patterns with `AnnotationNames` constants.

Key changes:
- `DoNotCallChecker`: updated `getDoNotCallValue` to use `MoreAnnotations.getStringValue(symbol, DO_NOT_CALL_ANNOTATION)`.
- `IncompatibleModifiersChecker` & `RequiredModifiersChecker`: updated to use `MoreAnnotations.getEnumValues(symbol, ...)`.
- `GuardedByUtils`: updated `getGuardValues` to use `sym.getAnnotationMirrors()` and `MoreAnnotations.getStrings`.
- `UnnecessaryAssignment`: updated `isOptionalInject` to use `MoreAnnotations.getBooleanValue`.
- `AbstractMockChecker`, `FieldCanBeFinal`, `ThreadSafety`, `AssistedParameters`: migrated to `AnnotationMirror` and `MoreAnnotations.asElement`.
- `BadImport`, `DifferentNameButSame`, `NullableOnContainingClass`, `QualifierWithTypeUse`, `InvalidTargetingOnScopingAnnotation`, `RecordComponentAccessorAnnotationConflict`, `NullablePrimitiveArray`, `FieldCanBeLocal`: updated to use `MoreAnnotations.targetsElement` / `MoreAnnotations.getTargetElementTypes` / `MoreAnnotations.isTypeAnnotation`.
- `ElementPredicates`, `MissingRuntimeRetention`: updated to use `MoreAnnotations.hasRuntimeRetention` / `MoreAnnotations.getRetentionPolicy` / `ASTHelpers.hasAnnotation`.
- `NonOverridingEquals`, `BanClassLoader`: updated to use `ASTHelpers.hasAnnotation` with string literal.
- `IncompatibleArgumentType`: updated to use `MoreAnnotations.getStringValue(symbol, ...)`.
- `InlineMeData`, `Inliner`: updated to use `MoreAnnotations.getAnnotationWithSimpleName` and `MoreAnnotations.getStrings`.
- `RestrictedApiChecker`: updated to use `MoreAnnotations.getTypeValue`, `MoreAnnotations.getTypes`, and `MoreAnnotations.getBooleanValue`.
- Replaced annotation string literals with `AnnotationNames` constants across bug patterns.

PiperOrigin-RevId: 1004922280
@copybara-service
copybara-service Bot merged commit e5aac42 into master Oct 22, 2026
8 checks passed
@copybara-service
copybara-service Bot deleted the test_975171319 branch October 22, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant