blob: 309f16fc63b9fa18acc7d5c00b10559b3a29471e [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_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
arguments: ArgumentList
leftParenthesis: ( @108
rightParenthesis: ) @109
element: self::@class::Annotation::@constructor::named
constructors
synthetic @-1
class AfterMeta @185
documentationComment: /// Comment 1\n/// Comment 2
metadata
Annotation
atSign: @ @137
name: SimpleIdentifier
token: Annotation @138
staticElement: self::@class::Annotation
staticType: null
arguments: ArgumentList
leftParenthesis: ( @148
rightParenthesis: ) @149
element: self::@class::Annotation::@constructor::•
constructors
synthetic @-1
class AroundMeta @247
documentationComment: /// Comment 2
metadata
Annotation
atSign: @ @213
name: SimpleIdentifier
token: Annotation @214
staticElement: self::@class::Annotation
staticType: null
arguments: ArgumentList
leftParenthesis: ( @224
rightParenthesis: ) @225
element: self::@class::Annotation::@constructor::•
constructors
synthetic @-1
class DocBeforeMetaNotDocAfter @319
documentationComment: /// Doc comment.
metadata
Annotation
atSign: @ @279
name: SimpleIdentifier
token: Annotation @280
staticElement: self::@class::Annotation
staticType: null
arguments: ArgumentList
leftParenthesis: ( @290
rightParenthesis: ) @291
element: self::@class::Annotation::@constructor::•
constructors
synthetic @-1
class Annotation @354
constructors
const @375
const named @408
periodOffset: 407
nameEnd: 413
''');
}
test_class_field_abstract() async {
var library = await buildLibrary('''
abstract class C {
abstract int i;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
abstract class C @15
fields
abstract i @34
type: int
constructors
synthetic @-1
accessors
synthetic abstract get i @-1
returnType: int
synthetic abstract set i @-1
parameters
requiredPositional _i @-1
type: int
returnType: void
''');
}
test_class_field_const() async {
var library = await buildLibrary('class C { static const int i = 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
static const i @27
type: int
constantInitializer
IntegerLiteral
literal: 0 @31
staticType: int
constructors
synthetic @-1
accessors
synthetic static get i @-1
returnType: int
''');
}
test_class_field_const_late() async {
var library =
await buildLibrary('class C { static late const int i = 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
static late const i @32
type: int
constantInitializer
IntegerLiteral
literal: 0 @36
staticType: int
constructors
synthetic @-1
accessors
synthetic static get i @-1
returnType: int
''');
}
test_class_field_covariant() async {
var library = await buildLibrary('''
class C {
covariant int x;
}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
covariant x @26
type: int
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: int
synthetic set x @-1
parameters
requiredPositional covariant _x @-1
type: int
returnType: void
''');
}
test_class_field_documented() async {
var library = await buildLibrary('''
class C {
/**
* Docs
*/
var x;
}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @38
documentationComment: /**\n * Docs\n */
type: dynamic
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_field_external() async {
var library = await buildLibrary('''
abstract class C {
external int i;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
abstract class C @15
fields
external i @34
type: int
constructors
synthetic @-1
accessors
synthetic get i @-1
returnType: int
synthetic set i @-1
parameters
requiredPositional _i @-1
type: int
returnType: void
''');
}
test_class_field_final_hasInitializer_hasConstConstructor() async {
var library = await buildLibrary('''
class C {
final x = 42;
const C();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: int
constantInitializer
IntegerLiteral
literal: 42 @22
staticType: int
constructors
const @34
accessors
synthetic get x @-1
returnType: int
''');
}
test_class_field_final_hasInitializer_hasConstConstructor_genericFunctionType() async {
var library = await buildLibrary('''
class A<T> {
const A();
}
class B {
final f = const A<int Function(double a)>();
const B();
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
typeParameters
covariant T @8
defaultType: dynamic
constructors
const @21
class B @34
fields
final f @46
type: A<int Function(double)>
constantInitializer
InstanceCreationExpression
keyword: const @50
constructorName: ConstructorName
type: NamedType
name: SimpleIdentifier
token: A @56
staticElement: self::@class::A
staticType: null
typeArguments: TypeArgumentList
leftBracket: < @57
arguments
GenericFunctionType
returnType: NamedType
name: SimpleIdentifier
token: int @58
staticElement: dart:core::@class::int
staticType: null
type: int
functionKeyword: Function @62
parameters: FormalParameterList
leftParenthesis: ( @70
parameter: SimpleFormalParameter
type: NamedType
name: SimpleIdentifier
token: double @71
staticElement: dart:core::@class::double
staticType: null
type: double
identifier: SimpleIdentifier
token: a @78
staticElement: a@78
staticType: null
declaredElement: a@78
declaredElementType: double
rightParenthesis: ) @79
declaredElement: GenericFunctionTypeElement
parameters
a
kind: required positional
type: double
returnType: int
type: int Function(double)
type: int Function(double)
rightBracket: > @80
type: A<int Function(double)>
staticElement: ConstructorMember
base: self::@class::A::@constructor::•
substitution: {T: int Function(double)}
argumentList: ArgumentList
leftParenthesis: ( @81
rightParenthesis: ) @82
staticType: A<int Function(double)>
constructors
const @93
accessors
synthetic get f @-1
returnType: A<int Function(double)>
''');
}
test_class_field_final_hasInitializer_noConstConstructor() async {
var library = await buildLibrary('''
class C {
final x = 42;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: int
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: int
''');
}
test_class_field_final_withSetter() async {
var library = await buildLibrary(r'''
class A {
final int foo;
A(this.foo);
set foo(int newValue) {}
}
''');
checkElementText(library, r'''
library
definingUnit
classes
class A @6
fields
final foo @22
type: int
constructors
@29
parameters
requiredPositional final this.foo @36
type: int
field: self::@class::A::@field::foo
accessors
synthetic get foo @-1
returnType: int
set foo @48
parameters
requiredPositional newValue @56
type: int
returnType: void
''');
}
test_class_field_formal_param_inferred_type_implicit() async {
var library = await buildLibrary('class C extends D { var v; C(this.v); }'
' abstract class D { int get v; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
supertype: D
fields
v @24
type: int
constructors
@27
parameters
requiredPositional final this.v @34
type: int
field: self::@class::C::@field::v
superConstructor: self::@class::D::@constructor::•
accessors
synthetic get v @-1
returnType: int
synthetic set v @-1
parameters
requiredPositional _v @-1
type: int
returnType: void
abstract class D @55
fields
synthetic v @-1
type: int
constructors
synthetic @-1
accessors
abstract get v @67
returnType: int
''');
}
test_class_field_implicit_type() async {
var library = await buildLibrary('class C { var x; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
x @14
type: dynamic
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_field_implicit_type_late() async {
var library = await buildLibrary('class C { late var x; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
late x @19
type: dynamic
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: dynamic
synthetic set x @-1
parameters
requiredPositional _x @-1
type: dynamic
returnType: void
''');
}
test_class_field_inferred_type_nonStatic_explicit_initialized() async {
var library = await buildLibrary('class C { num v = 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
v @14
type: num
constructors
synthetic @-1
accessors
synthetic get v @-1
returnType: num
synthetic set v @-1
parameters
requiredPositional _v @-1
type: num
returnType: void
''');
}
test_class_field_inferred_type_nonStatic_implicit_initialized() async {
var library = await buildLibrary('class C { var v = 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
v @14
type: int
constructors
synthetic @-1
accessors
synthetic get v @-1
returnType: int
synthetic set v @-1
parameters
requiredPositional _v @-1
type: int
returnType: void
''');
}
test_class_field_inferred_type_nonStatic_implicit_uninitialized() async {
var library = await buildLibrary(
'class C extends D { var v; } abstract class D { int get v; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
supertype: D
fields
v @24
type: int
constructors
synthetic @-1
superConstructor: self::@class::D::@constructor::•
accessors
synthetic get v @-1
returnType: int
synthetic set v @-1
parameters
requiredPositional _v @-1
type: int
returnType: void
abstract class D @44
fields
synthetic v @-1
type: int
constructors
synthetic @-1
accessors
abstract get v @56
returnType: int
''');
}
test_class_field_inferred_type_nonStatic_inherited_resolveInitializer() async {
var library = await buildLibrary(r'''
const a = 0;
abstract class A {
const A();
List<int> get f;
}
class B extends A {
const B();
final f = [a];
}
''');
checkElementText(library, r'''
library
definingUnit
classes
abstract class A @28
fields
synthetic f @-1
type: List<int>
constructors
const @40
accessors
abstract get f @61
returnType: List<int>
class B @72
supertype: A
fields
final f @107
type: List<int>
constantInitializer
ListLiteral
leftBracket: [ @111
elements
SimpleIdentifier
token: a @112
staticElement: self::@getter::a
staticType: int
rightBracket: ] @113
staticType: List<int>
constructors
const @94
superConstructor: self::@class::A::@constructor::•
accessors
synthetic get f @-1
returnType: List<int>
topLevelVariables
static const a @6
type: int
constantInitializer
IntegerLiteral
literal: 0 @10
staticType: int
accessors
synthetic static get a @-1
returnType: int
''');
}
test_class_field_inferred_type_static_implicit_initialized() async {
var library = await buildLibrary('class C { static var v = 0; }');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
static v @21
type: int
constructors
synthetic @-1
accessors
synthetic static get v @-1
returnType: int
synthetic static set v @-1
parameters
requiredPositional _v @-1
type: int
returnType: void
''');
}
test_class_field_inheritedContextType_double() async {
var library = await buildLibrary('''
abstract class A {
const A();
double get foo;
}
class B extends A {
const B();
final foo = 2;
}
''');
checkElementText(library, r'''
library
definingUnit
classes
abstract class A @15
fields
synthetic foo @-1
type: double
constructors
const @27
accessors
abstract get foo @45
returnType: double
class B @58
supertype: A
fields
final foo @93
type: double
constantInitializer
IntegerLiteral
literal: 2 @99
staticType: double
constructors
const @80
superConstructor: self::@class::A::@constructor::•
accessors
synthetic get foo @-1
returnType: double
''');
}
test_class_field_propagatedType_const_noDep() async {
var library = await buildLibrary('''
class C {
static const x = 0;
}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
static const x @25
type: int
constantInitializer
IntegerLiteral
literal: 0 @29
staticType: int
constructors
synthetic @-1
accessors
synthetic static get x @-1
returnType: int
''');
}
test_class_field_propagatedType_final_dep_inLib() async {
addSource('$testPackageLibPath/a.dart', 'final a = 1;');
var library = await buildLibrary('''
import "a.dart";
class C {
final b = a / 2;
}''');
checkElementText(library, r'''
library
imports
package:test/a.dart
definingUnit
classes
class C @23
fields
final b @35
type: double
constructors
synthetic @-1
accessors
synthetic get b @-1
returnType: double
''');
}
test_class_field_propagatedType_final_dep_inPart() async {
addSource('$testPackageLibPath/a.dart', 'part of lib; final a = 1;');
var library = await buildLibrary('''
library lib;
part "a.dart";
class C {
final b = a / 2;
}''');
checkElementText(library, r'''
library
name: lib
nameOffset: 8
definingUnit
classes
class C @34
fields
final b @46
type: double
constructors
synthetic @-1
accessors
synthetic get b @-1
returnType: double
parts
package:test/a.dart
topLevelVariables
static final a @19
type: int
accessors
synthetic static get a @-1
returnType: int
''');
}
test_class_field_propagatedType_final_noDep_instance() async {
var library = await buildLibrary('''
class C {
final x = 0;
}''');
checkElementText(library, r'''
library
definingUnit
classes
class C @6
fields
final x @18
type: int
constructors
synthetic @-1
accessors
synthetic get x @-1
returnType: int
''');
}
test_class_field_propagatedType_final_noDep_static() async {
var library = await buildLibrary('''
class C {
static final x = 0;
}''');
checkElementText(library, r'''
library
definingUnit