Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: reflectable/lib/transformer.dart

Issue 1448333004: Checks for entry point existence and supports warning suppression. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in 2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file. 3 // the LICENSE file.
4 4
5 library reflectable.transformer; 5 library reflectable.transformer;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:logging/logging.dart'; 10 import 'package:logging/logging.dart';
11 import 'src/transformer_implementation.dart' as implementation; 11 import 'src/transformer_implementation.dart' as implementation;
12 12
13 class ReflectableTransformer extends AggregateTransformer 13 class ReflectableTransformer extends AggregateTransformer
14 implements DeclaringAggregateTransformer { 14 implements DeclaringAggregateTransformer {
15 BarbackSettings _settings; 15 BarbackSettings _settings;
16 List<String> _entryPoints = <String>[]; 16 List<String> _entryPoints = <String>[];
17 bool _formatted; 17 bool _formatted;
18 List<implementation.WarningKind> _suppressWarnings =
19 <implementation.WarningKind>[];
18 20
19 /// Reports an error in a situation where we do not yet have 21 /// Reports an error in a situation where we do not yet have
20 /// a [Logger]. 22 /// a [Logger].
21 void _reportEarlyError(String message) { 23 void _reportEarlyError(String message) {
22 print("Error(Reflectable): $message."); 24 print("Error(Reflectable): $message.");
23 exit(-1); 25 exit(-1);
24 } 26 }
25 27
26 /// Reports an info message in a situation where we do not yet have 28 /// Reports an info message in a situation where we do not yet have
27 /// a [Logger]. 29 /// a [Logger].
(...skipping 29 matching lines...) Expand all
57 if (formattedSettings == null) { 59 if (formattedSettings == null) {
58 return false; 60 return false;
59 } else if (formattedSettings is! bool) { 61 } else if (formattedSettings is! bool) {
60 _reportEarlyError("Encountered non-bool value for 'formatted' option."); 62 _reportEarlyError("Encountered non-bool value for 'formatted' option.");
61 return false; 63 return false;
62 } else { 64 } else {
63 return formattedSettings; 65 return formattedSettings;
64 } 66 }
65 } 67 }
66 68
69 List<implementation.WarningKind> _findSuppressWarnings(
70 suppressWarningsSettings) {
71 Iterable<implementation.WarningKind> helper(setting) sync* {
72 // With no settings, no warnings are suppressed; same for `false`.
73 if (setting == null || setting == false) return;
74 // Setting `true` means suppress them all.
75 if (setting == true) {
76 yield implementation.WarningKind.allWarnings;
77 } else if (suppressWarningsSettings == "missingEntryPoint") {
78 yield implementation.WarningKind.missingEntryPoint;
79 } else if (suppressWarningsSettings == "badSuperclass") {
80 yield implementation.WarningKind.badSuperclass;
81 } else if (suppressWarningsSettings == "badNamePattern") {
82 yield implementation.WarningKind.badNamePattern;
83 } else if (suppressWarningsSettings == "badMetadata") {
84 yield implementation.WarningKind.badMetadata;
85 } else {
86 _reportEarlyError(
87 "Encountered unknown value for the 'suppressWarnings' option.\n"
88 "Accepted values: true, false, missingEntryPoint, "
89 "badSuperclass, badNamePattern, badMetadata.");
90 return;
91 }
92 }
93
94 List<implementation.WarningKind> result = <implementation.WarningKind>[];
95 if (suppressWarningsSettings is Iterable) {
96 suppressWarningsSettings
97 .forEach((setting) => helper(setting).forEach(result.add));
98 } else {
99 result.addAll(helper(suppressWarningsSettings));
100 }
101 return new List<implementation.WarningKind>.unmodifiable(result);
102 }
103
67 /// Creates new instance as required by Barback. 104 /// Creates new instance as required by Barback.
68 ReflectableTransformer.asPlugin(this._settings) { 105 ReflectableTransformer.asPlugin(this._settings) {
69 _entryPoints = _findEntryPoints(_settings.configuration['entry_points']); 106 _entryPoints = _findEntryPoints(_settings.configuration['entry_points']);
70 _formatted = _findFormatted(_settings.configuration['formatted']); 107 _formatted = _findFormatted(_settings.configuration['formatted']);
108 _suppressWarnings =
109 _findSuppressWarnings(_settings.configuration['suppressWarnings']);
71 } 110 }
72 111
73 /// Return a [String] or [Future<String>] valued key for each 112 /// Return a [String] or [Future<String>] valued key for each
74 /// primary asset that this transformer wishes to process, and 113 /// primary asset that this transformer wishes to process, and
75 /// null for assets that it wishes to ignore. Primary assets 114 /// null for assets that it wishes to ignore. Primary assets
76 /// with the same key are delivered to [apply] as a group. In 115 /// with the same key are delivered to [apply] as a group. In
77 /// this transformer we handle the grouping later, so everything 116 /// this transformer we handle the grouping later, so everything
78 /// is in the same group. 117 /// is in the same group.
79 String classifyPrimary(AssetId id) { 118 String classifyPrimary(AssetId id) {
80 return _entryPoints.any((entryPoint) => id.path.endsWith(entryPoint)) 119 return _entryPoints.any((entryPoint) => id.path.endsWith(entryPoint))
81 ? "ReflectableTransformed" 120 ? "ReflectableTransformed"
82 : null; 121 : null;
83 } 122 }
84 123
85 /// Performs the transformation. 124 /// Performs the transformation.
86 @override 125 @override
87 Future apply(AggregateTransform transform) { 126 Future apply(AggregateTransform transform) {
88 return new implementation.TransformerImplementation() 127 return new implementation.TransformerImplementation()
89 .apply(transform, _entryPoints, _formatted); 128 .apply(transform, _entryPoints, _formatted, _suppressWarnings);
90 } 129 }
91 130
92 @override 131 @override
93 declareOutputs(DeclaringAggregateTransform transform) async { 132 declareOutputs(DeclaringAggregateTransform transform) async {
94 List<AssetId> ids = await transform.primaryIds.toList(); 133 List<AssetId> ids = await transform.primaryIds.toList();
95 _entryPoints.forEach((String entryPoint) { 134 _entryPoints.forEach((String entryPoint) {
96 AssetId id = ids.firstWhere((AssetId id) => id.path.endsWith(entryPoint), 135 AssetId id = ids.firstWhere((AssetId id) => id.path.endsWith(entryPoint),
97 orElse: () => null); 136 orElse: () => null);
98 if (id == null) { 137 if (id == null) {
99 // There is no such entry point; however, we do not need to emit 138 // There is no such entry point; however, we do not need to emit
100 // any diagnostic messages, this is done by `apply` in 139 // any diagnostic messages, this is done by `apply` in
101 // `TransformerImplementation`. 140 // `TransformerImplementation`.
102 return; 141 return;
103 } 142 }
104 transform.declareOutput(id); 143 transform.declareOutput(id);
105 AssetId dataId = id.changeExtension("_reflectable_original_main.dart"); 144 AssetId dataId = id.changeExtension("_reflectable_original_main.dart");
106 transform.declareOutput(dataId); 145 transform.declareOutput(dataId);
107 }); 146 });
108 } 147 }
109 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698