blob: b12f41d293a63bc1c22319dad2b8d368be3647ce [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'element_text.dart';
import 'elements_base.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ElementsKeepLinkingTest);
defineReflectiveTests(ElementsFromBytesTest);
// defineReflectiveTests(ApplyCheckElementTextReplacements);
});
}
@reflectiveTest
class ApplyCheckElementTextReplacements {
test_applyReplacements() {
applyCheckElementTextReplacements();
}
}
@reflectiveTest
class ElementsFromBytesTest extends ElementsTest {
@override
bool get keepLinkingLibraries => false;
}
@reflectiveTest
class ElementsKeepLinkingTest extends ElementsTest {
@override
bool get keepLinkingLibraries => true;
}
abstract class ElementsTest extends ElementsBaseTest {
test_augmentation_augmentationImports_augmentation() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
import augment 'b.dart';
class A {}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'a.dart';
class B {}
''');
final library = await buildLibrary(r'''
import augment 'a.dart';
class C {}
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
augmentationImports
package:test/b.dart
definingUnit
classes
class B @32
constructors
synthetic @-1
definingUnit
classes
class A @60
constructors
synthetic @-1
definingUnit
classes
class C @31
constructors
synthetic @-1
''');
}
test_augmentation_class_constructor_superConstructor_generic_named() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class B extends A<int> {
B() : super.named(0);
}
''');
var library = await buildLibrary('''
import augment 'a.dart';
class A<T> {
A.named(T a);
}
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
class B @35
supertype: A<int>
constructors
@56
superConstructor: ConstructorMember
base: self::@class::A::@constructor::named
substitution: {T: int}
definingUnit
classes
class A @31
typeParameters
covariant T @33
defaultType: dynamic
constructors
named @42
periodOffset: 41
nameEnd: 47
parameters
requiredPositional a @50
type: T
''');
}
test_augmentation_class_constructor_superConstructor_notGeneric_named() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class B extends A {
B() : super.named();
}
''');
var library = await buildLibrary('''
import augment 'a.dart';
class A {
A.named();
}
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
class B @35
supertype: A
constructors
@51
superConstructor: self::@class::A::@constructor::named
definingUnit
classes
class A @31
constructors
named @39
periodOffset: 38
nameEnd: 44
''');
}
test_augmentation_class_constructor_superConstructor_notGeneric_unnamed_explicit() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class B extends A {
B() : super();
}
''');
var library = await buildLibrary('''
import augment 'a.dart';
class A {}
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
class B @35
supertype: A
constructors
@51
superConstructor: self::@class::A::@constructor::•
definingUnit
classes
class A @31
constructors
synthetic @-1
''');
}
test_augmentation_class_notSimplyBounded_circularity_via_typedef() async {
// C's type parameter T is not simply bounded because its bound, F, expands
// to `dynamic F(C)`, which refers to C.
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class C<T extends F> {}
''');
var library = await buildLibrary('''
import augment 'a.dart';
typedef F(C value);
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
notSimplyBounded class C @35
typeParameters
covariant T @37
bound: dynamic
defaultType: dynamic
constructors
synthetic @-1
definingUnit
typeAliases
functionTypeAliasBased notSimplyBounded F @33
aliasedType: dynamic Function(C<dynamic>)
aliasedElement: GenericFunctionTypeElement
parameters
requiredPositional value @37
type: C<dynamic>
returnType: dynamic
''');
}
test_augmentation_class_notSimplyBounded_self() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class C<T extends C> {}
''');
var library = await buildLibrary('''
import augment 'a.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
notSimplyBounded class C @35
typeParameters
covariant T @37
bound: C<dynamic>
defaultType: dynamic
constructors
synthetic @-1
definingUnit
''');
}
test_augmentation_defaultValue_class_field() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static const a = 0;
}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
void f({int x = A.a}) {}
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
functions
f @51
parameters
optionalNamed x @58
type: int
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: A @62
staticElement: package:test/a.dart::@class::A
staticType: null
period: . @63
identifier: SimpleIdentifier
token: a @64
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
returnType: void
definingUnit
''');
}
test_augmentation_defaultValue_prefix_class_field() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static const a = 0;
}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart' as prefix;
void f({int x = prefix.A.a}) {}
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart as prefix @48
definingUnit
functions
f @61
parameters
optionalNamed x @68
type: int
constantInitializer
PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix @72
staticElement: self::@augmentation::package:test/b.dart::@prefix::prefix
staticType: null
period: . @78
identifier: SimpleIdentifier
token: A @79
staticElement: package:test/a.dart::@class::A
staticType: null
staticElement: package:test/a.dart::@class::A
staticType: null
operator: . @80
propertyName: SimpleIdentifier
token: a @81
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
staticType: int
returnType: void
definingUnit
''');
}
test_augmentation_documented() async {
newFile('$testPackageLibPath/a.dart', r'''
/// My documentation.
library augment 'test.dart';
''');
final library = await buildLibrary(r'''
import augment 'a.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
documentationComment: /// My documentation.
definingUnit
definingUnit
''');
}
test_augmentation_importScope_constant() async {
newFile('$testPackageLibPath/a.dart', r'''
final a = 0;
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
const b = a;
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
topLevelVariables
static const b @52
type: int
constantInitializer
SimpleIdentifier
token: a @56
staticElement: package:test/a.dart::@getter::a
staticType: int
accessors
synthetic static get b @-1
returnType: int
definingUnit
''');
}
test_augmentation_importScope_constant_class_field() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static const a = 0;
}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
const b = A.a;
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
topLevelVariables
static const b @52
type: int
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: A @56
staticElement: package:test/a.dart::@class::A
staticType: null
period: . @57
identifier: SimpleIdentifier
token: a @58
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
accessors
synthetic static get b @-1
returnType: int
definingUnit
''');
}
test_augmentation_importScope_constant_instanceCreation() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
const A {};
}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
const a = A();
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
topLevelVariables
static const a @52
type: A
constantInitializer
InstanceCreationExpression
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: A @56
staticElement: package:test/a.dart::@class::A
staticType: null
type: A
staticElement: package:test/a.dart::@class::A::@constructor::•
argumentList: ArgumentList
leftParenthesis: ( @57
rightParenthesis: ) @58
staticType: A
accessors
synthetic static get a @-1
returnType: A
definingUnit
''');
}
test_augmentation_importScope_constant_prefix_class_field() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static const a = 0;
}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart' as prefix;
const b = prefix.A.a;
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart as prefix @48
definingUnit
topLevelVariables
static const b @62
type: int
constantInitializer
PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix @66
staticElement: self::@augmentation::package:test/b.dart::@prefix::prefix
staticType: null
period: . @72
identifier: SimpleIdentifier
token: A @73
staticElement: package:test/a.dart::@class::A
staticType: null
staticElement: package:test/a.dart::@class::A
staticType: null
operator: . @74
propertyName: SimpleIdentifier
token: a @75
staticElement: package:test/a.dart::@class::A::@getter::a
staticType: int
staticType: int
accessors
synthetic static get b @-1
returnType: int
definingUnit
''');
}
test_augmentation_importScope_prefixed() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart' as prefix;
prefix.A f() {}
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart as prefix @48
definingUnit
functions
f @65
returnType: A
definingUnit
''');
}
test_augmentation_importScope_topInference() async {
newFile('$testPackageLibPath/a.dart', r'''
final a = 0;
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
final b = a;
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
''');
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
topLevelVariables
static final b @52
type: int
accessors
synthetic static get b @-1
returnType: int
definingUnit
''');
}
test_augmentation_importScope_types_augmentation() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'a.dart';
A f() {}
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
A f() {}
''');
// The augmentation imports `a.dart`, so can resolve `A`.
// But the library does not import, so there `A` is unresolved.
checkElementText(library, r'''
library
augmentationImports
package:test/b.dart
imports
package:test/a.dart
definingUnit
functions
f @48
returnType: A
definingUnit
functions
f @27
returnType: dynamic
''');
}
test_augmentation_importScope_types_library() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
A f() {}
''');
final library = await buildLibrary(r'''
import augment 'b.dart';
import 'a.dart';
A f() {}
''');
// The library imports `a.dart`, so can resolve `A`.
// But the augmentation does not import, so there `A` is unresolved.
checkElementText(library, r'''
library
imports
package:test/a.dart
augmentationImports
package:test/b.dart
definingUnit
functions
f @31
returnType: dynamic
definingUnit
functions
f @44
returnType: A
''');
}
test_augmentation_libraryExports_library() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
export 'dart:async';
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
export 'dart:collection';
export 'dart:math';
''');
final library = await buildLibrary(r'''
import 'dart:io';
import augment 'a.dart';
import augment 'b.dart';
''');
checkElementText(library, r'''
library
imports
dart:io
augmentationImports
package:test/a.dart
exports
dart:async
definingUnit
package:test/b.dart
exports
dart:collection
dart:math
definingUnit
definingUnit
''');
}
test_augmentation_libraryImports_library() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
import 'dart:async';
''');
newFile('$testPackageLibPath/b.dart', r'''
library augment 'test.dart';
import 'dart:collection';
import 'dart:math';
''');
final library = await buildLibrary(r'''
import 'dart:io';
import augment 'a.dart';
import augment 'b.dart';
''');
checkElementText(library, r'''
library
imports
dart:io
augmentationImports
package:test/a.dart
imports
dart:async
definingUnit
package:test/b.dart
imports
dart:collection
dart:math
definingUnit
definingUnit
''');
}
test_augmentation_topScope_augmentation() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
class A {}
A f() {}
''');
final library = await buildLibrary(r'''
import augment 'a.dart';
A f() {}
''');
// The augmentation declares `A`, and can it be used in the library.
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
classes
class A @35
constructors
synthetic @-1
functions
f @42
returnType: A
definingUnit
functions
f @27
returnType: A
''');
}
test_augmentation_topScope_library() async {
newFile('$testPackageLibPath/a.dart', r'''
library augment 'test.dart';
A f() {}
''');
final library = await buildLibrary(r'''
import augment 'a.dart';
class A {}
A f() {}
''');
// The library declares `A`, and can it be used in the augmentation.
checkElementText(library, r'''
library
augmentationImports
package:test/a.dart
definingUnit
functions
f @31
returnType: A
definingUnit
classes
class A @31
constructors
synthetic @-1
functions
f @38
returnType: A
''');
}
test_class_abstract() async {
var library = await buildLibrary('abstract class C {}');
checkElementText(library, r'''
library
definingUnit
classes
abstract class C @15
constructors
synthetic @-1
''');
}
test_class_constructor_const() async {
var library = await buildLibrary('class C { const C(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @16
''');
}
test_class_constructor_const_external() async {
var library = await buildLibrary('class C { external const C(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
external const @25
''');
}
test_class_constructor_documented() async {
var library = await buildLibrary('''
class C {
/**
* Docs
*/
C();
}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
@34
documentationComment: /**\n * Docs\n */
''');
}
test_class_constructor_explicit_named() async {
var library = await buildLibrary('class C { C.foo(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
foo @12
periodOffset: 11
nameEnd: 15
''');
}
test_class_constructor_explicit_type_params() async {
var library = await buildLibrary('class C<T, U> { C(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
covariant U @11
defaultType: dynamic
constructors
@16
''');
}
test_class_constructor_explicit_unnamed() async {
var library = await buildLibrary('class C { C(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
@10
''');
}
test_class_constructor_external() async {
var library = await buildLibrary('class C { external C(); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
external @19
''');
}
test_class_constructor_factory() async {
var library = await buildLibrary('class C { factory C() => throw 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
factory @18
''');
}
test_class_constructor_field_formal_dynamic_dynamic() async {
var library =
await buildLibrary('class C { dynamic x; C(dynamic this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @18
type: dynamic
constructors
@21
parameters
requiredPositional final this.x @36
type: dynamic
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_dynamic_typed() async {
var library = await buildLibrary('class C { dynamic x; C(int this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @18
type: dynamic
constructors
@21
parameters
requiredPositional final this.x @32
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_dynamic_untyped() async {
var library = await buildLibrary('class C { dynamic x; C(this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @18
type: dynamic
constructors
@21
parameters
requiredPositional final this.x @28
type: dynamic
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_functionTyped_noReturnType() async {
var library = await buildLibrary(r'''
class C {
var x;
C(this.x(double b));
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @16
type: dynamic
constructors
@21
parameters
requiredPositional final this.x @28
type: dynamic Function(double)
parameters
requiredPositional b @37
type: double
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_functionTyped_withReturnType() async {
var library = await buildLibrary(r'''
class C {
var x;
C(int this.x(double b));
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @16
type: dynamic
constructors
@21
parameters
requiredPositional final this.x @32
type: int Function(double)
parameters
requiredPositional b @41
type: double
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_functionTyped_withReturnType_generic() async {
var library = await buildLibrary(r'''
class C {
Function() f;
C(List<U> this.f<T, U>(T t));
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
f @23
type: dynamic Function()
constructors
@28
parameters
requiredPositional final this.f @43
type: List<U> Function<T, U>(T)
typeParameters
covariant T @45
covariant U @48
parameters
requiredPositional t @53
type: T
field: self::@class::C::@field::f
accessors
synthetic get f @-1
returnType: dynamic Function()
synthetic set f @-1
parameters
requiredPositional _f @-1
type: dynamic Function()
returnType: void
''');
}
test_class_constructor_field_formal_multiple_matching_fields() async {
// This is a compile-time error but it should still analyze consistently.
var library = await buildLibrary('class C { C(this.x); int x; String x; }',
allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @25
type: int
x @35
type: String
constructors
@10
parameters
requiredPositional final this.x @17
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional _x @-1
type: int
returnType: void
synthetic get x @-1
returnType: String
synthetic set x @-1
parameters
requiredPositional _x @-1
type: String
returnType: void
''');
}
test_class_constructor_field_formal_no_matching_field() async {
// This is a compile-time error but it should still analyze consistently.
var library =
await buildLibrary('class C { C(this.x); }', allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
@10
parameters
requiredPositional final this.x @17
type: dynamic
field: <null>
''');
}
test_class_constructor_field_formal_typed_dynamic() async {
var library = await buildLibrary('class C { num x; C(dynamic this.x); }',
allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: num
constructors
@17
parameters
requiredPositional final this.x @32
type: dynamic
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: num
synthetic set x @-1
parameters
requiredPositional _x @-1
type: num
returnType: void
''');
}
test_class_constructor_field_formal_typed_typed() async {
var library = await buildLibrary('class C { num x; C(int this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: num
constructors
@17
parameters
requiredPositional final this.x @28
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: num
synthetic set x @-1
parameters
requiredPositional _x @-1
type: num
returnType: void
''');
}
test_class_constructor_field_formal_typed_untyped() async {
var library = await buildLibrary('class C { num x; C(this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: num
constructors
@17
parameters
requiredPositional final this.x @24
type: num
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: num
synthetic set x @-1
parameters
requiredPositional _x @-1
type: num
returnType: void
''');
}
test_class_constructor_field_formal_untyped_dynamic() async {
var library = await buildLibrary('class C { var x; C(dynamic this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: dynamic
constructors
@17
parameters
requiredPositional final this.x @32
type: dynamic
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_untyped_typed() async {
var library = await buildLibrary('class C { var x; C(int this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: dynamic
constructors
@17
parameters
requiredPositional final this.x @28
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_field_formal_untyped_untyped() async {
var library = await buildLibrary('class C { var x; C(this.x); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: dynamic
constructors
@17
parameters
requiredPositional final this.x @24
type: dynamic
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_constructor_fieldFormal_named_noDefault() async {
var library = await buildLibrary('class C { int x; C({this.x}); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: int
constructors
@17
parameters
optionalNamed final this.x @25
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional _x @-1
type: int
returnType: void
''');
}
test_class_constructor_fieldFormal_named_withDefault() async {
var library = await buildLibrary('class C { int x; C({this.x: 42}); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: int
constructors
@17
parameters
optionalNamed final this.x @25
type: int
constantInitializer
IntegerLiteral
literal: 42 @28
staticType: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional _x @-1
type: int
returnType: void
''');
}
test_class_constructor_fieldFormal_optional_noDefault() async {
var library = await buildLibrary('class C { int x; C([this.x]); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: int
constructors
@17
parameters
optionalPositional final this.x @25
type: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional _x @-1
type: int
returnType: void
''');
}
test_class_constructor_fieldFormal_optional_withDefault() async {
var library = await buildLibrary('class C { int x; C([this.x = 42]); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: int
constructors
@17
parameters
optionalPositional final this.x @25
type: int
constantInitializer
IntegerLiteral
literal: 42 @29
staticType: int
field: self::@class::C::@field::x
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional _x @-1
type: int
returnType: void
''');
}
test_class_constructor_implicit_type_params() async {
var library = await buildLibrary('class C<T, U> {}');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
covariant U @11
defaultType: dynamic
constructors
synthetic @-1
''');
}
test_class_constructor_initializers_assertInvocation() async {
var library = await buildLibrary('''
class C {
const C(int x) : assert(x >= 42);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @18
parameters
requiredPositional x @24
type: int
constantInitializers
AssertInitializer
assertKeyword: assert @29
leftParenthesis: ( @35
condition: BinaryExpression
leftOperand: SimpleIdentifier
token: x @36
staticElement: self::@class::C::@constructor::•::@parameter::x
staticType: int
operator: >= @38
rightOperand: IntegerLiteral
literal: 42 @41
staticType: int
staticElement: dart:core::@class::num::@method::>=
staticInvokeType: bool Function(num)
staticType: bool
rightParenthesis: ) @43
''');
}
test_class_constructor_initializers_assertInvocation_message() async {
var library = await buildLibrary('''
class C {
const C(int x) : assert(x >= 42, 'foo');
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @18
parameters
requiredPositional x @24
type: int
constantInitializers
AssertInitializer
assertKeyword: assert @29
leftParenthesis: ( @35
condition: BinaryExpression
leftOperand: SimpleIdentifier
token: x @36
staticElement: self::@class::C::@constructor::•::@parameter::x
staticType: int
operator: >= @38
rightOperand: IntegerLiteral
literal: 42 @41
staticType: int
staticElement: dart:core::@class::num::@method::>=
staticInvokeType: bool Function(num)
staticType: bool
comma: , @43
message: SimpleStringLiteral
literal: 'foo' @45
rightParenthesis: ) @50
''');
}
test_class_constructor_initializers_field() async {
var library = await buildLibrary('''
class C {
final x;
const C() : x = 42;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: dynamic
constructors
const @29
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: x @35
staticElement: self::@class::C::@field::x
staticType: null
equals: = @37
expression: IntegerLiteral
literal: 42 @39
staticType: int
accessors
synthetic get x @-1
returnType: dynamic
''');
}
test_class_constructor_initializers_field_notConst() async {
var library = await buildLibrary('''
class C {
final x;
const C() : x = foo();
}
int foo() => 42;
''', allowErrors: true);
// It is OK to keep non-constant initializers.
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: dynamic
constructors
const @29
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: x @35
staticElement: self::@class::C::@field::x
staticType: null
equals: = @37
expression: MethodInvocation
methodName: SimpleIdentifier
token: foo @39
staticElement: self::@function::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: ( @42
rightParenthesis: ) @43
staticInvokeType: int Function()
staticType: int
accessors
synthetic get x @-1
returnType: dynamic
functions
foo @52
returnType: int
''');
}
test_class_constructor_initializers_field_optionalPositionalParameter() async {
var library = await buildLibrary('''
class A {
final int _f;
const A([int f = 0]) : _f = f;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
fields
final _f @22
type: int
constructors
const @34
parameters
optionalPositional f @41
type: int
constantInitializer
IntegerLiteral
literal: 0 @45
staticType: int
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: _f @51
staticElement: self::@class::A::@field::_f
staticType: null
equals: = @54
expression: SimpleIdentifier
token: f @56
staticElement: self::@class::A::@constructor::•::@parameter::f
staticType: int
accessors
synthetic get _f @-1
returnType: int
''');
}
test_class_constructor_initializers_field_withParameter() async {
var library = await buildLibrary('''
class C {
final x;
const C(int p) : x = 1 + p;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: dynamic
constructors
const @29
parameters
requiredPositional p @35
type: int
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: x @40
staticElement: self::@class::C::@field::x
staticType: null
equals: = @42
expression: BinaryExpression
leftOperand: IntegerLiteral
literal: 1 @44
staticType: int
operator: + @46
rightOperand: SimpleIdentifier
token: p @48
staticElement: self::@class::C::@constructor::•::@parameter::p
staticType: int
staticElement: dart:core::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
accessors
synthetic get x @-1
returnType: dynamic
''');
}
test_class_constructor_initializers_genericFunctionType() async {
var library = await buildLibrary('''
class A<T> {
const A();
}
class B {
const B(dynamic x);
const B.f()
: this(A<Function()>());
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
typeParameters
covariant T @8
defaultType: dynamic
constructors
const @21
class B @34
constructors
const @46
parameters
requiredPositional x @56
type: dynamic
const f @70
periodOffset: 69
nameEnd: 71
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @79
argumentList: ArgumentList
leftParenthesis: ( @83
arguments
InstanceCreationExpression
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: A @84
staticElement: self::@class::A
staticType: null
typeArguments: TypeArgumentList
leftBracket: < @85
arguments
GenericFunctionType
functionKeyword: Function @86
parameters: FormalParameterList
leftParenthesis: ( @94
rightParenthesis: ) @95
declaredElement: GenericFunctionTypeElement
parameters
returnType: dynamic
type: dynamic Function()
type: dynamic Function()
rightBracket: > @96
type: A<dynamic Function()>
staticElement: ConstructorMember
base: self::@class::A::@constructor::•
substitution: {T: dynamic Function()}
argumentList: ArgumentList
leftParenthesis: ( @97
rightParenthesis: ) @98
staticType: A<dynamic Function()>
rightParenthesis: ) @99
staticElement: self::@class::B::@constructor::•
redirectedConstructor: self::@class::B::@constructor::•
''');
}
test_class_constructor_initializers_superInvocation_argumentContextType() async {
var library = await buildLibrary('''
class A {
const A(List<String> values);
}
class B extends A {
const B() : super(const []);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const @18
parameters
requiredPositional values @33
type: List<String>
class B @50
supertype: A
constructors
const @72
constantInitializers
SuperConstructorInvocation
superKeyword: super @78
argumentList: ArgumentList
leftParenthesis: ( @83
arguments
ListLiteral
constKeyword: const @84
leftBracket: [ @90
rightBracket: ] @91
staticType: List<String>
rightParenthesis: ) @92
staticElement: self::@class::A::@constructor::•
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_initializers_superInvocation_named() async {
var library = await buildLibrary('''
class A {
const A.aaa(int p);
}
class C extends A {
const C() : super.aaa(42);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const aaa @20
periodOffset: 19
nameEnd: 23
parameters
requiredPositional p @28
type: int
class C @40
supertype: A
constructors
const @62
constantInitializers
SuperConstructorInvocation
superKeyword: super @68
period: . @73
constructorName: SimpleIdentifier
token: aaa @74
staticElement: self::@class::A::@constructor::aaa
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @77
arguments
IntegerLiteral
literal: 42 @78
staticType: int
rightParenthesis: ) @80
staticElement: self::@class::A::@constructor::aaa
superConstructor: self::@class::A::@constructor::aaa
''');
}
test_class_constructor_initializers_superInvocation_named_underscore() async {
var library = await buildLibrary('''
class A {
const A._();
}
class B extends A {
const B() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const _ @20
periodOffset: 19
nameEnd: 21
class B @33
supertype: A
constructors
const @55
constantInitializers
SuperConstructorInvocation
superKeyword: super @61
period: . @66
constructorName: SimpleIdentifier
token: _ @67
staticElement: self::@class::A::@constructor::_
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @68
rightParenthesis: ) @69
staticElement: self::@class::A::@constructor::_
superConstructor: self::@class::A::@constructor::_
''');
}
test_class_constructor_initializers_superInvocation_namedExpression() async {
var library = await buildLibrary('''
class A {
const A.aaa(a, {int b});
}
class C extends A {
const C() : super.aaa(1, b: 2);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const aaa @20
periodOffset: 19
nameEnd: 23
parameters
requiredPositional a @24
type: dynamic
optionalNamed b @32
type: int
class C @45
supertype: A
constructors
const @67
constantInitializers
SuperConstructorInvocation
superKeyword: super @73
period: . @78
constructorName: SimpleIdentifier
token: aaa @79
staticElement: self::@class::A::@constructor::aaa
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @82
arguments
IntegerLiteral
literal: 1 @83
staticType: int
NamedExpression
name: Label
label: SimpleIdentifier
token: b @86
staticElement: self::@class::A::@constructor::aaa::@parameter::b
staticType: null
colon: : @87
expression: IntegerLiteral
literal: 2 @89
staticType: int
rightParenthesis: ) @90
staticElement: self::@class::A::@constructor::aaa
superConstructor: self::@class::A::@constructor::aaa
''');
}
test_class_constructor_initializers_superInvocation_unnamed() async {
var library = await buildLibrary('''
class A {
const A(int p);
}
class C extends A {
const C.ccc() : super(42);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const @18
parameters
requiredPositional p @24
type: int
class C @36
supertype: A
constructors
const ccc @60
periodOffset: 59
nameEnd: 63
constantInitializers
SuperConstructorInvocation
superKeyword: super @68
argumentList: ArgumentList
leftParenthesis: ( @73
arguments
IntegerLiteral
literal: 42 @74
staticType: int
rightParenthesis: ) @76
staticElement: self::@class::A::@constructor::•
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_initializers_thisInvocation_argumentContextType() async {
var library = await buildLibrary('''
class A {
const A(List<String> values);
const A.empty() : this(const []);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
const @18
parameters
requiredPositional values @33
type: List<String>
const empty @52
periodOffset: 51
nameEnd: 57
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @62
argumentList: ArgumentList
leftParenthesis: ( @66
arguments
ListLiteral
constKeyword: const @67
leftBracket: [ @73
rightBracket: ] @74
staticType: List<String>
rightParenthesis: ) @75
staticElement: self::@class::A::@constructor::•
redirectedConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_initializers_thisInvocation_named() async {
var library = await buildLibrary('''
class C {
const C() : this.named(1, 'bbb');
const C.named(int a, String b);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @18
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @24
period: . @28
constructorName: SimpleIdentifier
token: named @29
staticElement: self::@class::C::@constructor::named
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @34
arguments
IntegerLiteral
literal: 1 @35
staticType: int
SimpleStringLiteral
literal: 'bbb' @38
rightParenthesis: ) @43
staticElement: self::@class::C::@constructor::named
redirectedConstructor: self::@class::C::@constructor::named
const named @56
periodOffset: 55
nameEnd: 61
parameters
requiredPositional a @66
type: int
requiredPositional b @76
type: String
''');
}
test_class_constructor_initializers_thisInvocation_namedExpression() async {
var library = await buildLibrary('''
class C {
const C() : this.named(1, b: 2);
const C.named(a, {int b});
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @18
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @24
period: . @28
constructorName: SimpleIdentifier
token: named @29
staticElement: self::@class::C::@constructor::named
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @34
arguments
IntegerLiteral
literal: 1 @35
staticType: int
NamedExpression
name: Label
label: SimpleIdentifier
token: b @38
staticElement: self::@class::C::@constructor::named::@parameter::b
staticType: null
colon: : @39
expression: IntegerLiteral
literal: 2 @41
staticType: int
rightParenthesis: ) @42
staticElement: self::@class::C::@constructor::named
redirectedConstructor: self::@class::C::@constructor::named
const named @55
periodOffset: 54
nameEnd: 60
parameters
requiredPositional a @61
type: dynamic
optionalNamed b @69
type: int
''');
}
test_class_constructor_initializers_thisInvocation_unnamed() async {
var library = await buildLibrary('''
class C {
const C.named() : this(1, 'bbb');
const C(int a, String b);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const named @20
periodOffset: 19
nameEnd: 25
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @30
argumentList: ArgumentList
leftParenthesis: ( @34
arguments
IntegerLiteral
literal: 1 @35
staticType: int
SimpleStringLiteral
literal: 'bbb' @38
rightParenthesis: ) @43
staticElement: self::@class::C::@constructor::•
redirectedConstructor: self::@class::C::@constructor::•
const @54
parameters
requiredPositional a @60
type: int
requiredPositional b @70
type: String
''');
}
test_class_constructor_parameters_super_explicitType_function() async {
var library = await buildLibrary('''
class A {
A(Object? a);
}
class B extends A {
B(int super.a<T extends num>(T d)?);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @22
type: Object?
class B @35
supertype: A
constructors
@51
parameters
requiredPositional final super.a @63
type: int Function<T extends num>(T)?
typeParameters
covariant T @65
bound: num
parameters
requiredPositional d @82
type: T
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_explicitType_interface() async {
var library = await buildLibrary('''
class A {
A(num a);
}
class B extends A {
B(int super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @18
type: num
class B @31
supertype: A
constructors
@47
parameters
requiredPositional final super.a @59
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_explicitType_interface_nullable() async {
var library = await buildLibrary('''
class A {
A(num? a);
}
class B extends A {
B(int? super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @19
type: num?
class B @32
supertype: A
constructors
@48
parameters
requiredPositional final super.a @61
type: int?
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_invalid_topFunction() async {
var library = await buildLibrary('''
void f(super.a) {}
''');
checkElementText(library, r'''
library
definingUnit
functions
f @5
parameters
requiredPositional final super.a @13
type: dynamic
superConstructorParameter: <null>
returnType: void
''');
}
test_class_constructor_parameters_super_optionalNamed() async {
var library = await buildLibrary('''
class A {
A({required int a, required double b});
}
class B extends A {
B({String o1, super.a, String o2, super.b}) : super();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredNamed a @28
type: int
requiredNamed b @47
type: double
class B @61
supertype: A
constructors
@77
parameters
optionalNamed o1 @87
type: String
optionalNamed final super.a @97
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
optionalNamed o2 @107
type: String
optionalNamed final super.b @117
type: double
superConstructorParameter: self::@class::A::@constructor::•::@parameter::b
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_optionalNamed_unresolved() async {
var library = await buildLibrary('''
class A {
A({required int a});
}
class B extends A {
B({super.b});
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredNamed a @28
type: int
class B @42
supertype: A
constructors
@58
parameters
optionalNamed final super.b @67
type: dynamic
superConstructorParameter: <null>
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_optionalNamed_unresolved2() async {
var library = await buildLibrary('''
class A {
A(int a);
}
class B extends A {
B({super.a});
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @18
type: int
class B @31
supertype: A
constructors
@47
parameters
optionalNamed final super.a @56
type: dynamic
superConstructorParameter: <null>
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_optionalPositional() async {
var library = await buildLibrary('''
class A {
A(int a, double b);
}
class B extends A {
B([String o1, super.a, String o2, super.b]) : super();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @18
type: int
requiredPositional b @28
type: double
class B @41
supertype: A
constructors
@57
parameters
optionalPositional o1 @67
type: String
optionalPositional final super.a @77
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
optionalPositional o2 @87
type: String
optionalPositional final super.b @97
type: double
superConstructorParameter: self::@class::A::@constructor::•::@parameter::b
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredNamed() async {
var library = await buildLibrary('''
class A {
A({required int a, required double b});
}
class B extends A {
B({
required String o1,
required super.a,
required String o2,
required super.b,
}) : super();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredNamed a @28
type: int
requiredNamed b @47
type: double
class B @61
supertype: A
constructors
@77
parameters
requiredNamed o1 @101
type: String
requiredNamed final super.a @124
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
requiredNamed o2 @147
type: String
requiredNamed final super.b @170
type: double
superConstructorParameter: self::@class::A::@constructor::•::@parameter::b
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredPositional() async {
var library = await buildLibrary('''
class A {
A(int a, double b);
}
class B extends A {
B(String o1, super.a, String o2, super.b) : super();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @18
type: int
requiredPositional b @28
type: double
class B @41
supertype: A
constructors
@57
parameters
requiredPositional o1 @66
type: String
requiredPositional final super.a @76
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
requiredPositional o2 @86
type: String
requiredPositional final super.b @96
type: double
superConstructorParameter: self::@class::A::@constructor::•::@parameter::b
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredPositional_inferenceOrder() async {
// It is important that `B` is declared after `C`, so that we check that
// inference happens in order - first `B`, then `C`.
var library = await buildLibrary('''
abstract class A {
A(int a);
}
class C extends B {
C(super.a);
}
class B extends A {
B(super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
abstract class A @15
constructors
@21
parameters
requiredPositional a @27
type: int
class C @40
supertype: B
constructors
@56
parameters
requiredPositional final super.a @64
type: int
superConstructorParameter: self::@class::B::@constructor::•::@parameter::a
superConstructor: self::@class::B::@constructor::•
class B @77
supertype: A
constructors
@93
parameters
requiredPositional final super.a @101
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredPositional_inferenceOrder_generic() async {
// It is important that `C` is declared before `B`, so that we check that
// inference happens in order - first `B`, then `C`.
var library = await buildLibrary('''
class A {
A(int a);
}
class C extends B<String> {
C(super.a);
}
class B<T> extends A {
B(super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredPositional a @18
type: int
class C @31
supertype: B<String>
constructors
@55
parameters
requiredPositional final super.a @63
type: int
superConstructorParameter: SuperFormalParameterMember
base: self::@class::B::@constructor::•::@parameter::a
substitution: {T: String}
superConstructor: ConstructorMember
base: self::@class::B::@constructor::•
substitution: {T: String}
class B @76
typeParameters
covariant T @78
defaultType: dynamic
supertype: A
constructors
@95
parameters
requiredPositional final super.a @103
type: int
superConstructorParameter: self::@class::A::@constructor::•::@parameter::a
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredPositional_unresolved() async {
var library = await buildLibrary('''
class A {}
class B extends A {
B(super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
synthetic @-1
class B @18
supertype: A
constructors
@34
parameters
requiredPositional final super.a @42
type: dynamic
superConstructorParameter: <null>
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_parameters_super_requiredPositional_unresolved2() async {
var library = await buildLibrary('''
class A {
A({required int a})
}
class B extends A {
B(super.a);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
@12
parameters
requiredNamed a @28
type: int
class B @41
supertype: A
constructors
@57
parameters
requiredPositional final super.a @65
type: dynamic
superConstructorParameter: <null>
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_params() async {
var library = await buildLibrary('class C { C(x, int y); }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
@10
parameters
requiredPositional x @12
type: dynamic
requiredPositional y @19
type: int
''');
}
test_class_constructor_redirected_factory_named() async {
var library = await buildLibrary('''
class C {
factory C() = D.named;
C._();
}
class D extends C {
D.named() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
factory @20
redirectedConstructor: self::@class::D::@constructor::named
_ @39
periodOffset: 38
nameEnd: 40
class D @52
supertype: C
constructors
named @70
periodOffset: 69
nameEnd: 75
superConstructor: self::@class::C::@constructor::_
''');
}
test_class_constructor_redirected_factory_named_generic() async {
var library = await buildLibrary('''
class C<T, U> {
factory C() = D<U, T>.named;
C._();
}
class D<T, U> extends C<U, T> {
D.named() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
covariant U @11
defaultType: dynamic
constructors
factory @26
redirectedConstructor: ConstructorMember
base: self::@class::D::@constructor::named
substitution: {T: U, U: T}
_ @51
periodOffset: 50
nameEnd: 52
class D @64
typeParameters
covariant T @66
defaultType: dynamic
covariant U @69
defaultType: dynamic
supertype: C<U, T>
constructors
named @94
periodOffset: 93
nameEnd: 99
superConstructor: ConstructorMember
base: self::@class::C::@constructor::_
substitution: {T: U, U: T}
''');
}
test_class_constructor_redirected_factory_named_generic_viaTypeAlias() async {
var library = await buildLibrary('''
typedef A<T, U> = C<T, U>;
class B<T, U> {
factory B() = A<U, T>.named;
B._();
}
class C<T, U> extends A<U, T> {
C.named() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class B @33
typeParameters
covariant T @35
defaultType: dynamic
covariant U @38
defaultType: dynamic
constructors
factory @53
redirectedConstructor: ConstructorMember
base: self::@class::C::@constructor::named
substitution: {T: U, U: T}
_ @78
periodOffset: 77
nameEnd: 79
class C @91
typeParameters
covariant T @93
defaultType: dynamic
covariant U @96
defaultType: dynamic
supertype: C<U, T>
alias: self::@typeAlias::A
typeArguments
U
T
constructors
named @121
periodOffset: 120
nameEnd: 126
typeAliases
A @8
typeParameters
covariant T @10
defaultType: dynamic
covariant U @13
defaultType: dynamic
aliasedType: C<T, U>
''');
}
test_class_constructor_redirected_factory_named_imported() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D extends C {
D.named() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart';
class C {
factory C() = D.named;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart
definingUnit
classes
class C @25
constructors
factory @39
redirectedConstructor: package:test/foo.dart::@class::D::@constructor::named
_ @58
periodOffset: 57
nameEnd: 59
''');
}
test_class_constructor_redirected_factory_named_imported_generic() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D<T, U> extends C<U, T> {
D.named() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart';
class C<T, U> {
factory C() = D<U, T>.named;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart
definingUnit
classes
class C @25
typeParameters
covariant T @27
defaultType: dynamic
covariant U @30
defaultType: dynamic
constructors
factory @45
redirectedConstructor: ConstructorMember
base: package:test/foo.dart::@class::D::@constructor::named
substitution: {T: U, U: T}
_ @70
periodOffset: 69
nameEnd: 71
''');
}
test_class_constructor_redirected_factory_named_prefixed() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D extends C {
D.named() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart' as foo;
class C {
factory C() = foo.D.named;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart as foo @21
definingUnit
classes
class C @32
constructors
factory @46
redirectedConstructor: package:test/foo.dart::@class::D::@constructor::named
_ @69
periodOffset: 68
nameEnd: 70
''');
}
test_class_constructor_redirected_factory_named_prefixed_generic() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D<T, U> extends C<U, T> {
D.named() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart' as foo;
class C<T, U> {
factory C() = foo.D<U, T>.named;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart as foo @21
definingUnit
classes
class C @32
typeParameters
covariant T @34
defaultType: dynamic
covariant U @37
defaultType: dynamic
constructors
factory @52
redirectedConstructor: ConstructorMember
base: package:test/foo.dart::@class::D::@constructor::named
substitution: {T: U, U: T}
_ @81
periodOffset: 80
nameEnd: 82
''');
}
test_class_constructor_redirected_factory_named_unresolved_class() async {
var library = await buildLibrary('''
class C<E> {
factory C() = D.named<E>;
}
''', allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant E @8
defaultType: dynamic
constructors
factory @23
''');
}
test_class_constructor_redirected_factory_named_unresolved_constructor() async {
var library = await buildLibrary('''
class D {}
class C<E> {
factory C() = D.named<E>;
}
''', allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class D @6
constructors
synthetic @-1
class C @17
typeParameters
covariant E @19
defaultType: dynamic
constructors
factory @34
''');
}
test_class_constructor_redirected_factory_unnamed() async {
var library = await buildLibrary('''
class C {
factory C() = D;
C._();
}
class D extends C {
D() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
factory @20
redirectedConstructor: self::@class::D::@constructor::•
_ @33
periodOffset: 32
nameEnd: 34
class D @46
supertype: C
constructors
@62
superConstructor: self::@class::C::@constructor::_
''');
}
test_class_constructor_redirected_factory_unnamed_generic() async {
var library = await buildLibrary('''
class C<T, U> {
factory C() = D<U, T>;
C._();
}
class D<T, U> extends C<U, T> {
D() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
covariant U @11
defaultType: dynamic
constructors
factory @26
redirectedConstructor: ConstructorMember
base: self::@class::D::@constructor::•
substitution: {T: U, U: T}
_ @45
periodOffset: 44
nameEnd: 46
class D @58
typeParameters
covariant T @60
defaultType: dynamic
covariant U @63
defaultType: dynamic
supertype: C<U, T>
constructors
@86
superConstructor: ConstructorMember
base: self::@class::C::@constructor::_
substitution: {T: U, U: T}
''');
}
test_class_constructor_redirected_factory_unnamed_generic_viaTypeAlias() async {
var library = await buildLibrary('''
typedef A<T, U> = C<T, U>;
class B<T, U> {
factory B() = A<U, T>;
B_();
}
class C<T, U> extends B<U, T> {
C() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class B @33
typeParameters
covariant T @35
defaultType: dynamic
covariant U @38
defaultType: dynamic
constructors
factory @53
redirectedConstructor: ConstructorMember
base: self::@class::C::@constructor::•
substitution: {T: U, U: T}
methods
abstract B_ @70
returnType: dynamic
class C @84
typeParameters
covariant T @86
defaultType: dynamic
covariant U @89
defaultType: dynamic
supertype: B<U, T>
constructors
@112
typeAliases
A @8
typeParameters
covariant T @10
defaultType: dynamic
covariant U @13
defaultType: dynamic
aliasedType: C<T, U>
''');
}
test_class_constructor_redirected_factory_unnamed_imported() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D extends C {
D() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart';
class C {
factory C() = D;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart
definingUnit
classes
class C @25
constructors
factory @39
redirectedConstructor: package:test/foo.dart::@class::D::@constructor::•
_ @52
periodOffset: 51
nameEnd: 53
''');
}
test_class_constructor_redirected_factory_unnamed_imported_generic() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D<T, U> extends C<U, T> {
D() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart';
class C<T, U> {
factory C() = D<U, T>;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart
definingUnit
classes
class C @25
typeParameters
covariant T @27
defaultType: dynamic
covariant U @30
defaultType: dynamic
constructors
factory @45
redirectedConstructor: ConstructorMember
base: package:test/foo.dart::@class::D::@constructor::•
substitution: {T: U, U: T}
_ @64
periodOffset: 63
nameEnd: 65
''');
}
test_class_constructor_redirected_factory_unnamed_imported_viaTypeAlias() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
typedef A = B;
class B extends C {
B() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart';
class C {
factory C() = A;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart
definingUnit
classes
class C @25
constructors
factory @39
redirectedConstructor: package:test/foo.dart::@class::B::@constructor::•
_ @52
periodOffset: 51
nameEnd: 53
''');
}
test_class_constructor_redirected_factory_unnamed_prefixed() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D extends C {
D() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart' as foo;
class C {
factory C() = foo.D;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart as foo @21
definingUnit
classes
class C @32
constructors
factory @46
redirectedConstructor: package:test/foo.dart::@class::D::@constructor::•
_ @63
periodOffset: 62
nameEnd: 64
''');
}
test_class_constructor_redirected_factory_unnamed_prefixed_generic() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
class D<T, U> extends C<U, T> {
D() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart' as foo;
class C<T, U> {
factory C() = foo.D<U, T>;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart as foo @21
definingUnit
classes
class C @32
typeParameters
covariant T @34
defaultType: dynamic
covariant U @37
defaultType: dynamic
constructors
factory @52
redirectedConstructor: ConstructorMember
base: package:test/foo.dart::@class::D::@constructor::•
substitution: {T: U, U: T}
_ @75
periodOffset: 74
nameEnd: 76
''');
}
test_class_constructor_redirected_factory_unnamed_prefixed_viaTypeAlias() async {
addSource('$testPackageLibPath/foo.dart', '''
import 'test.dart';
typedef A = B;
class B extends C {
B() : super._();
}
''');
var library = await buildLibrary('''
import 'foo.dart' as foo;
class C {
factory C() = foo.A;
C._();
}
''');
checkElementText(library, r'''
library
imports
package:test/foo.dart as foo @21
definingUnit
classes
class C @32
constructors
factory @46
redirectedConstructor: package:test/foo.dart::@class::B::@constructor::•
_ @63
periodOffset: 62
nameEnd: 64
''');
}
test_class_constructor_redirected_factory_unnamed_unresolved() async {
var library = await buildLibrary('''
class C<E> {
factory C() = D<E>;
}
''', allowErrors: true);
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant E @8
defaultType: dynamic
constructors
factory @23
''');
}
test_class_constructor_redirected_factory_unnamed_viaTypeAlias() async {
var library = await buildLibrary('''
typedef A = C;
class B {
factory B() = A;
B._();
}
class C extends B {
C() : super._();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class B @21
constructors
factory @35
redirectedConstructor: self::@class::C::@constructor::•
_ @48
periodOffset: 47
nameEnd: 49
class C @61
supertype: B
constructors
@77
superConstructor: self::@class::B::@constructor::_
typeAliases
A @8
aliasedType: C
''');
}
test_class_constructor_redirected_thisInvocation_named() async {
var library = await buildLibrary('''
class C {
const C.named();
const C() : this.named();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const named @20
periodOffset: 19
nameEnd: 25
const @37
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @43
period: . @47
constructorName: SimpleIdentifier
token: named @48
staticElement: self::@class::C::@constructor::named
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @53
rightParenthesis: ) @54
staticElement: self::@class::C::@constructor::named
redirectedConstructor: self::@class::C::@constructor::named
''');
}
test_class_constructor_redirected_thisInvocation_named_generic() async {
var library = await buildLibrary('''
class C<T> {
const C.named();
const C() : this.named();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
constructors
const named @23
periodOffset: 22
nameEnd: 28
const @40
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @46
period: . @50
constructorName: SimpleIdentifier
token: named @51
staticElement: self::@class::C::@constructor::named
staticType: null
argumentList: ArgumentList
leftParenthesis: ( @56
rightParenthesis: ) @57
staticElement: self::@class::C::@constructor::named
redirectedConstructor: self::@class::C::@constructor::named
''');
}
test_class_constructor_redirected_thisInvocation_named_notConst() async {
var library = await buildLibrary('''
class C {
C.named();
C() : this.named();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
named @14
periodOffset: 13
nameEnd: 19
@25
redirectedConstructor: self::@class::C::@constructor::named
''');
}
test_class_constructor_redirected_thisInvocation_unnamed() async {
var library = await buildLibrary('''
class C {
const C();
const C.named() : this();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
const @18
const named @33
periodOffset: 32
nameEnd: 38
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @43
argumentList: ArgumentList
leftParenthesis: ( @47
rightParenthesis: ) @48
staticElement: self::@class::C::@constructor::•
redirectedConstructor: self::@class::C::@constructor::•
''');
}
test_class_constructor_redirected_thisInvocation_unnamed_generic() async {
var library = await buildLibrary('''
class C<T> {
const C();
const C.named() : this();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
typeParameters
covariant T @8
defaultType: dynamic
constructors
const @21
const named @36
periodOffset: 35
nameEnd: 41
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @46
argumentList: ArgumentList
leftParenthesis: ( @50
rightParenthesis: ) @51
staticElement: self::@class::C::@constructor::•
redirectedConstructor: self::@class::C::@constructor::•
''');
}
test_class_constructor_redirected_thisInvocation_unnamed_notConst() async {
var library = await buildLibrary('''
class C {
C();
C.named() : this();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
constructors
@12
named @21
periodOffset: 20
nameEnd: 26
redirectedConstructor: self::@class::C::@constructor::•
''');
}
test_class_constructor_superConstructor_generic_named() async {
var library = await buildLibrary('''
class A<T> {
A.named(T a);
}
class B extends A<int> {
B() : super.named(0);
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
typeParameters
covariant T @8
defaultType: dynamic
constructors
named @17
periodOffset: 16
nameEnd: 22
parameters
requiredPositional a @25
type: T
class B @37
supertype: A<int>
constructors
@58
superConstructor: ConstructorMember
base: self::@class::A::@constructor::named
substitution: {T: int}
''');
}
test_class_constructor_superConstructor_notGeneric_named() async {
var library = await buildLibrary('''
class A {
A.named();
}
class B extends A {
B() : super.named();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
named @14
periodOffset: 13
nameEnd: 19
class B @31
supertype: A
constructors
@47
superConstructor: self::@class::A::@constructor::named
''');
}
test_class_constructor_superConstructor_notGeneric_unnamed_explicit() async {
var library = await buildLibrary('''
class A {}
class B extends A {
B() : super();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
synthetic @-1
class B @17
supertype: A
constructors
@33
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_superConstructor_notGeneric_unnamed_implicit() async {
var library = await buildLibrary('''
class A {}
class B extends A {
B();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
synthetic @-1
class B @17
supertype: A
constructors
@33
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_superConstructor_notGeneric_unnamed_implicit2() async {
var library = await buildLibrary('''
class A {}
class B extends A {}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
constructors
synthetic @-1
class B @17
supertype: A
constructors
synthetic @-1
superConstructor: self::@class::A::@constructor::•
''');
}
test_class_constructor_unnamed_implicit() async {
var library = await buildLibrary('class C {}');
checkElementText(
library,
r'''
library
definingUnit
classes
class C @6
constructors
synthetic @-1
displayName: C
''',
withDisplayName: true);
}
test_class_constructor_withCycles_const() async {
var library = await buildLibrary('''
class C {
final x;
const C() : x = const D();
}
class D {
final x;
const D() : x = const C();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: dynamic
constructors
const @29
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: x @35
staticElement: self::@class::C::@field::x
staticType: null
equals: = @37
expression: InstanceCreationExpression
keyword: const @39
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: D @45
staticElement: self::@class::D
staticType: null
type: D
staticElement: self::@class::D::@constructor::•
argumentList: ArgumentList
leftParenthesis: ( @46
rightParenthesis: ) @47
staticType: D
accessors
synthetic get x @-1
returnType: dynamic
class D @58
fields
final x @70
type: dynamic
constructors
const @81
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: x @87
staticElement: self::@class::D::@field::x
staticType: null
equals: = @89
expression: InstanceCreationExpression
keyword: const @91
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: C @97
staticElement: self::@class::C
staticType: null
type: C
staticElement: self::@class::C::@constructor::•
argumentList: ArgumentList
leftParenthesis: ( @98
rightParenthesis: ) @99
staticType: C
accessors
synthetic get x @-1
returnType: dynamic
''');
}
test_class_constructor_withCycles_nonConst() async {
var library = await buildLibrary('''
class C {
final x;
C() : x = new D();
}
class D {
final x;
D() : x = new C();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: dynamic
constructors
@23
accessors
synthetic get x @-1
returnType: dynamic
class D @50
fields
final x @62
type: dynamic
constructors
@67
accessors
synthetic get x @-1
returnType: dynamic
''');
}
test_class_constructors_named() async {
var library = await buildLibrary('''
class C {
C.foo();
}
''');
checkElementText(
library,
r'''
library
definingUnit
classes
class C @6
constructors
foo @14
displayName: C.foo
periodOffset: 13
nameEnd: 17
''',
withDisplayName: true);
}
test_class_constructors_unnamed() async {
var library = await buildLibrary('''
class C {
C();
}
''');
checkElementText(
library,
r'''
library
definingUnit
classes
class C @6
constructors
@12
displayName: C
''',
withDisplayName: true);
}
test_class_constructors_unnamed_new() async {
var library = await buildLibrary('''
class C {
C.new();
}
''');
checkElementText(
library,
r'''
library
definingUnit
classes
class C @6
constructors
@14
displayName: C
periodOffset: 13
nameEnd: 17
''',
withDisplayName: true);
}
test_class_documented() async {
var library = await buildLibrary('''
/**
* Docs
*/
class C {}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @22
documentationComment: /**\n * Docs\n */
constructors
synthetic @-1
''');
}
test_class_documented_mix() async {
var library = await buildLibrary('''
/**
* aaa
*/
/**
* bbb
*/
class A {}
/**
* aaa
*/
/// bbb
/// ccc
class B {}
/// aaa
/// bbb
/**
* ccc
*/
class C {}
/// aaa
/// bbb
/**
* ccc
*/
/// ddd
class D {}
/**
* aaa
*/
// bbb
class E {}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @36
documentationComment: /**\n * bbb\n */
constructors
synthetic @-1
class B @79
documentationComment: /// bbb\n/// ccc
constructors
synthetic @-1
class C @122
documentationComment: /**\n * ccc\n */
constructors
synthetic @-1
class D @173
documentationComment: /// ddd
constructors
synthetic @-1
class E @207
documentationComment: /**\n * aaa\n */
constructors
synthetic @-1
''');
}
test_class_documented_tripleSlash() async {
var library = await buildLibrary('''
/// first
/// second
/// third
class C {}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @37
documentationComment: /// first\n/// second\n/// third
constructors
synthetic @-1
''');
}
test_class_documented_with_references() async {
var library = await buildLibrary('''
/**
* Docs referring to [D] and [E]
*/
class C {}
class D {}
class E {}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @47
documentationComment: /**\n * Docs referring to [D] and [E]\n */
constructors
synthetic @-1
class D @59
constructors
synthetic @-1
class E @70
constructors
synthetic @-1
''');
}
test_class_documented_with_windows_line_endings() async {
var library = await buildLibrary('/**\r\n * Docs\r\n */\r\nclass C {}');
checkElementText(library, r'''
library
definingUnit
classes
class C @25
documentationComment: /**\n * Docs\n */
constructors
synthetic @-1
''');
}
test_class_documented_withLeadingNotDocumentation() async {
var library = await buildLibrary('''
// Extra comment so doc comment offset != 0
/**
* Docs
*/
class C {}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @66
documentationComment: /**\n * Docs\n */
constructors
synthetic @-1
''');
}
test_class_documented_withMetadata() async {
var library = await buildLibrary('''
/// Comment 1
/// Comment 2
@Annotation()
class BeforeMeta {}
/// Comment 1
/// Comment 2
@Annotation.named()
class BeforeMetaNamed {}
@Annotation()
/// Comment 1
/// Comment 2
class AfterMeta {}
/// Comment 1
@Annotation()
/// Comment 2
class AroundMeta {}
/// Doc comment.
@Annotation()
// Not doc comment.
class DocBeforeMetaNotDocAfter {}
class Annotation {
const Annotation();
const Annotation.named();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class BeforeMeta @48
documentationComment: /// Comment 1\n/// Comment 2
metadata
Annotation
atSign: @ @28
name: SimpleIdentifier
token: Annotation @29
staticElement: self::@class::Annotation
staticType: null
arguments: ArgumentList
leftParenthesis: ( @39
rightParenthesis: ) @40
element: self::@class::Annotation::@constructor::•
constructors
synthetic @-1
class BeforeMetaNamed @117
documentationComment: /// Comment 1\n/// Comment 2
metadata
Annotation
atSign: @ @91
name: PrefixedIdentifier
prefix: SimpleIdentifier
token: Annotation @92
staticElement: self::@class::Annotation
staticType: null
period: . @102
identifier: SimpleIdentifier
token: named @103
staticElement: self::@class::Annotation::@constructor::named
staticType: null
staticElement: self::@class::Annotation::@constructor::named
staticType: null