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

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: Review response; eliminated "allWarnings". Landing now. 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 void fail(setting) {
72 _reportEarlyError("Encountered unknown value '$setting' for"
73 " the 'suppressWarnings' option.\n"
74 "Accepted values: true, false, missingEntryPoint, "
75 "badSuperclass, badNamePattern, badMetadata");
76 }
77
78 Iterable<implementation.WarningKind> helper(setting) sync* {
79 // With no settings, no warnings are suppressed; same for `false`.
80 if (setting == null || setting == false) return;
81 // Setting `true` means suppress them all.
82 if (setting == true) {
83 yield* implementation.WarningKind.values;
84 } else if (setting is String) {
85 switch (setting) {
86 case "missingEntryPoint":
87 yield implementation.WarningKind.missingEntryPoint;
88 break;
89 case "badSuperclass":
90 yield implementation.WarningKind.badSuperclass;
91 break;
92 case "badNamePattern":
93 yield implementation.WarningKind.badNamePattern;
94 break;
95 case "badMetadata":
96 yield implementation.WarningKind.badMetadata;
97 break;
98 default:
99 fail(setting);
100 return;
101 }
102 } else {
103 fail(setting);
104 return;
105 }
106 }
107
108 List<implementation.WarningKind> result = <implementation.WarningKind>[];
109 if (suppressWarningsSettings is Iterable) {
110 suppressWarningsSettings
111 .forEach((setting) => helper(setting).forEach(result.add));
112 } else {
113 result.addAll(helper(suppressWarningsSettings));
114 }
115 return new List<implementation.WarningKind>.unmodifiable(result);
116 }
117
67 /// Creates new instance as required by Barback. 118 /// Creates new instance as required by Barback.
68 ReflectableTransformer.asPlugin(this._settings) { 119 ReflectableTransformer.asPlugin(this._settings) {
69 _entryPoints = _findEntryPoints(_settings.configuration['entry_points']); 120 _entryPoints = _findEntryPoints(_settings.configuration['entry_points']);
70 _formatted = _findFormatted(_settings.configuration['formatted']); 121 _formatted = _findFormatted(_settings.configuration['formatted']);
122 _suppressWarnings =
123 _findSuppressWarnings(_settings.configuration['suppressWarnings']);
71 } 124 }
72 125
73 /// Return a [String] or [Future<String>] valued key for each 126 /// Return a [String] or [Future<String>] valued key for each
74 /// primary asset that this transformer wishes to process, and 127 /// primary asset that this transformer wishes to process, and
75 /// null for assets that it wishes to ignore. Primary assets 128 /// null for assets that it wishes to ignore. Primary assets
76 /// with the same key are delivered to [apply] as a group. In 129 /// with the same key are delivered to [apply] as a group. In
77 /// this transformer we handle the grouping later, so everything 130 /// this transformer we handle the grouping later, so everything
78 /// is in the same group. 131 /// is in the same group.
79 String classifyPrimary(AssetId id) { 132 String classifyPrimary(AssetId id) {
80 return _entryPoints.any((entryPoint) => id.path.endsWith(entryPoint)) 133 return _entryPoints.any((entryPoint) => id.path.endsWith(entryPoint))
81 ? "ReflectableTransformed" 134 ? "ReflectableTransformed"
82 : null; 135 : null;
83 } 136 }
84 137
85 /// Performs the transformation. 138 /// Performs the transformation.
86 @override 139 @override
87 Future apply(AggregateTransform transform) { 140 Future apply(AggregateTransform transform) {
88 return new implementation.TransformerImplementation() 141 return new implementation.TransformerImplementation()
89 .apply(transform, _entryPoints, _formatted); 142 .apply(transform, _entryPoints, _formatted, _suppressWarnings);
90 } 143 }
91 144
92 @override 145 @override
93 declareOutputs(DeclaringAggregateTransform transform) async { 146 declareOutputs(DeclaringAggregateTransform transform) async {
94 List<AssetId> ids = await transform.primaryIds.toList(); 147 List<AssetId> ids = await transform.primaryIds.toList();
95 _entryPoints.forEach((String entryPoint) { 148 _entryPoints.forEach((String entryPoint) {
96 AssetId id = ids.firstWhere((AssetId id) => id.path.endsWith(entryPoint), 149 AssetId id = ids.firstWhere((AssetId id) => id.path.endsWith(entryPoint),
97 orElse: () => null); 150 orElse: () => null);
98 if (id == null) { 151 if (id == null) {
99 // There is no such entry point; however, we do not need to emit 152 // There is no such entry point; however, we do not need to emit
100 // any diagnostic messages, this is done by `apply` in 153 // any diagnostic messages, this is done by `apply` in
101 // `TransformerImplementation`. 154 // `TransformerImplementation`.
102 return; 155 return;
103 } 156 }
104 transform.declareOutput(id); 157 transform.declareOutput(id);
105 AssetId dataId = id.changeExtension("_reflectable_original_main.dart"); 158 AssetId dataId = id.changeExtension("_reflectable_original_main.dart");
106 transform.declareOutput(dataId); 159 transform.declareOutput(dataId);
107 }); 160 });
108 } 161 }
109 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698