Skip to content

Annotation on enum values don't show up in the element model #33375

Closed
@kevmoo

Description

@kevmoo

Hitting this on pkg:analyzer 0.32.1

Given this input file:

enum Sample {
  notAnnotated,
  @deprecated
  annotated
}

Running this script:

import 'package:analyzer/analyzer.dart';

import 'analysis_utils.dart';

main(List<String> args) async {
  var compUnit = await resolveCompilationUnit(args.single);

  var entity = compUnit.childEntities.single as EnumDeclaration;

  print('FROM ENTITY');
  for (var enumValue in entity.constants) {
    print('  ${enumValue.name}: ${enumValue.metadata.join(', ')}');
  }

  var element = entity.element;

  print('FROM ELEMENT');
  for (var enumValue
      in element.accessors.where((p) => p.returnType == element.type)) {
    print('  ${enumValue.name}: ${enumValue.metadata.join(', ')}');
  }
}

Yields:

FROM ENTITY
  notAnnotated:
  annotated: @deprecated
FROM ELEMENT
  notAnnotated:
  annotated:

I'd expect to see the same metadata on the element items as the entity items

FYI: analysis_utils.dart is https://github.com/dart-lang/json_serializable/blob/master/json_serializable/test/analysis_utils.dart

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions