Skip to content

Make source-export annotation cleanup syntax-aware #178

Description

@feO2x

Problem

CleanupStep removes several annotations using exact string replacement or whole-line classification. This is unreliable when an annotation is combined with other attributes or spans multiple lines.

A source export configured with these options can therefore retain JetBrains annotation usages even though their definitions and using directive are excluded:

  • IncludeJetBrainsAnnotations=false
  • IncludeJetBrainsAnnotationsUsing=false
  • RemoveContractAnnotations=true
  • IncludeValidatedNotNullAttribute=false
  • RemoveValidatedNotNull=true

Concrete cases in the current source:

  1. Combined attribute lists such as [NotNull, ValidatedNotNull] are not handled by the exact [ValidatedNotNull] replacement.
  2. The multiline ContractAnnotation on Check.IsSameAs is classified one line at a time. Only the line beginning with [ContractAnnotation( is removed, leaving its argument and closing lines behind.
  3. NoEnumeration usages remain because there is no corresponding cleanup option. This can leave generated code referring to an attribute whose definition was intentionally excluded.

Consumers currently need an additional post-processing step to remove these tokens while preserving adjacent nullable-flow annotations such as NotNull and NotNullWhen.

Expected behavior

The exporter should remove configured JetBrains annotations regardless of whether they:

  • occupy a standalone attribute list,
  • share an attribute list with other annotations,
  • appear in adjacent attribute lists, or
  • span multiple lines.

Adjacent annotations that are not being removed must remain intact. Excluding JetBrains annotations should also provide a supported way to remove NoEnumeration usages.

Suggested acceptance criteria

  • RemoveValidatedNotNull removes ValidatedNotNull from combined and standalone attribute lists while preserving NotNull.
  • RemoveContractAnnotations removes both single-line and multiline ContractAnnotation attributes without removing neighboring attributes.
  • NoEnumeration usages can be removed when JetBrains annotations are excluded.
  • Cleanup tests cover combined, adjacent, and multiline attribute syntax.
  • Generated output compiles without JetBrains.Annotations when its definitions and using directive are excluded.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions