Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

update tool/generate_* scripts and sync files generated by those scripts #150

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions goldens/foo/lib/built_value/built_value_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,33 @@ void main() {
b
..aPrimitiveFields.anInt = 3
..aPrimitiveFields.aString = 'four'
..aString = 'five',
..aString = 'five'
..stringWrapper = StringWraper('six'),
);
expect(
value.toString(),
'NestedFields(aPrimitiveFields: PrimitiveFields('
'anInt: 3, aString: four, aNullableString: null), aString: five)',
'anInt: 3, aString: four, aNullableString: null), '
'stringWrapper: StringWrapper(aString: six), aString: five)',
);
});
});
}

class NonMacro {
const NonMacro();
}

@NonMacro()
class StringWraper {
eEQK marked this conversation as resolved.
Show resolved Hide resolved
const StringWraper(this.aString);

final String aString;

@override
String toString() => 'StringWrapper(aString: $aString)';
}

@BuiltValue()
class Empty {}

Expand All @@ -78,5 +94,6 @@ class PrimitiveFields {
@BuiltValue()
class NestedFields {
final PrimitiveFields aPrimitiveFields;
final StringWraper stringWrapper;
final String aString;
}
16 changes: 12 additions & 4 deletions goldens/foo/lib/foo.analyzer.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,18 @@
"value": {
"reference": {
"type": "ClassReference",
"value": {}
"value": {
"name": "QueryClass"
}
},
"typeArguments": []
}
},
"constructor": {
"type": "ConstructorReference",
"value": {}
"value": {
"name": "new"
}
},
"arguments": []
}
Expand Down Expand Up @@ -272,14 +276,18 @@
"value": {
"reference": {
"type": "ClassReference",
"value": {}
"value": {
"name": "QueryClass"
}
},
"typeArguments": []
}
},
"constructor": {
"type": "ConstructorReference",
"value": {}
"value": {
"name": "new"
}
},
"arguments": []
}
Expand Down
4 changes: 2 additions & 2 deletions goldens/foo/lib/literal_params.analyzer.augmentations
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ augment class Foo {
// aNum: 8.0, double
// aDouble: 9.0, double
// aString: 10, String
// anObject: {type: {type: NamedTypeAnnotation, value: {reference: {type: ClassReference, value: {}}, typeArguments: []}}, constructor: {type: ConstructorReference, value: {}}, arguments: [{type: NamedArgument, value: {name: a, expression: {type: BooleanLiteral, value: {text: true}}}}, {type: NamedArgument, value: {name: b, expression: {type: BooleanLiteral, value: {text: false}}}}]}, String
// anObject: {type: {type: NamedTypeAnnotation, value: {reference: {type: ClassReference, value: {name: Bar}}, typeArguments: []}}, constructor: {type: ConstructorReference, value: {name: new}}, arguments: [{type: NamedArgument, value: {name: a, expression: {type: BooleanLiteral, value: {value: true}}}}, {type: NamedArgument, value: {name: b, expression: {type: BooleanLiteral, value: {value: false}}}}]}, String
// ints: [11, 12], List<Object>
// nums: [13.0, 14], List<Object>
// doubles: [15.0, 16], List<Object>
// strings: [17, eighteen], List<Object>
// objects: [19, {type: {type: NamedTypeAnnotation, value: {reference: {type: ClassReference, value: {}}, typeArguments: []}}, constructor: {type: ConstructorReference, value: {}}, arguments: [{type: NamedArgument, value: {name: a, expression: {type: BooleanLiteral, value: {text: true}}}}, {type: NamedArgument, value: {name: b, expression: {type: BooleanLiteral, value: {text: false}}}}]}], List<Object>
// objects: [19, {type: {type: NamedTypeAnnotation, value: {reference: {type: ClassReference, value: {name: Bar}}, typeArguments: []}}, constructor: {type: ConstructorReference, value: {name: new}}, arguments: [{type: NamedArgument, value: {name: a, expression: {type: BooleanLiteral, value: {value: true}}}}, {type: NamedArgument, value: {name: b, expression: {type: BooleanLiteral, value: {value: false}}}}]}], List<Object>
}
21 changes: 15 additions & 6 deletions goldens/foo/lib/metadata.analyzer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@
"value": {
"reference": {
"type": "ClassReference",
"value": {}
"value": {
"name": "QueryClass"
}
},
"typeArguments": []
}
},
"constructor": {
"type": "ConstructorReference",
"value": {}
"value": {
"name": "new"
}
},
"arguments": []
}
Expand All @@ -50,14 +54,18 @@
"value": {
"reference": {
"type": "ClassReference",
"value": {}
"value": {
"name": "Annotation"
}
},
"typeArguments": []
}
},
"constructor": {
"type": "ConstructorReference",
"value": {}
"value": {
"name": "new"
}
},
"arguments": [
{
Expand All @@ -67,7 +75,7 @@
"expression": {
"type": "BooleanLiteral",
"value": {
"text": "true"
"value": true
}
}
}
Expand All @@ -79,7 +87,8 @@
"expression": {
"type": "IntegerLiteral",
"value": {
"text": "23"
"text": "23",
"value": 23
}
}
}
Expand Down
42 changes: 28 additions & 14 deletions pkgs/_analyzer_cfe_macros/lib/metadata_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ dart_model.Reference? convertToReference(Object? object) => switch (object) {
front_end.EnumReference o => dart_model.Reference.enumReference(
convert<dart_model.EnumReference>(o)!,
),
front_end.MixinReference o => dart_model.Reference.mixinReference(
convert<dart_model.MixinReference>(o)!,
),
front_end.FunctionTypeParameterReference o => dart_model
.Reference.functionTypeParameterReference(
convert<dart_model.FunctionTypeParameterReference>(o)!,
Expand Down Expand Up @@ -250,6 +253,8 @@ T? convert<T>(Object? object) => switch (object) {
front_end.BinaryOperator o => o.name as T,
front_end.LogicalOperator o => o.name as T,
front_end.UnaryOperator o => o.name as T,
front_end.AdjacentStringLiterals o =>
dart_model.AdjacentStringLiterals(expressions: convert(o.expressions)) as T,
front_end.AsExpression o =>
dart_model.AsExpression(
expression: convertToExpression(o.expression),
Expand All @@ -264,8 +269,9 @@ T? convert<T>(Object? object) => switch (object) {
)
as T,
front_end.BooleanLiteral o =>
dart_model.BooleanLiteral(text: convert(o.value.toString())) as T,
front_end.ClassReference o => dart_model.ClassReference() as T,
dart_model.BooleanLiteral(value: convert(o.value)) as T,
front_end.ClassReference o =>
dart_model.ClassReference(name: convert(o.name)) as T,
front_end.ConditionalExpression o =>
dart_model.ConditionalExpression(
condition: convertToExpression(o.condition),
Expand All @@ -280,19 +286,22 @@ T? convert<T>(Object? object) => switch (object) {
arguments: convert(o.arguments),
)
as T,
front_end.ConstructorReference o => dart_model.ConstructorReference() as T,
front_end.ConstructorReference o =>
dart_model.ConstructorReference(name: convert(o.name)) as T,
front_end.ConstructorTearOff o =>
dart_model.ConstructorTearOff(
type: convert(o.type),
reference: convert(o.reference),
)
as T,
front_end.DoubleLiteral o =>
dart_model.DoubleLiteral(text: convert(o.text)) as T,
dart_model.DoubleLiteral(text: convert(o.text), value: convert(o.value))
as T,
front_end.DynamicTypeAnnotation o =>
dart_model.DynamicTypeAnnotation(reference: convertToReference(o.reference))
as T,
front_end.EnumReference o => dart_model.EnumReference() as T,
front_end.EnumReference o =>
dart_model.EnumReference(name: convert(o.name)) as T,
front_end.EqualityExpression o =>
dart_model.EqualityExpression(
left: convertToExpression(o.left),
Expand All @@ -306,13 +315,16 @@ T? convert<T>(Object? object) => switch (object) {
isNullAware: convert(o.isNullAware),
)
as T,
front_end.ExtensionReference o => dart_model.ExtensionReference() as T,
front_end.ExtensionReference o =>
dart_model.ExtensionReference(name: convert(o.name)) as T,
front_end.ExtensionTypeReference o =>
dart_model.ExtensionTypeReference() as T,
front_end.FieldReference o => dart_model.FieldReference() as T,
dart_model.ExtensionTypeReference(name: convert(o.name)) as T,
front_end.FieldReference o =>
dart_model.FieldReference(name: convert(o.name)) as T,
front_end.FormalParameter o => dart_model.FormalParameter() as T,
front_end.FormalParameterGroup o => dart_model.FormalParameterGroup() as T,
front_end.FunctionReference o => dart_model.FunctionReference() as T,
front_end.FunctionReference o =>
dart_model.FunctionReference(name: convert(o.name)) as T,
front_end.FunctionTearOff o =>
dart_model.FunctionTearOff(reference: convert(o.reference)) as T,
front_end.FunctionTypeAnnotation o =>
Expand All @@ -324,7 +336,7 @@ T? convert<T>(Object? object) => switch (object) {
as T,
front_end.FunctionTypeParameter o => dart_model.FunctionTypeParameter() as T,
front_end.FunctionTypeParameterReference o =>
dart_model.FunctionTypeParameterReference() as T,
dart_model.FunctionTypeParameterReference(name: convert(o.name)) as T,
front_end.FunctionTypeParameterType o =>
dart_model.FunctionTypeParameterType(
functionTypeParameter: convert(o.functionTypeParameter),
Expand Down Expand Up @@ -357,7 +369,8 @@ T? convert<T>(Object? object) => switch (object) {
)
as T,
front_end.IntegerLiteral o =>
dart_model.IntegerLiteral(text: convert(o.text)) as T,
dart_model.IntegerLiteral(text: convert(o.text), value: convert(o.value))
as T,
front_end.InterpolationPart o =>
dart_model.InterpolationPart(expression: convertToExpression(o.expression))
as T,
Expand Down Expand Up @@ -399,6 +412,8 @@ T? convert<T>(Object? object) => switch (object) {
arguments: convert(o.arguments),
)
as T,
front_end.MixinReference o =>
dart_model.MixinReference(name: convert(o.name)) as T,
front_end.NamedArgument o =>
dart_model.NamedArgument(
name: convert(o.name),
Expand Down Expand Up @@ -479,14 +494,13 @@ T? convert<T>(Object? object) => switch (object) {
arguments: convert(o.arguments),
)
as T,
front_end.AdjacentStringLiterals o =>
dart_model.AdjacentStringLiterals(expressions: convert(o.expressions)) as T,
front_end.StringLiteral o =>
dart_model.StringLiteral(parts: convert(o.parts)) as T,
front_end.StringPart o => dart_model.StringPart(text: convert(o.text)) as T,
front_end.SymbolLiteral o =>
dart_model.SymbolLiteral(parts: convert(o.parts)) as T,
front_end.TypedefReference o => dart_model.TypedefReference() as T,
front_end.TypedefReference o =>
dart_model.TypedefReference(name: convert(o.name)) as T,
front_end.TypeLiteral o =>
dart_model.TypeLiteral(typeAnnotation: convert(o.typeAnnotation)) as T,
front_end.TypeReference o => dart_model.TypeReference() as T,
Expand Down
8 changes: 4 additions & 4 deletions pkgs/_analyzer_cfe_macros/test/metadata_converter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
expect(convert<Object>(invocation), <String, Object?>{
'receiver': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'},
'value': {'text': '1.23', 'value': 1.23},
},
'name': 'round',
'typeArguments': [],
Expand All @@ -40,12 +40,12 @@ void main() {
expect(convert<Object>(expression), <String, Object?>{
'left': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'},
'value': {'text': '1.23', 'value': 1.23},
},
'operator': 'minus',
'right': {
'type': 'DoubleLiteral',
'value': {'text': '1.24'},
'value': {'text': '1.24', 'value': 1.24},
},
});
});
Expand All @@ -63,7 +63,7 @@ void main() {
expect(convert<Object>(invocation), <String, Object?>{
'receiver': {
'type': 'DoubleLiteral',
'value': {'text': '1.23'},
'value': {'text': '1.23', 'value': 1.23},
},
'name': 'round',
'typeArguments': [],
Expand Down
16 changes: 14 additions & 2 deletions pkgs/_test_macros/lib/built_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,20 @@ class BuiltValueBuilderImplementation implements ClassDeclarationsMacro {
TypeAnnotationType.namedTypeAnnotation) {
continue;
}
// TODO(davidmorgan): macro metadata model doesn't actually have the
// name yet, just assume any constructor annotation is `BuiltValue`.

final namedTypeAnnotation =
constructorInvocation.type.asNamedTypeAnnotation;
if (namedTypeAnnotation.reference.type !=
ReferenceType.classReference) {
continue;
}

final constructorReference =
namedTypeAnnotation.reference.asClassReference;
if (constructorReference.name != 'BuiltValue') {
continue;
}

nestedBuilderTypes.add(qualifiedName.asString);
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/_test_macros/lib/literal_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class LiteralParamsImplementation implements ClassDeclarationsMacro {
extension ExpressionExtension on Expression {
Object get evaluate => switch (type) {
ExpressionType.integerLiteral => int.parse(asIntegerLiteral.text),
ExpressionType.doubleLiteral => double.parse(asDoubleLiteral.text),
ExpressionType.doubleLiteral => asDoubleLiteral.value,
ExpressionType.stringLiteral => asStringLiteral.evaluate,
ExpressionType.booleanLiteral => bool.parse(asBooleanLiteral.text),
ExpressionType.booleanLiteral => asBooleanLiteral.value,
ExpressionType.listLiteral =>
asListLiteral.elements.map((e) => e.evaluate).toList(),
// TODO(davidmorgan): need the type name to do something useful here,
Expand Down
Loading
Loading