@@ -19,56 +19,47 @@ class Annotation extends Feature with ModelBuilder {
19
19
final PackageGraph packageGraph;
20
20
21
21
Annotation (this .annotation, this .library, this .packageGraph)
22
- : super (annotation.element! .name);
22
+ : super (annotation.element! .name! );
23
23
24
- String ? _linkedNameWithParameters;
25
24
@override
26
- String get linkedNameWithParameters => _linkedNameWithParameters ?? =
25
+ late final String linkedNameWithParameters =
27
26
packageGraph.rendererFactory.featureRenderer.renderAnnotation (this );
28
27
29
28
/// Return the linked name of the annotation.
30
29
@override
31
30
String get linkedName => annotation.element is PropertyAccessorElement
32
31
? modelBuilder.fromElement (annotation.element! ).linkedName
33
32
// TODO(jcollins-g): consider linking to constructor instead of type?
34
- : modelType! .linkedName;
33
+ : modelType.linkedName;
35
34
36
- ElementType ? _modelType;
37
- ElementType ? get modelType {
38
- if (_modelType == null ) {
39
- var annotatedWith = annotation.element;
40
- if (annotatedWith is ConstructorElement ) {
41
- _modelType = modelBuilder.typeFrom (annotatedWith.returnType, library! );
42
- } else if (annotatedWith is PropertyAccessorElement ) {
43
- _modelType = (modelBuilder.fromElement (annotatedWith.variable)
44
- as GetterSetterCombo )
45
- .modelType;
46
- } else {
47
- assert (false ,
48
- 'non-callable element used as annotation?: ${annotation .element }' );
49
- }
35
+ late final ElementType modelType = () {
36
+ var annotatedWith = annotation.element;
37
+ if (annotatedWith is ConstructorElement ) {
38
+ return modelBuilder.typeFrom (annotatedWith.returnType, library! );
39
+ } else if (annotatedWith is PropertyAccessorElement ) {
40
+ return (modelBuilder.fromElement (annotatedWith.variable)
41
+ as GetterSetterCombo )
42
+ .modelType;
43
+ } else {
44
+ throw StateError (
45
+ 'non-callable element used as annotation?: ${annotation .element }' );
50
46
}
51
- return _modelType;
52
- }
47
+ }();
53
48
54
- String ? _parameterText;
55
- String get parameterText {
56
- // TODO(srawlins): Attempt to revive constructor arguments in an annotation,
57
- // akin to source_gen's Reviver, in order to link to inner components. For
58
- // example, in `@Foo(const Bar(), baz: <Baz>[Baz.one, Baz.two])`, link to
59
- // `Foo`, `Bar`, `Baz`, `Baz.one`, and `Baz.two`.
60
- if (_parameterText == null ) {
61
- var source = annotation.toSource ();
62
- var startIndex = source.indexOf ('(' );
63
- _parameterText =
64
- source.substring (startIndex == - 1 ? source.length : startIndex);
65
- }
66
- return _parameterText! ;
67
- }
49
+ // TODO(srawlins): Attempt to revive constructor arguments in an annotation,
50
+ // akin to source_gen's Reviver, in order to link to inner components. For
51
+ // example, in `@Foo(const Bar(), baz: <Baz>[Baz.one, Baz.two])`, link to
52
+ // `Foo`, `Bar`, `Baz`, `Baz.one`, and `Baz.two`.
53
+ /// The textual representation of the argument(s) supplied to the annotation.
54
+ late final String parameterText = () {
55
+ var source = annotation.toSource ();
56
+ var startIndex = source.indexOf ('(' );
57
+ return source.substring (startIndex == - 1 ? source.length : startIndex);
58
+ }();
68
59
69
60
@override
70
61
bool get isPublic =>
71
- modelType! .isPublic &&
62
+ modelType.isPublic &&
72
63
modelType is DefinedElementType &&
73
64
! packageGraph.invisibleAnnotations
74
65
.contains ((modelType as DefinedElementType ).modelElement);
0 commit comments