| // Copyright (c) 2024, 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:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import '../../dart/resolution/node_text_expectations.dart'; |
| import '../elements_base.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(NonSyntheticElementTest_keepLinking); |
| defineReflectiveTests(NonSyntheticElementTest_fromBytes); |
| defineReflectiveTests(UpdateNodeTextExpectations); |
| }); |
| } |
| |
| abstract class NonSyntheticElementTest extends ElementsBaseTest { |
| test_nonSynthetic_class_field() async { |
| var library = await buildLibrary(r''' |
| class C { |
| int foo = 0; |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| classes |
| class C @6 |
| reference: <testLibraryFragment>::@class::C |
| enclosingElement: <testLibraryFragment> |
| fields |
| foo @16 |
| reference: <testLibraryFragment>::@class::C::@field::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| type: int |
| shouldUseTypeForInitializerInference: true |
| nonSynthetic: <testLibraryFragment>::@class::C::@field::foo |
| constructors |
| synthetic @-1 |
| reference: <testLibraryFragment>::@class::C::@constructor::new |
| enclosingElement: <testLibraryFragment>::@class::C |
| nonSynthetic: <testLibraryFragment>::@class::C |
| accessors |
| synthetic get foo @-1 |
| reference: <testLibraryFragment>::@class::C::@getter::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@field::foo |
| synthetic set foo= @-1 |
| reference: <testLibraryFragment>::@class::C::@setter::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| parameters |
| requiredPositional _foo @-1 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@field::foo |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@class::C::@field::foo |
| '''); |
| } |
| |
| test_nonSynthetic_class_getter() async { |
| var library = await buildLibrary(r''' |
| class C { |
| int get foo => 0; |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| classes |
| class C @6 |
| reference: <testLibraryFragment>::@class::C |
| enclosingElement: <testLibraryFragment> |
| fields |
| synthetic foo @-1 |
| reference: <testLibraryFragment>::@class::C::@field::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| type: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@getter::foo |
| constructors |
| synthetic @-1 |
| reference: <testLibraryFragment>::@class::C::@constructor::new |
| enclosingElement: <testLibraryFragment>::@class::C |
| nonSynthetic: <testLibraryFragment>::@class::C |
| accessors |
| get foo @20 |
| reference: <testLibraryFragment>::@class::C::@getter::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@getter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_class_setter() async { |
| var library = await buildLibrary(r''' |
| class C { |
| set foo(int value) {} |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| classes |
| class C @6 |
| reference: <testLibraryFragment>::@class::C |
| enclosingElement: <testLibraryFragment> |
| fields |
| synthetic foo @-1 |
| reference: <testLibraryFragment>::@class::C::@field::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| type: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@setter::foo |
| constructors |
| synthetic @-1 |
| reference: <testLibraryFragment>::@class::C::@constructor::new |
| enclosingElement: <testLibraryFragment>::@class::C |
| nonSynthetic: <testLibraryFragment>::@class::C |
| accessors |
| set foo= @16 |
| reference: <testLibraryFragment>::@class::C::@setter::foo |
| enclosingElement: <testLibraryFragment>::@class::C |
| parameters |
| requiredPositional value @24 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@class::C::@setter::foo::@parameter::value |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@class::C::@setter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_enum() async { |
| var library = await buildLibrary(r''' |
| enum E { |
| a, b |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| enums |
| enum E @5 |
| reference: <testLibraryFragment>::@enum::E |
| enclosingElement: <testLibraryFragment> |
| supertype: Enum |
| fields |
| static const enumConstant a @11 |
| reference: <testLibraryFragment>::@enum::E::@field::a |
| enclosingElement: <testLibraryFragment>::@enum::E |
| type: E |
| shouldUseTypeForInitializerInference: false |
| constantInitializer |
| InstanceCreationExpression |
| constructorName: ConstructorName |
| type: NamedType |
| name: E @-1 |
| element: <testLibraryFragment>::@enum::E |
| type: E |
| staticElement: <testLibraryFragment>::@enum::E::@constructor::new |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticType: E |
| nonSynthetic: <testLibraryFragment>::@enum::E::@field::a |
| static const enumConstant b @14 |
| reference: <testLibraryFragment>::@enum::E::@field::b |
| enclosingElement: <testLibraryFragment>::@enum::E |
| type: E |
| shouldUseTypeForInitializerInference: false |
| constantInitializer |
| InstanceCreationExpression |
| constructorName: ConstructorName |
| type: NamedType |
| name: E @-1 |
| element: <testLibraryFragment>::@enum::E |
| type: E |
| staticElement: <testLibraryFragment>::@enum::E::@constructor::new |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticType: E |
| nonSynthetic: <testLibraryFragment>::@enum::E::@field::b |
| synthetic static const values @-1 |
| reference: <testLibraryFragment>::@enum::E::@field::values |
| enclosingElement: <testLibraryFragment>::@enum::E |
| type: List<E> |
| constantInitializer |
| ListLiteral |
| leftBracket: [ @0 |
| elements |
| SimpleIdentifier |
| token: a @-1 |
| staticElement: <testLibraryFragment>::@enum::E::@getter::a |
| staticType: E |
| SimpleIdentifier |
| token: b @-1 |
| staticElement: <testLibraryFragment>::@enum::E::@getter::b |
| staticType: E |
| rightBracket: ] @0 |
| staticType: List<E> |
| nonSynthetic: <testLibraryFragment>::@enum::E |
| constructors |
| synthetic const @-1 |
| reference: <testLibraryFragment>::@enum::E::@constructor::new |
| enclosingElement: <testLibraryFragment>::@enum::E |
| nonSynthetic: <testLibraryFragment>::@enum::E |
| accessors |
| synthetic static get a @-1 |
| reference: <testLibraryFragment>::@enum::E::@getter::a |
| enclosingElement: <testLibraryFragment>::@enum::E |
| returnType: E |
| nonSynthetic: <testLibraryFragment>::@enum::E::@field::a |
| synthetic static get b @-1 |
| reference: <testLibraryFragment>::@enum::E::@getter::b |
| enclosingElement: <testLibraryFragment>::@enum::E |
| returnType: E |
| nonSynthetic: <testLibraryFragment>::@enum::E::@field::b |
| synthetic static get values @-1 |
| reference: <testLibraryFragment>::@enum::E::@getter::values |
| enclosingElement: <testLibraryFragment>::@enum::E |
| returnType: List<E> |
| nonSynthetic: <testLibraryFragment>::@enum::E |
| '''); |
| } |
| |
| test_nonSynthetic_mixin_field() async { |
| var library = await buildLibrary(r''' |
| mixin M { |
| int foo = 0; |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| mixins |
| mixin M @6 |
| reference: <testLibraryFragment>::@mixin::M |
| enclosingElement: <testLibraryFragment> |
| superclassConstraints |
| Object |
| fields |
| foo @16 |
| reference: <testLibraryFragment>::@mixin::M::@field::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| type: int |
| shouldUseTypeForInitializerInference: true |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@field::foo |
| accessors |
| synthetic get foo @-1 |
| reference: <testLibraryFragment>::@mixin::M::@getter::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@field::foo |
| synthetic set foo= @-1 |
| reference: <testLibraryFragment>::@mixin::M::@setter::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| parameters |
| requiredPositional _foo @-1 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@field::foo |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@field::foo |
| '''); |
| } |
| |
| test_nonSynthetic_mixin_getter() async { |
| var library = await buildLibrary(r''' |
| mixin M { |
| int get foo => 0; |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| mixins |
| mixin M @6 |
| reference: <testLibraryFragment>::@mixin::M |
| enclosingElement: <testLibraryFragment> |
| superclassConstraints |
| Object |
| fields |
| synthetic foo @-1 |
| reference: <testLibraryFragment>::@mixin::M::@field::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| type: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@getter::foo |
| accessors |
| get foo @20 |
| reference: <testLibraryFragment>::@mixin::M::@getter::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@getter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_mixin_setter() async { |
| var library = await buildLibrary(r''' |
| mixin M { |
| set foo(int value) {} |
| } |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| mixins |
| mixin M @6 |
| reference: <testLibraryFragment>::@mixin::M |
| enclosingElement: <testLibraryFragment> |
| superclassConstraints |
| Object |
| fields |
| synthetic foo @-1 |
| reference: <testLibraryFragment>::@mixin::M::@field::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| type: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@setter::foo |
| accessors |
| set foo= @16 |
| reference: <testLibraryFragment>::@mixin::M::@setter::foo |
| enclosingElement: <testLibraryFragment>::@mixin::M |
| parameters |
| requiredPositional value @24 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@setter::foo::@parameter::value |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@mixin::M::@setter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_unit_getter() async { |
| var library = await buildLibrary(r''' |
| int get foo => 0; |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| topLevelVariables |
| synthetic static foo @-1 |
| reference: <testLibraryFragment>::@topLevelVariable::foo |
| enclosingElement: <testLibraryFragment> |
| type: int |
| nonSynthetic: <testLibraryFragment>::@getter::foo |
| accessors |
| static get foo @8 |
| reference: <testLibraryFragment>::@getter::foo |
| enclosingElement: <testLibraryFragment> |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@getter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_unit_getterSetter() async { |
| var library = await buildLibrary(r''' |
| int get foo => 0; |
| set foo(int value) {} |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| topLevelVariables |
| synthetic static foo @-1 |
| reference: <testLibraryFragment>::@topLevelVariable::foo |
| enclosingElement: <testLibraryFragment> |
| type: int |
| nonSynthetic: <testLibraryFragment>::@getter::foo |
| accessors |
| static get foo @8 |
| reference: <testLibraryFragment>::@getter::foo |
| enclosingElement: <testLibraryFragment> |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@getter::foo |
| static set foo= @22 |
| reference: <testLibraryFragment>::@setter::foo |
| enclosingElement: <testLibraryFragment> |
| parameters |
| requiredPositional value @30 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@setter::foo::@parameter::value |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@setter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_unit_setter() async { |
| var library = await buildLibrary(r''' |
| set foo(int value) {} |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| topLevelVariables |
| synthetic static foo @-1 |
| reference: <testLibraryFragment>::@topLevelVariable::foo |
| enclosingElement: <testLibraryFragment> |
| type: int |
| nonSynthetic: <testLibraryFragment>::@setter::foo |
| accessors |
| static set foo= @4 |
| reference: <testLibraryFragment>::@setter::foo |
| enclosingElement: <testLibraryFragment> |
| parameters |
| requiredPositional value @12 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@setter::foo::@parameter::value |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@setter::foo |
| '''); |
| } |
| |
| test_nonSynthetic_unit_variable() async { |
| var library = await buildLibrary(r''' |
| int foo = 0; |
| '''); |
| configuration.withNonSynthetic = true; |
| checkElementText(library, r''' |
| library |
| reference: <testLibrary> |
| definingUnit: <testLibraryFragment> |
| units |
| <testLibraryFragment> |
| enclosingElement: <testLibrary> |
| topLevelVariables |
| static foo @4 |
| reference: <testLibraryFragment>::@topLevelVariable::foo |
| enclosingElement: <testLibraryFragment> |
| type: int |
| shouldUseTypeForInitializerInference: true |
| nonSynthetic: <testLibraryFragment>::@topLevelVariable::foo |
| accessors |
| synthetic static get foo @-1 |
| reference: <testLibraryFragment>::@getter::foo |
| enclosingElement: <testLibraryFragment> |
| returnType: int |
| nonSynthetic: <testLibraryFragment>::@topLevelVariable::foo |
| synthetic static set foo= @-1 |
| reference: <testLibraryFragment>::@setter::foo |
| enclosingElement: <testLibraryFragment> |
| parameters |
| requiredPositional _foo @-1 |
| type: int |
| nonSynthetic: <testLibraryFragment>::@topLevelVariable::foo |
| returnType: void |
| nonSynthetic: <testLibraryFragment>::@topLevelVariable::foo |
| '''); |
| } |
| } |
| |
| @reflectiveTest |
| class NonSyntheticElementTest_fromBytes extends NonSyntheticElementTest { |
| @override |
| bool get keepLinkingLibraries => false; |
| } |
| |
| @reflectiveTest |
| class NonSyntheticElementTest_keepLinking extends NonSyntheticElementTest { |
| @override |
| bool get keepLinkingLibraries => true; |
| } |