Skip to content

Feature Request: Allow specifying a replacement type in @Deprecated annotation #60454

@stan-at-work

Description

@stan-at-work

Problem

Currently, when marking something as @Deprecated, we have to manually specify the recommended replacement in the message string:

@Deprecated("Don't use this anymore, use CoreScannerState<T>")

This requires manual parsing of the message by the developer and does not provide a structured way for tooling to suggest replacements.

Proposed Solution

Introduce a replacement parameter in the @Deprecated annotation that explicitly defines the alternative type or member:

@Deprecated("Don't use this anymore", replacement: CoreScannerState<T>)

Benefits:

  • The IDE can automatically extract and display the replacement.
  • Tooling can provide direct refactoring suggestions.
  • The message remains clear while keeping metadata structured.

Current Behavior

When hovering over a deprecated member, the IDE tooltip says:

"... Try replacing the use of the deprecated member with the replacement."

However, "the replacement" is not configurable, and the developer must manually read and interpret the message.

Expected Behavior

By allowing a replacement argument, the IDE and tools can explicitly guide developers on what to use instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions