blob: bc2c16fd8d3b53de4143ce8ce1363ec46716c1db [file] [log] [blame]
// Copyright (c) 2022, 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 'dart:io' as io;
import 'dart:typed_data';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/visitor.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/results.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/summary2/macro.dart';
import 'package:analyzer/src/summary2/macro_application.dart';
import 'package:analyzer/src/summary2/macro_application_error.dart';
import 'package:analyzer/src/utilities/extensions/file_system.dart';
import 'package:analyzer_utilities/testing/tree_string_sink.dart';
import 'package:collection/collection.dart';
import 'package:macros/src/bootstrap.dart' as macro;
import 'package:macros/src/executor/serialization.dart' as macro;
import 'package:path/path.dart' as package_path;
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
import '../dart/resolution/node_text_expectations.dart';
import 'element_text.dart';
import 'elements_base.dart';
import 'macros_environment.dart';
main() {
try {
MacrosEnvironment.instance;
} catch (_) {
print('Cannot initialize environment. Skip macros tests.');
test('fake', () {});
return;
}
defineReflectiveSuite(() {
defineReflectiveTests(MacroArgumentsTest);
defineReflectiveTests(MacroIncrementalTest);
defineReflectiveTests(MacroIntrospectNodeTest);
defineReflectiveTests(MacroIntrospectNodeDefinitionsTest);
defineReflectiveTests(MacroIntrospectElementTest);
defineReflectiveTests(MacroTypesTest_keepLinking);
defineReflectiveTests(MacroTypesTest_fromBytes);
defineReflectiveTests(MacroDeclarationsTest_keepLinking);
defineReflectiveTests(MacroDeclarationsTest_fromBytes);
defineReflectiveTests(MacroDefinitionTest_keepLinking);
defineReflectiveTests(MacroDefinitionTest_fromBytes);
defineReflectiveTests(MacroElementsTest_keepLinking);
defineReflectiveTests(MacroElementsTest_fromBytes);
defineReflectiveTests(MacroApplicationOrderTest_keepLinking);
defineReflectiveTests(MacroApplicationOrderTest_fromBytes);
defineReflectiveTests(MacroCodeGenerationTest);
defineReflectiveTests(MacroStaticTypeTest);
defineReflectiveTests(MacroExampleTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
abstract class MacroApplicationOrderTest extends MacroElementsBaseTest {
@override
Future<void> setUp() async {
await super.setUp();
newFile(
'$testPackageLibPath/order.dart',
_getMacroCode('order.dart'),
);
}
test_declarations_class_constructorsOf_alreadyDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclareInType(' A1.named12();')
class A1 {
A1.named11();
}
@DeclarationsIntrospectConstructors('A1')
class A2 {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A1 {
A1.named12();
}
augment class A2 {
void introspected_A1_named11();
void introspected_A1_named12();
}
''');
}
test_declarations_class_constructorsOf_cycle2() async {
var library = await buildLibrary(r'''
import 'order.dart';
@DeclarationsIntrospectConstructors('A2')
class A1 {}
@DeclarationsIntrospectConstructors('A1')
class A2 {}
@DeclarationsIntrospectConstructors('A1')
@DeclarationsIntrospectConstructors('A2')
class A3 {}
''');
configuration
..withConstructors = false
..withMetadata = false;
// Note, the errors are also reported when introspecting `A1` and `A2`
// during running macro applications on `A3`, because we know that
// `A1` and `A2` declarations are incomplete.
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A1 @70
reference: <testLibraryFragment>::@class::A1
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A2 @125
reference: <testLibraryFragment>::@class::A2
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A3 @222
reference: <testLibraryFragment>::@class::A3
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 1
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
''');
}
test_declarations_class_constructorsOf_notYetDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclarationsIntrospectConstructors('A2')
class A1 {
}
@DeclareInType(' A2.named23();')
class A2 {
@DeclareInType(' A2.named22();')
A2.named21();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A2 {
A2.named22();
A2.named23();
}
augment class A1 {
void introspected_A2_named21();
void introspected_A2_named22();
void introspected_A2_named23();
}
''');
}
test_declarations_class_fieldsOf_alreadyDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclareInType(' int f12 = 0;')
class A1 {
int f11 = 0;
}
@DeclarationsIntrospectFields('A1')
class A2 {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A1 {
int f12 = 0;
}
augment class A2 {
void introspected_A1_f11();
void introspected_A1_f12();
}
''');
}
test_declarations_class_fieldsOf_cycle2() async {
var library = await buildLibrary(r'''
import 'order.dart';
@DeclarationsIntrospectFields('A2')
class A1 {}
@DeclarationsIntrospectFields('A1')
class A2 {}
@DeclarationsIntrospectFields('A1')
@DeclarationsIntrospectFields('A2')
class A3 {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A1 @64
reference: <testLibraryFragment>::@class::A1
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A2 @113
reference: <testLibraryFragment>::@class::A2
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A3 @198
reference: <testLibraryFragment>::@class::A3
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 1
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
''');
}
test_declarations_class_fieldsOf_notYetDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclarationsIntrospectFields('A2')
class A1 {}
@DeclareInType(' int f23 = 0;')
class A2 {
@DeclareInType(' int f22 = 0;')
int f21 = 0;
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A2 {
int f22 = 0;
int f23 = 0;
}
augment class A1 {
void introspected_A2_f21();
void introspected_A2_f22();
void introspected_A2_f23();
}
''');
}
test_declarations_class_methodsOf_alreadyDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclareInType(' void f12() {}')
class A1 {
void f11() {}
}
@DeclarationsIntrospectMethods('A1')
class A2 {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A1 {
void f12() {}
}
augment class A2 {
void introspected_A1_f11();
void introspected_A1_f12();
}
''');
}
test_declarations_class_methodsOf_cycle2() async {
var library = await buildLibrary(r'''
import 'order.dart';
@DeclarationsIntrospectMethods('A2')
class A1 {}
@DeclarationsIntrospectMethods('A1')
class A2 {}
@DeclarationsIntrospectMethods('A1')
@DeclarationsIntrospectMethods('A2')
class A3 {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A1 @65
reference: <testLibraryFragment>::@class::A1
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A2 @115
reference: <testLibraryFragment>::@class::A2
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
class A3 @202
reference: <testLibraryFragment>::@class::A3
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 1
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A1
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A1
''');
}
test_declarations_class_methodsOf_cycle2_withHead() async {
var library = await buildLibrary(r'''
import 'order.dart';
@DeclarationsIntrospectMethods('A2')
class A1 {}
@DeclarationsIntrospectMethods('A3')
class A2 {}
@DeclarationsIntrospectMethods('A2')
class A3 {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A1 @65
reference: <testLibraryFragment>::@class::A1
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A3
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A3
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
class A2 @115
reference: <testLibraryFragment>::@class::A2
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A3
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A3
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A3
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
class A3 @165
reference: <testLibraryFragment>::@class::A3
enclosingElement: <testLibraryFragment>
macroDiagnostics
DeclarationsIntrospectionCycleDiagnostic
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
components
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A2
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A3
DeclarationsIntrospectionCycleComponent
element: <testLibraryFragment>::@class::A3
annotationIndex: 0
introspectedElement: <testLibraryFragment>::@class::A2
''');
}
test_declarations_class_methodsOf_notYetDone() async {
var library = await buildLibrary(r'''
import 'append.dart';
import 'order.dart';
@DeclarationsIntrospectMethods('A2')
class A1 {}
@DeclareInType(' void f23() {}')
class A2 {
@DeclareInType(' void f22() {}')
void f21() {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A2 {
void f22() {}
void f23() {}
}
augment class A1 {
void introspected_A2_f21();
void introspected_A2_f22();
void introspected_A2_f23();
}
''');
}
test_declarations_class_methodsOf_self() async {
var library = await buildLibrary(r'''
import 'order.dart';
@DeclarationsIntrospectMethods('A')
class A {
void foo() {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class A {
void introspected_A_foo();
}
''');
}
test_phases_class_types_declarations() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
@AddFunction('f1')
class X {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A1 {}
void f1() {}
---
''');
}
test_types_class_method_rightToLeft() async {
var library = await buildLibrary(r'''
import 'order.dart';
class X {
@AddClass('A1')
@AddClass('A2')
void foo() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_class_method_sourceOrder() async {
var library = await buildLibrary(r'''
import 'order.dart';
class X {
@AddClass('A1')
void foo() {}
@AddClass('A2')
void bar() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A1 {}
class A2 {}
---
''');
}
test_types_class_rightToLeft() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
@AddClass('A2')
class X {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_class_sourceOrder() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
class X1 {}
@AddClass('A2')
class X2 {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A1 {}
class A2 {}
---
''');
}
test_types_enum() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
enum X {
@AddClass('A2')
v1,
@AddClass('A3')
v2;
@AddClass('A4')
void foo() {}
}
''');
configuration.forOrder();
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
class A2 {}
class A3 {}
class A4 {}
class A1 {}
''');
}
test_types_innerBeforeOuter_class_method() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
class X {
@AddClass('A2')
void foo() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_innerBeforeOuter_mixin_method() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
mixin X {
@AddClass('A2')
void foo() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_libraryDirective_last() async {
var library = await buildLibrary(r'''
@AddClass('A1')
library;
import 'order.dart';
@AddClass('A2')
class X {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_mixin_method_rightToLeft() async {
var library = await buildLibrary(r'''
import 'order.dart';
mixin X {
@AddClass('A1')
@AddClass('A2')
void foo() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_mixin_method_sourceOrder() async {
var library = await buildLibrary(r'''
import 'order.dart';
mixin X {
@AddClass('A1')
void foo() {}
@AddClass('A2')
void bar() {}
}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A1 {}
class A2 {}
---
''');
}
test_types_mixin_rightToLeft() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
@AddClass('A2')
mixin X {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A2 {}
class A1 {}
---
''');
}
test_types_mixin_sourceOrder() async {
var library = await buildLibrary(r'''
import 'order.dart';
@AddClass('A1')
mixin X1 {}
@AddClass('A2')
mixin X2 {}
''');
configuration.forOrder();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/order.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
class A1 {}
class A2 {}
---
''');
}
}
@reflectiveTest
class MacroApplicationOrderTest_fromBytes extends MacroApplicationOrderTest {
@override
bool get keepLinkingLibraries => false;
}
@reflectiveTest
class MacroApplicationOrderTest_keepLinking extends MacroApplicationOrderTest {
@override
bool get keepLinkingLibraries => true;
}
@reflectiveTest
class MacroArgumentsTest extends MacroElementsBaseTest {
@override
bool get keepLinkingLibraries => true;
@TestTimeout(Timeout(Duration(seconds: 60)))
test_error() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'Object',
'bar': 'Object',
},
constructorParametersCode: '(this.foo, this.bar)',
argumentsCode: '(0, const Object())',
hasErrors: true,
expected: r'''
library
reference: <testLibrary>
libraryImports
package:test/arguments_text.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/arguments_text.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @76
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
macroDiagnostics
ArgumentMacroDiagnostic
annotationIndex: 0
argumentIndex: 1
message: Not supported: InstanceCreationExpressionImpl
''',
);
}
test_kind_named_positional() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'List<int>',
'bar': 'List<double>',
},
constructorParametersCode: '(this foo, {required this.bar})',
argumentsCode: '(bar: [0.1], [2])',
expected: r'''
foo: List<int> [2]
bar: List<double> [0.1]
''',
);
}
test_kind_optionalNamed() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'int',
'bar': 'int',
},
constructorParametersCode: '({this.foo = -1, this.bar = -2})',
argumentsCode: '(foo: 1)',
expected: r'''
foo: int 1
bar: int -2
''',
);
}
test_kind_optionalPositional() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'int',
'bar': 'int',
},
constructorParametersCode: '([this.foo = -1, this.bar = -2])',
argumentsCode: '(1)',
expected: r'''
foo: int 1
bar: int -2
''',
);
}
test_kind_requiredNamed() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'int'},
constructorParametersCode: '({required this.foo})',
argumentsCode: '(foo: 42)',
expected: r'''
foo: int 42
''',
);
}
test_kind_requiredPositional() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'int'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(42)',
expected: r'''
foo: int 42
''',
);
}
test_type_bool() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'bool',
'bar': 'bool',
},
constructorParametersCode: '(this.foo, this.bar)',
argumentsCode: '(true, false)',
expected: r'''
foo: bool true
bar: bool false
''',
);
}
test_type_double() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'double'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(1.2)',
expected: r'''
foo: double 1.2
''',
);
}
test_type_double_negative() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'double'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(-1.2)',
expected: r'''
foo: double -1.2
''',
);
}
test_type_int() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'int'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(42)',
expected: r'''
foo: int 42
''',
);
}
test_type_int_negative() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'int'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(-42)',
expected: r'''
foo: int -42
''',
);
}
test_type_list_int() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'List<int>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '([0, 1, 2])',
expected: r'''
foo: List<int> [0, 1, 2]
''',
);
}
test_type_list_intQ() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'List<int?>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '([0, null, 2])',
expected: r'''
foo: List<int?> [0, null, 2]
''',
);
}
test_type_list_map_int_string() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'List<Map<int, String>>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '([{0: "a"}, {1: "b", 2: "c"}])',
expected: r'''
foo: List<Map<int, String>> [{0: a}, {1: b, 2: c}]
''',
);
}
test_type_list_objectQ() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'List<Object?>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '([1, 2, true, 3, 4.2])',
expected: r'''
foo: List<Object?> [1, 2, true, 3, 4.2]
''',
);
}
test_type_map_int_string() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'Map<int, String>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '({0: "a", 1: "b"})',
expected: r'''
foo: _Map<int, String> {0: a, 1: b}
''',
);
}
test_type_null() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'Object?'},
constructorParametersCode: '(this.foo)',
argumentsCode: '(null)',
expected: r'''
foo: Null null
''',
);
}
test_type_set() async {
await _assertTypesPhaseArgumentsText(
fields: {
'foo': 'Set<int>',
},
constructorParametersCode: '(this.foo)',
argumentsCode: '({1, 2, 3})',
expected: r'''
foo: _Set<int> {1, 2, 3}
''',
);
}
test_type_string() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'String'},
constructorParametersCode: '(this.foo)',
argumentsCode: "('aaa')",
expected: r'''
foo: String aaa
''',
);
}
test_type_string_adjacent() async {
await _assertTypesPhaseArgumentsText(
fields: {'foo': 'String'},
constructorParametersCode: '(this.foo)',
argumentsCode: "('aaa' 'bbb' 'ccc')",
expected: r'''
foo: String aaabbbccc
''',
);
}
/// Build a macro with specified [fields], initialized in the constructor
/// with [constructorParametersCode], and apply this macro with
/// [argumentsCode] to an empty class.
///
/// The macro generates exactly one top-level constant `x`, with a textual
/// dump of the field values. So, we check that the analyzer built these
/// values, and the macro executor marshalled these values to the running
/// macro isolate.
Future<void> _assertTypesPhaseArgumentsText({
required Map<String, String> fields,
required String constructorParametersCode,
required String argumentsCode,
required String expected,
bool hasErrors = false,
}) async {
var dumpCode = fields.keys.map((name) {
return "$name: \${$name.runtimeType} \$$name\\\\n";
}).join();
newFile('$testPackageLibPath/arguments_text.dart', '''
import 'dart:async';
import 'package:macros/macros.dart';
macro class ArgumentsTextMacro implements ClassTypesMacro {
${fields.entries.map((e) => ' final ${e.value} ${e.key};').join('\n')}
const ArgumentsTextMacro${constructorParametersCode.trim()};
FutureOr<void> buildTypesForClass(clazz, builder) {
builder.declareType(
'x',
DeclarationCode.fromString(
"const x = '$dumpCode';",
),
);
}
}
''');
var library = await buildLibrary('''
import 'arguments_text.dart';
@ArgumentsTextMacro$argumentsCode
class A {}
''');
if (hasErrors) {
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, expected);
} else {
if (library.allMacroDiagnostics.isNotEmpty) {
failWithLibraryText(library);
}
var x = library.topLevelElements
.whereType<ConstTopLevelVariableElementImpl>()
.single;
expect(x.name, 'x');
var actual = (x.constantInitializer as SimpleStringLiteral).value;
if (actual != expected) {
print('-------- Actual --------');
print('$actual------------------------');
NodeTextExpectationsCollector.add(actual);
}
expect(actual, expected);
}
}
}
@reflectiveTest
class MacroCodeGenerationTest extends MacroElementsBaseTest {
@override
bool get keepLinkingLibraries => true;
@override
Future<void> setUp() async {
await super.setUp();
newFile(
'$testPackageLibPath/code_generation.dart',
_getMacroCode('code_generation.dart'),
);
}
test_class_addMethod2_augmentMethod2() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType("""
@{{package:test/append.dart@AugmentDefinition}}('{}')
void foo();""")
@DeclareInType("""
@{{package:test/append.dart@AugmentDefinition}}('{}')
void bar();""")
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/append.dart' as prefix0;
augment class A {
@prefix0.AugmentDefinition('{}')
void bar();
@prefix0.AugmentDefinition('{}')
void foo();
augment void foo() {}
augment void bar() {}
}
''');
}
test_declarationsPhase_metadata_class_type() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
class X {}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_class_type_imported() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
const A();
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@DeclarationsPhaseAnnotationType()
@A()
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/a.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_class_type_imported_withPrefix() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
const A();
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart' as prefix;
@DeclarationsPhaseAnnotationType()
@prefix.A()
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/a.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_classAlias() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
class X = Object with M;
class A {
const A();
}
mixin M {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_classConstructor() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class X {
@DeclarationsPhaseAnnotationType()
@A()
X();
}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_classField() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class X {
@DeclarationsPhaseAnnotationType()
@A()
final foo = 0;
}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_classMethod() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class X {
@DeclarationsPhaseAnnotationType()
@A()
void foo() {}
}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_enum() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
enum X {v}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_extension() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
extension X on int {}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_extensionType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
extension type X(int it) {}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_function() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
void foo() {}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_mixin() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
mixin X {}
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_topLevelVariable() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
final foo = 0;
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_declarationsPhase_metadata_typeAlias() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DeclarationsPhaseAnnotationType()
@A()
typedef X = int;
class A {
const A();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/code_generation.dart' as prefix0;
import 'package:test/test.dart' as prefix1;
var x = [prefix0.DeclarationsPhaseAnnotationType, prefix1.A];
''');
}
test_inferOmittedType_fieldInstance_type() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
num? foo = 42;
}
class B extends A {
@AugmentForOmittedTypes()
var foo;
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class B {
augment prefix0.num? foo = 0;
}
''');
}
test_inferOmittedType_fieldStatic_type() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
static var foo;
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment static prefix0.dynamic foo = 0;
}
''');
}
test_inferOmittedType_function_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@AugmentForOmittedTypes()
foo() {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment prefix0.dynamic foo() {}
''');
}
test_inferOmittedType_functionType_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@AugmentForOmittedTypes()
void foo(Function() a) {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment void foo(prefix0.dynamic Function() a, ) {}
''');
}
test_inferOmittedType_getterInstance_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
int get foo => 0;
}
class B extends A {
@AugmentForOmittedTypes()
get foo => 0;
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class B {
augment prefix0.int get foo {}
}
''');
}
test_inferOmittedType_methodInstance_formalParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
void foo(int a) {}
}
class B extends A {
@AugmentForOmittedTypes()
void foo(a) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class B {
augment void foo(prefix0.int a, ) {}
}
''');
}
test_inferOmittedType_methodInstance_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
int foo() => 0;
}
class B extends A {
@AugmentForOmittedTypes()
foo() {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class B {
augment prefix0.int foo() {}
}
''');
}
test_inferOmittedType_methodStatic_formalParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
static void foo(a) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment static void foo(prefix0.dynamic a, ) {}
}
''');
}
test_inferOmittedType_methodStatic_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
static foo() {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment static prefix0.dynamic foo() {}
}
''');
}
test_inferOmittedType_setterInstance_formalParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
void set foo(int a) {}
}
class B extends A {
@AugmentForOmittedTypes()
void set foo(a) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class B {
augment void set foo(prefix0.int a, ) {}
}
''');
}
test_inferOmittedType_setterInstance_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
set foo(int _) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment void set foo(prefix0.int _, ) {}
}
''');
}
test_inferOmittedType_setterStatic_formalParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
static void set foo(a) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment static void set foo(prefix0.dynamic a, ) {}
}
''');
}
test_inferOmittedType_setterStatic_returnType() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@AugmentForOmittedTypes()
static set foo(int _) {}
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment static void set foo(prefix0.int _, ) {}
}
''');
}
test_macroGeneratedFile_existedBeforeLinking() async {
// See https://github.com/dart-lang/sdk/issues/54713
// Create `FileState` with the same name as would be macro generated.
// If we don't have implementation to discard it, we will get exception.
var macroFile = getFile('$testPackageLibPath/test.macro.dart');
driverFor(testFile).getFileSync2(macroFile);
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareTypesPhase('B', 'class B {}')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
class B {}
''');
}
test_resolveIdentifier_class() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_class_constructor() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
A.named();
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'named')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.named;
}
}
''');
}
test_resolveIdentifier_class_constructor_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
class A {
A.named();
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'named')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.named;
}
}
''');
}
test_resolveIdentifier_class_exported() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
newFile('$testPackageLibPath/b.dart', r'''
export 'a.dart';
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'b.dart';
@ReferenceIdentifier('package:test/b.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_class_field_instance() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
int foo = 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier(
'package:test/a.dart',
'A',
memberName: 'foo',
parametersCode: 'dynamic a',
leadCode: 'a.',
)
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class X {
void doReference(dynamic a) {
a.foo;
}
}
''');
}
test_resolveIdentifier_class_field_static() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static int foo = 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_class_field_static_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
class A {
static int foo = 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_class_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
class B {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'B')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.B;
}
}
''');
}
test_resolveIdentifier_class_getter_instance() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
int get foo => 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier(
'package:test/a.dart',
'A',
memberName: 'foo',
parametersCode: 'dynamic a',
leadCode: 'a.',
)
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class X {
void doReference(dynamic a) {
a.foo;
}
}
''');
}
test_resolveIdentifier_class_getter_static() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static int get foo => 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_class_getter_static_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
class A {
static int get foo => 0;
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_class_method_instance() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
void foo() {}
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier(
'package:test/a.dart',
'A',
memberName: 'foo',
parametersCode: 'dynamic a',
leadCode: 'a.',
)
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment class X {
void doReference(dynamic a) {
a.foo;
}
}
''');
}
test_resolveIdentifier_class_method_static() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {
static void foo() {}
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_class_method_static_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
class A {
static void foo() {}
}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A', memberName: 'foo')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A.foo;
}
}
''');
}
test_resolveIdentifier_extension() async {
newFile('$testPackageLibPath/a.dart', r'''
extension A on int {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_extensionType() async {
newFile('$testPackageLibPath/a.dart', r'''
extension type A(int it) {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_formalParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@ReferenceFirstFormalParameter()
void foo(int a);
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment void foo(prefix0.int a, ) {
a;
}
''');
}
test_resolveIdentifier_functionTypeAlias() async {
newFile('$testPackageLibPath/a.dart', r'''
typedef void A();
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_genericTypeAlias() async {
newFile('$testPackageLibPath/a.dart', r'''
typedef A = int;
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'A')
class X {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class X {
void doReference() {
prefix0.A;
}
}
''');
}
test_resolveIdentifier_typeParameter() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@ReferenceFirstTypeParameter()
void foo<T>();
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
augment void foo<T>() {
T;
}
''');
}
test_resolveIdentifier_unit_function() async {
newFile('$testPackageLibPath/a.dart', r'''
void foo() {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_function_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
void foo() {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_getter() async {
newFile('$testPackageLibPath/a.dart', r'''
int get foo => 0;
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_getter_fromPart() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');
newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
int get foo => 0;
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_setter() async {
newFile('$testPackageLibPath/a.dart', r'''
set foo(int value) {}
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo=')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_setter_exported() async {
newFile('$testPackageLibPath/a.dart', r'''
set foo(int value) {}
''');
newFile('$testPackageLibPath/b.dart', r'''
export 'a.dart';
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'b.dart';
@ReferenceIdentifier('package:test/b.dart', 'foo=')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_resolveIdentifier_unit_variable() async {
newFile('$testPackageLibPath/a.dart', r'''
var foo = 0;
''');
var library = await buildLibrary(r'''
import 'code_generation.dart';
import 'a.dart';
@ReferenceIdentifier('package:test/a.dart', 'foo')
class A {}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class A {
void doReference() {
prefix0.foo;
}
}
''');
}
test_toStringAsTypeName_atClass() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
@DefineToStringAsTypeName()
class A {
String toString();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment prefix0.String toString() {
return 'A';
}
}
''');
}
test_toStringAsTypeName_atMethod() async {
var library = await buildLibrary(r'''
import 'code_generation.dart';
class A {
@DefineToStringAsTypeName()
String toString();
}
''');
_assertMacroCode(library, r'''
augment library 'package:test/test.dart';
import 'dart:core' as prefix0;
augment class A {
augment prefix0.String toString() => 'A';
}
''');
}
}
abstract class MacroDeclarationsTest extends MacroElementsBaseTest {
test_addClass_addMethod_addMethod() async {
_addSingleMacro('addClass_addMethod_addMethod.dart');
var library = await buildLibrary(r'''
import 'a.dart';
@AddClassB()
class A {}
''');
configuration.withConstructors = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
@prefix0.AddMethodFoo()
class B {}
augment class B {
@prefix0.AddMethodBar()
void foo() {}
void bar() {}
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @37
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
metadata
Annotation
atSign: @ @18
name: SimpleIdentifier
token: AddClassB @19
staticElement: package:test/a.dart::<fragment>::@class::AddClassB
staticType: null
arguments: ArgumentList
leftParenthesis: ( @28
rightParenthesis: ) @29
element: package:test/a.dart::<fragment>::@class::AddClassB::@constructor::new
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
class B @115
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@class::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
metadata
Annotation
atSign: @ @85
name: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @86
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @93
identifier: SimpleIdentifier
token: AddMethodFoo @94
staticElement: package:test/a.dart::<fragment>::@class::AddMethodFoo
staticType: null
staticElement: package:test/a.dart::<fragment>::@class::AddMethodFoo
staticType: null
arguments: ArgumentList
leftParenthesis: ( @106
rightParenthesis: ) @107
element: package:test/a.dart::<fragment>::@class::AddMethodFoo::@constructor::new
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
augmented
methods
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::bar
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::foo
augment class B @135
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibrary>::@fragment::package:test/test.macro.dart::@class::B
methods
foo @172
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
metadata
Annotation
atSign: @ @141
name: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @142
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @149
identifier: SimpleIdentifier
token: AddMethodBar @150
staticElement: package:test/a.dart::<fragment>::@class::AddMethodBar
staticType: null
staticElement: package:test/a.dart::<fragment>::@class::AddMethodBar
staticType: null
arguments: ArgumentList
leftParenthesis: ( @162
rightParenthesis: ) @163
element: package:test/a.dart::<fragment>::@class::AddMethodBar::@constructor::new
returnType: void
bar @188
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::bar
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
returnType: void
''');
}
test_class_constructor_add_fieldFormalParameter() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' A.named(this.f);')
class A {
final int f;
}
''');
configuration.withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
A.named(this.f);
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @66
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
fields
final f @82
reference: <testLibraryFragment>::@class::A::@field::f
enclosingElement: <testLibraryFragment>::@class::A
type: int
accessors
synthetic get f @-1
reference: <testLibraryFragment>::@class::A::@getter::f
enclosingElement: <testLibraryFragment>::@class::A
returnType: int
augmented
fields
<testLibraryFragment>::@class::A::@field::f
constructors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::named
accessors
<testLibraryFragment>::@class::A::@getter::f
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
constructors
named @65
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::named
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
periodOffset: 64
nameEnd: 70
parameters
requiredPositional final this.f @76
type: int
field: <testLibraryFragment>::@class::A::@field::f
''');
}
test_class_constructor_add_named() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' A.named(int a);')
class A {}
''');
configuration.withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
A.named(int a);
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @65
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
constructors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::named
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
constructors
named @65
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::named
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
periodOffset: 64
nameEnd: 70
parameters
requiredPositional a @75
type: int
''');
}
test_class_constructor_add_unnamed() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' A(int a);')
class A {}
''');
configuration.withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
A(int a);
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @59
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
constructors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::new
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
constructors
@63
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@constructor::new
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
parameters
requiredPositional a @69
type: int
''');
}
test_class_field_add() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' int foo = 0;')
class A {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
int foo = 0;
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @62
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
fields
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
accessors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@getter::foo
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@setter::foo
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
fields
foo @67
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
type: int
shouldUseTypeForInitializerInference: true
accessors
synthetic get foo @-1
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@getter::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
returnType: int
synthetic set foo= @-1
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@setter::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
parameters
requiredPositional _foo @-1
type: int
returnType: void
''');
}
test_class_getter_add() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' int get foo => 0;')
class A {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
int get foo => 0;
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @67
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
fields
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
accessors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@getter::foo
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
fields
synthetic foo @-1
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
type: int
accessors
get foo @71
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@getter::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
returnType: int
''');
}
test_class_method_add() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' int foo(double a) => 0;')
class A {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
int foo(double a) => 0;
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @73
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
methods
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@method::foo
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
methods
foo @67
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@method::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
parameters
requiredPositional a @78
type: double
returnType: int
''');
}
test_class_setter_add() async {
var library = await buildLibrary(r'''
import 'append.dart';
@DeclareInType(' set foo(int a) {}')
class A {}
''');
configuration
..withConstructors = false
..withMetadata = false;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
augment class A {
set foo(int a) {}
}
---
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
classes
class A @67
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
augmentation: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
augmented
fields
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
accessors
<testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@setter::foo
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
classes
augment class A @57
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::A
fields
synthetic foo @-1
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@field::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
type: int
accessors
set foo= @67
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A::@setter::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::A
parameters
requiredPositional a @75
type: int
returnType: void
''');
}
test_codeOptimizer_class_constructor_optionalPositional_defaultValue() async {
newFile('$testPackageLibPath/a.dart', r'''
const a = 0;
''');
var library = await buildLibrary(r'''
import 'append.dart';
import 'a.dart';
@DeclareInType(' B([x = {{package:test/a.dart@a}}]);')
class B {}
''');
configuration
..forCodeOptimizer()
..withConstructors = true;
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class B {
B([x = prefix0.a]);
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
augment class B @99
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::B
constructors
@105
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@constructor::new
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
parameters
optionalPositional default x @108
type: dynamic
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @112
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @119
identifier: SimpleIdentifier
token: a @120
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: int
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: int
''');
}
test_codeOptimizer_class_method_optionalPositional_defaultValue() async {
newFile('$testPackageLibPath/a.dart', r'''
const a = 0;
''');
var library = await buildLibrary(r'''
import 'append.dart';
import 'a.dart';
@DeclareInType(' void foo([x = {{package:test/a.dart@a}}]) {}')
class B {}
''');
configuration.forCodeOptimizer();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class B {
void foo([x = prefix0.a]) {}
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
augment class B @99
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::B
methods
foo @110
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
parameters
optionalPositional default x @115
type: dynamic
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @119
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @126
identifier: SimpleIdentifier
token: a @127
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: int
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: int
returnType: void
''');
}
test_codeOptimizer_class_method_optionalPositional_metadata() async {
newFile('$testPackageLibPath/a.dart', r'''
const a = 0;
''');
var library = await buildLibrary(r'''
import 'append.dart';
import 'a.dart';
@DeclareInType(' void foo([@{{package:test/a.dart@a}} x]) {}')
class B {}
''');
configuration.forCodeOptimizer();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class B {
void foo([@prefix0.a x]) {}
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
augment class B @99
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::B
methods
foo @110
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
parameters
optionalPositional default x @126
type: dynamic
metadata
Annotation
atSign: @ @115
name: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @116
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @123
identifier: SimpleIdentifier
token: a @124
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: null
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: null
element: package:test/a.dart::<fragment>::@getter::a
returnType: void
''');
}
test_codeOptimizer_class_method_requiredPositional_metadata() async {
newFile('$testPackageLibPath/a.dart', r'''
const a = 0;
''');
var library = await buildLibrary(r'''
import 'append.dart';
import 'a.dart';
@DeclareInType(' void foo(@{{package:test/a.dart@a}} x) {}')
class B {}
''');
configuration.forCodeOptimizer();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class B {
void foo(@prefix0.a x) {}
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
augment class B @99
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::B
methods
foo @110
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@method::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
parameters
requiredPositional x @125
type: dynamic
metadata
Annotation
atSign: @ @114
name: PrefixedIdentifier
prefix: SimpleIdentifier
token: prefix0 @115
staticElement: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
staticType: null
period: . @122
identifier: SimpleIdentifier
token: a @123
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: null
staticElement: package:test/a.dart::<fragment>::@getter::a
staticType: null
element: package:test/a.dart::<fragment>::@getter::a
returnType: void
''');
}
test_codeOptimizer_class_setter_requiredPositional_metadata() async {
newFile('$testPackageLibPath/a.dart', r'''
const a = 0;
''');
var library = await buildLibrary(r'''
import 'append.dart';
import 'a.dart';
@DeclareInType(' set foo(@{{package:test/a.dart@a}} x) {}')
class B {}
''');
configuration.forCodeOptimizer();
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/append.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
augmentationImports
package:test/test.macro.dart
enclosingElement: <testLibrary>
reference: <testLibrary>::@augmentation::package:test/test.macro.dart
macroGeneratedCode
---
augment library 'package:test/test.dart';
import 'package:test/a.dart' as prefix0;
augment class B {
set foo(@prefix0.a x) {}
}
---
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
prefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
definingUnit: <testLibrary>::@fragment::package:test/test.macro.dart
units
<testLibrary>::@fragment::package:test/test.macro.dart
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibraryFragment>
libraryImports
package:test/a.dart as prefix0 @75
enclosingElement: <testLibrary>
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
libraryImportPrefixes
prefix0 @75
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@prefix::prefix0
enclosingElement: <testLibrary>::@augmentation::package:test/test.macro.dart
enclosingElement3: <testLibrary>::@fragment::package:test/test.macro.dart
classes
augment class B @99
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart
augmentationTarget: <testLibraryFragment>::@class::B
fields
synthetic foo @-1
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@field::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
type: dynamic
accessors
set foo= @109
reference: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B::@setter::foo
enclosingElement: <testLibrary>::@fragment::package:test/test.macro.dart::@classAugmentation::B
parameters
requiredPositional x @124
type: dynamic
metadata
Annotation
atSign: @ @113