Skip to content

Commit

Permalink
Use source_gen for JSON serialization (dart-lang#31)
Browse files Browse the repository at this point in the history
...for a few classes
  • Loading branch information
kevmoo authored Jun 14, 2017
1 parent 2e30307 commit 0553030
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 32 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ linter:
- valid_regexps

# Style
- annotate_overrides
- avoid_init_to_null
- avoid_return_types_on_setters
- await_only_futures
Expand Down
28 changes: 11 additions & 17 deletions lib/src/analyzer_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library pana.analyzer_output;

import 'package:path/path.dart' as p;
import 'package:quiver/core.dart';
import 'package:source_gen/generators/json_serializable.dart';

part 'analyzer_output.g.dart';

class AnalyzerOutput implements Comparable<AnalyzerOutput> {
@JsonSerializable()
class AnalyzerOutput extends Object
with _$AnalyzerOutputSerializerMixin
implements Comparable<AnalyzerOutput> {
static final _regexp = new RegExp('^' + // beginning of line
'([\\w_\\.]+)\\|' * 3 + // first three error notes
'([^\\|]+)\\|' + // file path
Expand Down Expand Up @@ -69,22 +77,8 @@ class AnalyzerOutput implements Comparable<AnalyzerOutput> {
type, error, filePath, int.parse(line), int.parse(column));
}

factory AnalyzerOutput.fromJson(Map<String, dynamic> json) {
var type = json['type'];
var error = json['error'];
var file = json['file'];
var line = json['line'];
var col = json['col'];
return new AnalyzerOutput(type, error, file, line, col);
}

Map<String, dynamic> toJson() => <String, dynamic>{
'type': type,
'file': file,
'line': line,
'col': col,
'error': error,
};
factory AnalyzerOutput.fromJson(Map<String, dynamic> json) =>
_$AnalyzerOutputFromJson(json);

@override
int compareTo(AnalyzerOutput other) {
Expand Down
30 changes: 30 additions & 0 deletions lib/src/analyzer_output.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions lib/src/platform.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
library pana.platform;

import 'package:source_gen/generators/json_serializable.dart';

import 'pubspec.dart';

part 'platform.g.dart';

abstract class KnownPlatforms {
static const String browser = 'browser';
static const String console = 'console';
Expand All @@ -25,18 +31,17 @@ class PlatformSummary {
libraries.values.any((p) => !p.worksInFlutter);
}

class Platform {
@JsonSerializable()
class Platform extends Object with _$PlatformSerializerMixin {
final List<String> uses;

Platform._(this.uses);

factory Platform(Iterable<String> uses) =>
new Platform._((uses ?? []).toList()..sort());

factory Platform.fromJson(Map<String, dynamic> map) {
map ??= {};
return new Platform(map['uses']);
}
factory Platform.fromJson(Map<String, dynamic> map) =>
_$PlatformFromJson(map);

bool get hasConflict =>
(!worksAnywhere) ||
Expand All @@ -60,10 +65,6 @@ class Platform {

bool _hasNoUseOf(Iterable<String> platforms) =>
!platforms.any((p) => uses.contains(p));

Map<String, dynamic> toJson() => <String, dynamic>{
'uses': uses,
};
}

Platform classifyPubspec(Pubspec pubspec) {
Expand Down
16 changes: 16 additions & 0 deletions lib/src/platform.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/src/pub_summary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library pana.pub_summary;

import 'dart:collection';
import 'dart:convert';
import 'dart:io' hide exitCode;
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pana
description: Evaluate the health and quality of a Dart package
version: 0.2.3
version: 0.2.4-dev
homepage: https://github.com/dart-lang/pana
author: Dart Team <[email protected]>

Expand All @@ -16,7 +16,9 @@ dependencies:
pool: ^1.3.0
pub_semver: ^1.3.2
quiver: '>=0.24.0 <0.26.0'
source_gen: ^0.5.8
yaml: ^2.1.12

dev_dependencies:
build_runner: ^0.3.4
test: ^0.12.0
4 changes: 0 additions & 4 deletions tool/README.md

This file was deleted.

10 changes: 10 additions & 0 deletions tool/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:build_runner/build_runner.dart';

import 'phases.dart';

main() async {
await build(phases, deleteFilesByDefault: true);
}
15 changes: 15 additions & 0 deletions tool/phases.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:build_runner/build_runner.dart';

import 'package:source_gen/generators/json_serializable_generator.dart' as json;
import 'package:source_gen/source_gen.dart';

final PhaseGroup phases = new PhaseGroup.singleAction(
new GeneratorBuilder(const [const json.JsonSerializableGenerator()]),
new InputSet('pana', const [
'lib/src/analyzer_output.dart',
'lib/src/platform.dart',
'lib/src/pub_summary.dart'
]));
10 changes: 10 additions & 0 deletions tool/watch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:build_runner/build_runner.dart';

import 'phases.dart';

main() {
watch(phases, deleteFilesByDefault: true);
}

0 comments on commit 0553030

Please sign in to comment.