From 0fa22e65e49f542144c92e2026159c4273b2ac80 Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Sat, 19 Nov 2022 01:59:34 +0800 Subject: [PATCH] Upgraded to analyzer 5.x.x --- packages/jael/jael_web/CHANGELOG.md | 4 ++-- packages/jael/jael_web/pubspec.yaml | 4 ++-- packages/orm/angel_orm_generator/CHANGELOG.md | 5 ++++ .../lib/src/migration_generator.dart | 2 +- .../lib/src/orm_build_context.dart | 15 ++++++------ .../lib/src/orm_generator.dart | 12 +++++----- packages/orm/angel_orm_generator/pubspec.yaml | 14 +++++------ .../angel_serialize_generator/CHANGELOG.md | 5 ++++ .../lib/angel3_serialize_generator.dart | 24 +++++++++---------- .../lib/build_context.dart | 2 +- .../angel_serialize_generator/lib/model.dart | 8 +++---- .../lib/serialize.dart | 4 ++-- .../lib/typescript.dart | 10 ++++---- .../angel_serialize_generator/pubspec.yaml | 4 ++-- 14 files changed, 61 insertions(+), 52 deletions(-) diff --git a/packages/jael/jael_web/CHANGELOG.md b/packages/jael/jael_web/CHANGELOG.md index e91eafde..344317b1 100644 --- a/packages/jael/jael_web/CHANGELOG.md +++ b/packages/jael/jael_web/CHANGELOG.md @@ -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 diff --git a/packages/jael/jael_web/pubspec.yaml b/packages/jael/jael_web/pubspec.yaml index 2f29e0c6..85dedbe0 100644 --- a/packages/jael/jael_web/pubspec.yaml +++ b/packages/jael/jael_web/pubspec.yaml @@ -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 diff --git a/packages/orm/angel_orm_generator/CHANGELOG.md b/packages/orm/angel_orm_generator/CHANGELOG.md index dca6c15e..be179786 100644 --- a/packages/orm/angel_orm_generator/CHANGELOG.md +++ b/packages/orm/angel_orm_generator/CHANGELOG.md @@ -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` diff --git a/packages/orm/angel_orm_generator/lib/src/migration_generator.dart b/packages/orm/angel_orm_generator/lib/src/migration_generator.dart index 2f40e657..48711489 100644 --- a/packages/orm/angel_orm_generator/lib/src/migration_generator.dart +++ b/packages/orm/angel_orm_generator/lib/src/migration_generator.dart @@ -226,7 +226,7 @@ class MigrationGenerator extends GeneratorForAnnotation { 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 = diff --git a/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart b/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart index e28eb03a..34f79482 100644 --- a/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart +++ b/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart @@ -74,7 +74,7 @@ Future buildOrmContext( .firstAnnotationOf(clazz)) != null) { if (clazz.supertype != null) { - clazz = clazz.supertype!.element2; + clazz = clazz.supertype!.element; } } @@ -172,7 +172,7 @@ Future 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 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 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 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; } diff --git a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart index c61e25c2..e7bd8683 100644 --- a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart +++ b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart @@ -271,14 +271,14 @@ class OrmGenerator extends GeneratorForAnnotation { // .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 { 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 { 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 { 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 { 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)) { diff --git a/packages/orm/angel_orm_generator/pubspec.yaml b/packages/orm/angel_orm_generator/pubspec.yaml index f695df0c..6f327e1f 100644 --- a/packages/orm/angel_orm_generator/pubspec.yaml +++ b/packages/orm/angel_orm_generator/pubspec.yaml @@ -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: diff --git a/packages/serialize/angel_serialize_generator/CHANGELOG.md b/packages/serialize/angel_serialize_generator/CHANGELOG.md index a59ea888..0e6eb935 100644 --- a/packages/serialize/angel_serialize_generator/CHANGELOG.md +++ b/packages/serialize/angel_serialize_generator/CHANGELOG.md @@ -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 diff --git a/packages/serialize/angel_serialize_generator/lib/angel3_serialize_generator.dart b/packages/serialize/angel_serialize_generator/lib/angel3_serialize_generator.dart index d42c6287..48beaa51 100644 --- a/packages/serialize/angel_serialize_generator/lib/angel3_serialize_generator.dart +++ b/packages/serialize/angel_serialize_generator/lib/angel3_serialize_generator.dart @@ -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; } } diff --git a/packages/serialize/angel_serialize_generator/lib/build_context.dart b/packages/serialize/angel_serialize_generator/lib/build_context.dart index acbd0444..91436cc9 100644 --- a/packages/serialize/angel_serialize_generator/lib/build_context.dart +++ b/packages/serialize/angel_serialize_generator/lib/build_context.dart @@ -62,7 +62,7 @@ Future 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; } diff --git a/packages/serialize/angel_serialize_generator/lib/model.dart b/packages/serialize/angel_serialize_generator/lib/model.dart index 11096f72..3285cb5e 100644 --- a/packages/serialize/angel_serialize_generator/lib/model.dart +++ b/packages/serialize/angel_serialize_generator/lib/model.dart @@ -254,7 +254,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { 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 { 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); diff --git a/packages/serialize/angel_serialize_generator/lib/serialize.dart b/packages/serialize/angel_serialize_generator/lib/serialize.dart index 4c5c26ce..7254a1e6 100644 --- a/packages/serialize/angel_serialize_generator/lib/serialize.dart +++ b/packages/serialize/angel_serialize_generator/lib/serialize.dart @@ -214,7 +214,7 @@ class ${pascal}Decoder extends Converter { return (map as Map?)?..[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 { })) : $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 diff --git a/packages/serialize/angel_serialize_generator/lib/typescript.dart b/packages/serialize/angel_serialize_generator/lib/typescript.dart index 78187784..45bbf304 100644 --- a/packages/serialize/angel_serialize_generator/lib/typescript.dart +++ b/packages/serialize/angel_serialize_generator/lib/typescript.dart @@ -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 = '/// '; } @@ -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, diff --git a/packages/serialize/angel_serialize_generator/pubspec.yaml b/packages/serialize/angel_serialize_generator/pubspec.yaml index eab35bdf..bcb2a032 100644 --- a/packages/serialize/angel_serialize_generator/pubspec.yaml +++ b/packages/serialize/angel_serialize_generator/pubspec.yaml @@ -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