Upgraded to analyzer 5.x.x

This commit is contained in:
thomashii@dukefirehawk.com 2022-11-19 01:59:34 +08:00
parent bfc94d94eb
commit 0fa22e65e4
14 changed files with 61 additions and 52 deletions

View file

@ -1,8 +1,8 @@
# Change Log
## 7.0.1
## 7.1.0
* Upgraded dependencies
* Upgraded to `analyzer` 5.x.x
* Fixed deprecation
## 7.0.0

View file

@ -1,11 +1,11 @@
name: jael3_web
version: 7.0.1
version: 7.1.0
description: Experimental virtual DOM/SPA engine built on Jael3. Supports SSR.
publish_to: none
environment:
sdk: '>=2.17.0 <3.0.0'
dependencies:
analyzer: ^5.2.0
analyzer: ^5.0.0
build: ^2.0.2
build_config: ^1.0.0
code_builder: ^4.0.0

View file

@ -1,5 +1,10 @@
# Change Log
## 7.1.0
* Upgraded to `analyzer` 5.x.x
* Replaced deprecated `element2` with `element`
## 7.0.2
* Fixed deprecated `assignVar` and `assignConst`

View file

@ -226,7 +226,7 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
defaultExpr =
refer('RawSql').constInstance([literalString(value)]);
} else if (type is InterfaceType &&
type.element2 is EnumElement) {
type.element is EnumElement) {
// Default to enum index.
try {
var index =

View file

@ -74,7 +74,7 @@ Future<OrmBuildContext?> buildOrmContext(
.firstAnnotationOf(clazz)) !=
null) {
if (clazz.supertype != null) {
clazz = clazz.supertype!.element2;
clazz = clazz.supertype!.element;
}
}
@ -172,7 +172,7 @@ Future<OrmBuildContext?> buildOrmContext(
}
var modelType = firstModelAncestor(refType) ?? refType;
var modelTypeElement = modelType.element2;
var modelTypeElement = modelType.element;
if (modelTypeElement != null) {
foreign = await buildOrmContext(
@ -188,7 +188,7 @@ Future<OrmBuildContext?> buildOrmContext(
if (through != null && through is InterfaceType) {
throughContext = await buildOrmContext(
cache,
through.element2,
through.element,
ConstantReader(const TypeChecker.fromRuntime(Serializable)
.firstAnnotationOf(modelTypeElement)),
buildStep,
@ -253,9 +253,8 @@ Future<OrmBuildContext?> buildOrmContext(
// Unfortunately, the analyzer library provides little to nothing
// in the way of reading enums from source, so here's a hack.
var joinTypeType = (joinTypeRdr.type as InterfaceType);
var enumFields = joinTypeType.element2.fields
.where((f) => f.isEnumConstant)
.toList();
var enumFields =
joinTypeType.element.fields.where((f) => f.isEnumConstant).toList();
for (var i = 0; i < enumFields.length; i++) {
if (enumFields[i].computeConstantValue() == joinTypeRdr) {
@ -295,7 +294,7 @@ Future<OrmBuildContext?> buildOrmContext(
if (foreign != null) {
if (isSpecialId(foreign, foreignField)) {
// Use integer
type = field.type.element2?.library?.typeProvider.intType
type = field.type.element?.library?.typeProvider.intType
as DartType;
//type = field.type.element?.context.typeProvider.intType;
@ -364,7 +363,7 @@ ColumnType inferColumnType(DartType type) {
if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
return ColumnType.jsonb;
}
if (type is InterfaceType && type.element2 is EnumElement) {
if (type is InterfaceType && type.element is EnumElement) {
return ColumnType.int;
}

View file

@ -271,14 +271,14 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
// .call([expr.property('toString').call([])]);
expr = refer('mapToDouble').call([expr]);
} else if (fType is InterfaceType &&
fType.element2 is EnumElement) {
fType.element is EnumElement) {
var isNull = expr.equalTo(literalNull);
expr = isNull.conditional(literalNull,
type.property('values').index(expr.asA(refer('int'))));
} else if (fType.isDartCoreBool) {
// Generated Code: mapToBool(row[i])
expr = refer('mapToBool').call([expr]);
} else if (fType.element2?.displayName == 'DateTime') {
} else if (fType.element?.displayName == 'DateTime') {
// Generated Code: mapToDateTime(row[i])
if (fType.nullabilitySuffix == NullabilitySuffix.question) {
expr = refer('mapToNullableDateTime').call([expr]);
@ -300,7 +300,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
defaultRef = CodeExpression(Code('0.0'));
} else if (fType.isDartCoreInt || fType.isDartCoreNum) {
defaultRef = CodeExpression(Code('0'));
} else if (fType.element2?.displayName == 'DateTime') {
} else if (fType.element?.displayName == 'DateTime') {
defaultRef = CodeExpression(
Code('DateTime.parse("1970-01-01 00:00:00")'));
} else if (fType.isDartCoreList) {
@ -748,7 +748,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
builderType = TypeReference((b) => b
..symbol = 'NumericSqlExpressionBuilder'
..types.add(refer(typeName)));
} else if (type is InterfaceType && type.element2 is EnumElement) {
} else if (type is InterfaceType && type.element is EnumElement) {
builderType = TypeReference((b) => b
..symbol = 'EnumSqlExpressionBuilder'
..types.add(convertTypeReference(type)));
@ -884,7 +884,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
clazz.methods.add(Method((b) {
var value = refer('values').index(literalString(name!));
if (fType is InterfaceType && fType.element2 is EnumElement) {
if (fType is InterfaceType && fType.element is EnumElement) {
var asInt = value.asA(refer('int'));
var t = convertTypeReference(fType);
value = t.property('values').index(asInt);
@ -918,7 +918,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
clazz.methods.add(Method((b) {
Expression value = refer('value');
if (fType is InterfaceType && fType.element2 is EnumElement) {
if (fType is InterfaceType && fType.element is EnumElement) {
value = CodeExpression(Code('value?.index'));
} else if (const TypeChecker.fromRuntime(List)
.isAssignableFromType(fType)) {

View file

@ -1,5 +1,5 @@
name: angel3_orm_generator
version: 7.0.2
version: 7.1.0
description: Code generators for Angel3 ORM. Generates query builder classes.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_generator
@ -10,7 +10,7 @@ dependencies:
angel3_serialize: ^7.0.0
angel3_orm: ^7.0.0
angel3_serialize_generator: ^7.0.0
analyzer: ^4.0.0
analyzer: ^5.0.0
inflection3: ^0.5.3+1
build: ^2.0.1
build_config: ^1.0.0
@ -30,7 +30,7 @@ dev_dependencies:
postgres: ^2.4.0
test: ^1.21.0
lints: ^2.0.0
# dependency_overrides:
dependency_overrides:
# angel3_container:
# path: ../../container/angel_container
# angel3_framework:
@ -43,10 +43,10 @@ dev_dependencies:
# path: ../../route
# angel3_mock_request:
# path: ../../mock_request
# angel3_serialize:
# path: ../../serialize/angel_serialize
# angel3_serialize_generator:
# path: ../../serialize/angel_serialize_generator
# angel3_serialize:
# path: ../../serialize/angel_serialize
angel3_serialize_generator:
path: ../../serialize/angel_serialize_generator
# angel3_orm:
# path: ../angel_orm
# angel3_migration:

View file

@ -1,5 +1,10 @@
# Change Log
## 7.1.0
* Upgraded to `analyzer` 5.x.x
* Replaced deprecated `element2` with `element`
## 7.0.0
* Require Dart >= 2.17

View file

@ -40,7 +40,7 @@ Builder typescriptDefinitionBuilder(_) {
/// Converts a [DartType] to a [TypeReference].
TypeReference convertTypeReference(DartType t, {bool forceNullable = false}) {
return TypeReference((b) {
b.symbol = t.element2?.displayName;
b.symbol = t.element?.displayName;
// Generate nullable type
if (t.nullabilitySuffix == NullabilitySuffix.question || forceNullable) {
@ -112,21 +112,21 @@ String? dartObjectToString(DartObject v) {
.accept(DartEmitter(useNullSafetySyntax: true))
.toString();
}
if (type is InterfaceType && type.element2 is EnumElement) {
if (type is InterfaceType && type.element is EnumElement) {
// Find the index of the enum, then find the member.
for (var field in type.element2.fields) {
for (var field in type.element.fields) {
if (field.isEnumConstant && field.isStatic) {
var value = type.element2.getField(field.name)!.computeConstantValue();
var value = type.element.getField(field.name)!.computeConstantValue();
if (v is Enum && value is Enum) {
var v2 = v as Enum;
var value2 = value as Enum;
if (value2.name == v2.name) {
return '${type.element2.displayName}.${field.name}';
return '${type.element.displayName}.${field.name}';
}
} else {
if (value == v) {
return '${type.element2.displayName}.${field.name}';
return '${type.element.displayName}.${field.name}';
}
}
}
@ -140,11 +140,11 @@ String? dartObjectToString(DartObject v) {
bool isModelClass(DartType? t) {
if (t == null) return false;
if (serializableTypeChecker.hasAnnotationOf(t.element2!)) {
if (serializableTypeChecker.hasAnnotationOf(t.element!)) {
return true;
}
if (generatedSerializableTypeChecker.hasAnnotationOf(t.element2!)) {
if (generatedSerializableTypeChecker.hasAnnotationOf(t.element!)) {
return true;
}
@ -177,7 +177,7 @@ bool isListOrMapType(DartType t) {
bool isEnumType(DartType t) {
if (t is InterfaceType) {
return t.element2 is Enum;
return t.element is Enum;
}
return false;
@ -204,13 +204,13 @@ bool isAssignableToModel(DartType type) =>
String? typeToString(DartType type) {
if (type is InterfaceType) {
if (type.typeArguments.isEmpty) {
return type.element2.displayName;
return type.element.displayName;
}
var name = type.element2.displayName;
var name = type.element.displayName;
return '$name<${type.typeArguments.map(typeToString).join(', ')}>';
} else {
return type.element2?.displayName;
return type.element?.displayName;
}
}

View file

@ -62,7 +62,7 @@ Future<BuildContext?> buildContext(
// Crawl for classes from parent classes.
void crawlClass(InterfaceType? t) {
while (t != null) {
fields.insertAll(0, t.element2.fields);
fields.insertAll(0, t.element.fields);
t.interfaces.forEach(crawlClass);
t = t.superclass;
}

View file

@ -254,7 +254,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
if (type.typeArguments.length == 1) {
var eq = generateEquality(type.typeArguments[0]);
return 'ListEquality<${type.typeArguments[0].element2!.name}>($eq)';
return 'ListEquality<${type.typeArguments[0].element!.name}>($eq)';
} else {
return 'ListEquality()';
}
@ -263,20 +263,20 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
if (type.typeArguments.length == 2) {
var keq = generateEquality(type.typeArguments[0]),
veq = generateEquality(type.typeArguments[1]);
return 'MapEquality<${type.typeArguments[0].element2!.name}, ${type.typeArguments[1].element2!.name}>(keys: $keq, values: $veq)';
return 'MapEquality<${type.typeArguments[0].element!.name}, ${type.typeArguments[1].element!.name}>(keys: $keq, values: $veq)';
} else {
return 'MapEquality()';
}
}
return nullable ? null : 'DefaultEquality<${type.element2.name}>()';
return nullable ? null : 'DefaultEquality<${type.element.name}>()';
} else {
return 'DefaultEquality()';
}
}
static String Function(String, String) generateComparator(DartType type) {
if (type is! InterfaceType || type.element2.displayName == 'dynamic') {
if (type is! InterfaceType || type.element.displayName == 'dynamic') {
return (a, b) => '$a == $b';
}
var eq = generateEquality(type, true);

View file

@ -214,7 +214,7 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
return (map as Map<dynamic,dynamic>?)?..[key] =
${serializerToMap(rc, 'model.${field.name}[key]')};
})''';
} else if (type.element2 is Enum) {
} else if (type.element is Enum) {
var convert =
(field.type.nullabilitySuffix == NullabilitySuffix.question)
? '!'
@ -390,7 +390,7 @@ class ${pascal}Decoder extends Converter<Map, $pascal> {
}))
: $defaultValue
''';
} else if (type.element2 is Enum) {
} else if (type.element is Enum) {
deserializedRepresentation = '''
map['$alias'] is ${type.getDisplayString(withNullability: true)}
? (map['$alias'] as ${type.getDisplayString(withNullability: true)}) ?? $defaultValue

View file

@ -77,15 +77,15 @@ class TypeScriptDefinitionBuilder implements Builder {
}
} else if (isModelClass(type)) {
var sourcePath = buildStep.inputId.uri.toString();
var targetPath = type.element2.source.uri.toString();
var targetPath = type.element.source.uri.toString();
if (!p.equals(sourcePath, targetPath)) {
var relative = p.relative(targetPath, from: sourcePath);
String? ref;
if (type.element2.source.uri.scheme == 'asset') {
if (type.element.source.uri.scheme == 'asset') {
var id =
AssetId.resolve(Uri.parse(type.element2.source.uri.toString()));
AssetId.resolve(Uri.parse(type.element.source.uri.toString()));
if (id.package != buildStep.inputId.package) {
ref = '/// <reference types="${id.package}" />';
}
@ -105,9 +105,9 @@ class TypeScriptDefinitionBuilder implements Builder {
}
var ctx = await buildContext(
type.element2,
type.element,
ConstantReader(
serializableTypeChecker.firstAnnotationOf(type.element2)),
serializableTypeChecker.firstAnnotationOf(type.element)),
buildStep,
buildStep.resolver,
autoSnakeCaseNames,

View file

@ -1,12 +1,12 @@
name: angel3_serialize_generator
version: 7.0.0
version: 7.1.0
description: Angel3 model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/serialize/angel_serialize_generator
environment:
sdk: '>=2.17.0 <3.0.0'
dependencies:
analyzer: ^4.1.0
analyzer: ^5.0.0
angel3_model: ^7.0.0
angel3_serialize: ^7.0.0
belatuk_code_buffer: ^4.0.0