Skip to content

Commit 51c6aa4

Browse files
committed
Support latest version of build, upgrade analyzer dev
Also stop using most deprecated analyzer APIs
1 parent 7f92d35 commit 51c6aa4

15 files changed

+61
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.0+1
2+
3+
* Support the latest version of `pkg/build`.
4+
15
## 0.5.0
26

37
* **Breaking**: Switch to the `build` package for running `Generator`s. This

lib/generators/json_literal_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ library source_gen.example.json_literal_generator;
77
import 'dart:async';
88
import 'dart:convert';
99

10-
import 'package:analyzer/src/generated/element.dart';
10+
import 'package:analyzer/dart/element/element.dart';
1111
import 'package:build/build.dart';
1212
import 'package:path/path.dart' as p;
1313
import 'package:source_gen/source_gen.dart';

lib/generators/json_serializable_generator.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
library source_gen.json_serial.generator;
66

77
import 'dart:async';
8-
import 'package:analyzer/src/generated/element.dart';
9-
import 'package:analyzer/src/generated/utilities_dart.dart';
108

9+
import 'package:analyzer/dart/element/element.dart';
10+
import 'package:analyzer/dart/element/type.dart';
11+
import 'package:analyzer/src/generated/utilities_dart.dart';
1112
import 'package:source_gen/source_gen.dart';
12-
import 'package:source_gen/src/utils.dart';
1313
import 'package:source_gen/src/annotation.dart';
14+
import 'package:source_gen/src/utils.dart';
1415

1516
import 'json_serializable.dart';
1617

@@ -260,7 +261,7 @@ bool _hasFromJsonCtor(DartType type) {
260261
return false;
261262
}
262263

263-
DartType _getIterableGenericType(InterfaceTypeImpl type) {
264+
DartType _getIterableGenericType(InterfaceType type) {
264265
var iterableThing = _typeTest(type, _isDartIterable);
265266

266267
return iterableThing.typeArguments.single;

lib/src/annotation.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ library source_gen.annotation;
77
import 'dart:io';
88
import 'dart:mirrors';
99

10-
import 'package:analyzer/src/generated/ast.dart';
10+
import 'package:analyzer/dart/ast/ast.dart';
11+
import 'package:analyzer/dart/element/element.dart';
12+
import 'package:analyzer/dart/element/type.dart';
1113
import 'package:analyzer/src/generated/constant.dart';
12-
import 'package:analyzer/src/generated/element.dart';
13-
import 'package:analyzer/src/generated/utilities_dart.dart';
14+
import 'package:analyzer/src/generated/element.dart'
15+
show ConstructorElementImpl;
1416
import 'package:analyzer/src/generated/resolver.dart';
17+
import 'package:analyzer/src/generated/utilities_dart.dart';
1518
import 'package:path/path.dart' as p;
1619

17-
dynamic instantiateAnnotation(ElementAnnotationImpl annotation) {
18-
var annotationObjectImpl = annotation.evaluationResult.value;
20+
dynamic instantiateAnnotation(ElementAnnotation annotation) {
21+
var annotationObject = annotation.constantValue;
1922
try {
20-
return _getValue(
21-
annotationObjectImpl, annotation.element.context.typeProvider);
23+
return _getValue(annotationObject, annotation.element.context.typeProvider);
2224
} on CannotCreateFromAnnotationException catch (e) {
2325
if (e.innerException != null) {
2426
// If there was a issue creating a nested object, there's not much we
@@ -29,20 +31,19 @@ dynamic instantiateAnnotation(ElementAnnotationImpl annotation) {
2931

3032
var element = annotation.element;
3133

32-
if (element is PropertyAccessorElementImpl) {
33-
var initializer = ((element as PropertyAccessorElementImpl)
34+
if (element is PropertyAccessorElement) {
35+
var initializer = ((element as PropertyAccessorElement)
3436
.variable
3537
.computeNode() as VariableDeclaration)
3638
.initializer as InstanceCreationExpression;
3739
element = initializer.staticElement;
3840
}
3941

40-
if (element is ConstructorElementImpl) {
41-
return _createFromConstructor(element, annotationObjectImpl);
42+
if (element is ConstructorElement) {
43+
return _createFromConstructor(element, annotationObject);
4244
}
4345

44-
var valueDeclaration =
45-
_getDeclMirrorFromType(annotation.evaluationResult.value.type);
46+
var valueDeclaration = _getDeclMirrorFromType(annotation.constantValue.type);
4647

4748
throw "No clue how to create $valueDeclaration of type ${valueDeclaration.runtimeType}";
4849
}
@@ -75,7 +76,7 @@ dynamic _getValue(DartObject object, TypeProvider typeProvider) {
7576
if (object.type == typeProvider.typeType) {
7677
var typeData = object.toTypeValue();
7778

78-
if (typeData is InterfaceTypeImpl) {
79+
if (typeData is InterfaceType) {
7980
var declarationMirror = _getDeclMirrorFromType(typeData) as ClassMirror;
8081

8182
return declarationMirror.reflectedType;
@@ -140,12 +141,13 @@ dynamic _createFromConstructor(
140141
for (var p in ctorDecl.parameters.parameterElements) {
141142
var paramName = p.name;
142143
String fieldName;
143-
if (p is FieldFormalParameterElementImpl) {
144+
if (p is FieldFormalParameterElement) {
144145
fieldName = p.name;
145146
} else {
146147
// Trying to find the relationship between the ctor argument name and the
147148
// field assigned in the object. Then we can take the field value and
148149
// set it as the argument value
150+
149151
var initializer = ctor.constantInitializers.singleWhere((ci) {
150152
var expression = (ci as ConstructorFieldInitializer).expression;
151153
if (expression is SimpleIdentifier) {
@@ -203,11 +205,11 @@ DeclarationMirror _getDeclMirrorFromType(InterfaceType type) {
203205
return libMirror.declarations[typeNameSymbol];
204206
}
205207

206-
bool matchAnnotation(Type annotationType, ElementAnnotationImpl annotation) {
208+
bool matchAnnotation(Type annotationType, ElementAnnotation annotation) {
207209
var classMirror = reflectClass(annotationType);
208210
var classMirrorSymbol = classMirror.simpleName;
209211

210-
var annotationValueType = annotation.evaluationResult.value.type;
212+
var annotationValueType = annotation.constantValue.type;
211213

212214
var annTypeName = annotationValueType.name;
213215
var annotationTypeSymbol = new Symbol(annTypeName);

lib/src/builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44
import 'dart:async';
55

6-
import 'package:analyzer/src/generated/element.dart';
6+
import 'package:analyzer/dart/element/element.dart';
77
import 'package:build/build.dart';
88
import 'package:dart_style/src/dart_formatter.dart';
99

lib/src/generated_output.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library source_gen.generated_output;
66

77
import 'dart:convert';
88

9-
import 'package:analyzer/src/generated/element.dart';
9+
import 'package:analyzer/dart/element/element.dart';
1010

1111
import 'generator.dart';
1212

lib/src/generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library source_gen.generator;
66

77
import 'dart:async';
88

9-
import 'package:analyzer/src/generated/element.dart';
9+
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:build/build.dart';
1111

1212
abstract class Generator {

lib/src/generator_for_annotation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library source_gen.generator_for_annotation;
66

77
import 'dart:async';
88

9-
import 'package:analyzer/src/generated/element.dart';
9+
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:build/build.dart';
1111

1212
import 'annotation.dart';

lib/src/utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import 'dart:async';
88
import 'dart:io';
99

1010
import 'package:analyzer/analyzer.dart';
11+
import 'package:analyzer/dart/ast/ast.dart';
12+
import 'package:analyzer/dart/element/element.dart';
1113
import 'package:analyzer/file_system/file_system.dart' hide File;
1214
import 'package:analyzer/file_system/physical_file_system.dart';
1315
import 'package:analyzer/source/package_map_provider.dart';
1416
import 'package:analyzer/source/package_map_resolver.dart';
1517
import 'package:analyzer/source/pub_package_map_provider.dart';
16-
import 'package:analyzer/src/generated/ast.dart';
17-
import 'package:analyzer/src/generated/element.dart';
1818
import 'package:analyzer/src/generated/engine.dart';
1919
import 'package:analyzer/src/generated/java_io.dart';
20-
import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
2120
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
22-
import 'package:analyzer/src/generated/source_io.dart';
21+
import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
2322
import 'package:analyzer/src/generated/source.dart';
23+
import 'package:analyzer/src/generated/source_io.dart';
2424
import 'package:cli_util/cli_util.dart' as cli;
2525
import 'package:path/path.dart' as p;
2626

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: source_gen
2-
version: 0.5.0
2+
version: 0.5.0+1
33
author: Dart Team <[email protected]>
44
description: Automatic sourcecode generation for Dart
55
homepage: https://github.com/dart-lang/source_gen
66
environment:
77
sdk: '>=1.12.0 <2.0.0'
88
dependencies:
9-
analyzer: '^0.27.3-alpha.1'
10-
build: ^0.2.1
9+
analyzer: '^0.27.3'
10+
build: '>=0.2.1 <0.4.0'
1111
cli_util: ^0.0.1
1212
dart_style: '>=0.1.7 <0.3.0'
1313
path: ^1.3.2

0 commit comments

Comments
 (0)