Skip to content

Commit

Permalink
Version 3.5.0-217.0.dev
Browse files Browse the repository at this point in the history
Merge 4692937 into dev
  • Loading branch information
Dart CI committed Jun 3, 2024
2 parents daca5f8 + 4692937 commit 95475e3
Show file tree
Hide file tree
Showing 53 changed files with 1,050 additions and 649 deletions.
1 change: 0 additions & 1 deletion pkg/_fe_analyzer_shared/analysis_options_no_lints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ analyzer:
- test/inference/inferred_type_arguments/data/**
- test/inference/inferred_variable_types/data/**
- test/inheritance/data/**
- test/macros/api/**
30 changes: 28 additions & 2 deletions pkg/_fe_analyzer_shared/test/macros/api/api_test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ class Class3 extends Class2 implements Interface1 {
class Class4 extends Class1 with Mixin1 {}

@ClassMacro()
class Class5 extends Class2
abstract class Class5 extends Class2
with Mixin1, Mixin2
implements Interface1, Interface2 {}

@MixinMacro()
mixin Mixin1 {}

mixin Mixin2 {}
@MixinMacro()
mixin Mixin2 {
var instanceField;
static var staticField;
get instanceGetter => 42;
set instanceSetter(int value) {}
static get staticGetter => 42;
static set staticSetter(int value) {}
instanceMethod() {}
abstractMethod();
static staticMethod() {}
}

@ClassMacro()
abstract class Interface1 {}
Expand All @@ -66,3 +78,17 @@ void topLevelFunction1(Class1 a, {Class1? b, required Class2? c}) {}

@FunctionMacro()
external Class2 topLevelFunction2(Class1 a, [Class2? b]);

@ExtensionTypeMacro()
extension type ExtensionType1(int i) {
ExtensionType1.constructor(this.i);
factory ExtensionType1.fact(int i) => ExtensionType1(i);
factory ExtensionType1.redirect(int i) = ExtensionType1.constructor;
static var staticField;
get instanceGetter => 42;
set instanceSetter(int value) {}
static get staticGetter => 42;
static set staticSetter(int value) {}
instanceMethod() {}
static staticMethod() {}
}
186 changes: 182 additions & 4 deletions pkg/_fe_analyzer_shared/test/macros/api/api_test_expectations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,62 @@ const Map<String, ClassData> expectedClassData = {
'Class5': ClassData(
superclass: 'Class2',
superSuperclass: 'Object',
isAbstract: true,
mixins: ['Mixin1', 'Mixin2'],
interfaces: ['Interface1', 'Interface2']),
'Interface1': ClassData(isAbstract: true),
'Interface2': ClassData(isAbstract: true),
};

const Map<String, MixinData> expectedMixinData = {
'Mixin1': MixinData(),
'Mixin2': MixinData(
// TODO(johnniwinther): Should we require a specific order?
fieldsOf: [
'instanceField',
'staticField',
],
// TODO(johnniwinther): Should we require a specific order?
methodsOf: [
'instanceGetter',
'staticGetter',
'instanceMethod',
'abstractMethod',
'staticMethod',
'instanceSetter',
'staticSetter',
],
),
};

const Map<String, ExtensionTypeData> expectedExtensionTypeData = {
'ExtensionType1': ExtensionTypeData(
representationType: NamedTypeData(name: 'int'),
// TODO(johnniwinther): Should we require a specific order?
fieldsOf: [
'i',
'staticField',
],
// TODO(johnniwinther): Should we require a specific order?
methodsOf: [
'instanceGetter',
'staticGetter',
'instanceMethod',
'staticMethod',
'instanceSetter',
'staticSetter',
],
// TODO(johnniwinther): Should we require a specific order?
constructorsOf: [
// TODO(johnniwinther): Should we normalize no-name constructor names?
'',
'constructor',
'fact',
'redirect',
],
),
};

const Map<String, FunctionData> expectedFunctionData = {
'topLevelFunction1': FunctionData(
returnType: NamedTypeData(name: 'void'),
Expand Down Expand Up @@ -187,7 +237,105 @@ Future<void> checkClassDeclaration(ClassDeclaration declaration,
'$name.constructorsOf[$i]');
}
}
// TODO(johnniwinther): Test more properties when there are supported.
// TODO(johnniwinther): Test more properties when they are supported.
} else {
throw 'Unexpected class declaration "${name}"';
}
}

Future<void> checkMixinDeclaration(MixinDeclaration declaration,
{DeclarationPhaseIntrospector? introspector}) async {
String name = declaration.identifier.name;
MixinData? expected = expectedMixinData[name];
if (expected != null) {
expect(expected.hasBase, declaration.hasBase, '$name.hasBase');
if (introspector != null) {
List<TypeDeclaration> superClassConstraints = [
for (NamedTypeAnnotation superclassConstraint
in declaration.superclassConstraints)
await introspector.typeDeclarationOf(superclassConstraint.identifier),
];
expect(expected.superclassConstraints.length,
superClassConstraints.length, '$name.superClassConstraints.length');
for (int i = 0; i < superClassConstraints.length; i++) {
expect(
expected.superclassConstraints[i],
superClassConstraints[i].identifier.name,
'$name.superClassConstraints[$i]');
}

List<TypeDeclaration> interfaces = [
for (NamedTypeAnnotation interface in declaration.interfaces)
await introspector.typeDeclarationOf(interface.identifier),
];
expect(expected.interfaces.length, interfaces.length,
'$name.interfaces.length');
for (int i = 0; i < interfaces.length; i++) {
expect(expected.interfaces[i], interfaces[i].identifier.name,
'$name.interfaces[$i]');
}
}
if (introspector != null) {
List<FieldDeclaration> fieldsOf =
await introspector.fieldsOf(declaration);
expect(
expected.fieldsOf.length, fieldsOf.length, '$name.fieldsOf.length');
for (int i = 0; i < fieldsOf.length; i++) {
expect(expected.fieldsOf[i], fieldsOf[i].identifier.name,
'$name.fieldsOf[$i]');
}

List<MethodDeclaration> methodsOf =
await introspector.methodsOf(declaration);
expect(expected.methodsOf.length, methodsOf.length,
'$name.methodsOf.length');
for (int i = 0; i < methodsOf.length; i++) {
expect(expected.methodsOf[i], methodsOf[i].identifier.name,
'$name.methodsOf[$i]');
}
}
// TODO(johnniwinther): Test more properties when they are supported.
} else {
throw 'Unexpected mixin declaration "${name}"';
}
}

Future<void> checkExtensionTypeDeclaration(ExtensionTypeDeclaration declaration,
{DeclarationPhaseIntrospector? introspector}) async {
String name = declaration.identifier.name;
ExtensionTypeData? expected = expectedExtensionTypeData[name];
if (expected != null) {
checkTypeAnnotation(expected.representationType,
declaration.representationType, '$name.representationType');
if (introspector != null) {
List<FieldDeclaration> fieldsOf =
await introspector.fieldsOf(declaration);
expect(
expected.fieldsOf.length, fieldsOf.length, '$name.fieldsOf.length');
for (int i = 0; i < fieldsOf.length; i++) {
expect(expected.fieldsOf[i], fieldsOf[i].identifier.name,
'$name.fieldsOf[$i]');
}

List<MethodDeclaration> methodsOf =
await introspector.methodsOf(declaration);
expect(expected.methodsOf.length, methodsOf.length,
'$name.methodsOf.length');
for (int i = 0; i < methodsOf.length; i++) {
expect(expected.methodsOf[i], methodsOf[i].identifier.name,
'$name.methodsOf[$i]');
}

List<ConstructorDeclaration> constructorsOf =
await introspector.constructorsOf(declaration);
expect(expected.constructorsOf.length, constructorsOf.length,
'$name.constructorsOf.length');
for (int i = 0; i < constructorsOf.length; i++) {
expect(expected.constructorsOf[i], constructorsOf[i].identifier.name,
'$name.constructorsOf[$i]');
}
}
// TODO(johnniwinther): Test more properties when they are supported.
} else {
throw 'Unexpected class declaration "${name}"';
}
Expand Down Expand Up @@ -232,9 +380,11 @@ Future<void> checkIdentifierResolver(TypePhaseIntrospector introspector) async {
Future<void> check(Uri uri, String name, {bool expectThrows = false}) async {
if (expectThrows) {
await throws(() async {
// ignore: deprecated_member_use
await introspector.resolveIdentifier(uri, name);
}, '$name from $uri');
} else {
// ignore: deprecated_member_use
Identifier result = await introspector.resolveIdentifier(uri, name);
expect(name, result.name, '$name from $uri');
}
Expand Down Expand Up @@ -265,7 +415,8 @@ Future<void> checkTypeDeclarationResolver(
await introspector.typeDeclarationOf(identifier);
}, '$name from $identifier',
expectedError: (e) => e is! MacroImplementationException
? 'Expected MacroImplementationException, got ${e.runtimeType}: $e'
? 'Expected MacroImplementationException, got ${e.runtimeType}: '
'$e'
: null);
} else {
TypeDeclaration result = await introspector.typeDeclarationOf(identifier);
Expand Down Expand Up @@ -302,6 +453,34 @@ class ClassData {
this.constructorsOf = const []});
}

class MixinData {
final bool hasBase;
final List<String> interfaces;
final List<String> superclassConstraints;
final List<String> fieldsOf;
final List<String> methodsOf;

const MixinData(
{this.hasBase = false,
this.interfaces = const [],
this.superclassConstraints = const [],
this.fieldsOf = const [],
this.methodsOf = const []});
}

class ExtensionTypeData {
final TypeData representationType;
final List<String> fieldsOf;
final List<String> methodsOf;
final List<String> constructorsOf;

const ExtensionTypeData(
{required this.representationType,
this.fieldsOf = const [],
this.methodsOf = const [],
this.constructorsOf = const []});
}

class FunctionData {
final bool isAbstract;
final bool isExternal;
Expand Down Expand Up @@ -333,8 +512,7 @@ class NamedTypeData extends TypeData {
final String? name;
final List<TypeData>? typeArguments;

const NamedTypeData({bool isNullable = false, this.name, this.typeArguments})
: super(isNullable: isNullable);
const NamedTypeData({super.isNullable, this.name, this.typeArguments});
}

class ParameterData {
Expand Down
Loading

0 comments on commit 95475e3

Please sign in to comment.