OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Simple script that shows the inferred types of a function. |
| 6 library compiler.tool.show_inferred_types; |
| 7 |
| 8 import 'dart:convert'; |
| 9 import 'dart:io'; |
| 10 |
| 11 import 'package:dart2js_info/info.dart'; |
| 12 import 'package:dart2js_info/src/util.dart'; |
| 13 |
| 14 main(args) { |
| 15 if (args.length < 2) { |
| 16 var scriptName = Platform.script.pathSegments.last; |
| 17 print('usage: dart $scriptName <info.json> <function-name-regex> [-l]'); |
| 18 print(' -l: print the long qualified name for a function.'); |
| 19 exit(1); |
| 20 } |
| 21 |
| 22 var showLongName = args.length > 2 && args[2] == '-l'; |
| 23 |
| 24 var json = JSON.decode(new File(args[0]).readAsStringSync()); |
| 25 var info = new AllInfoJsonCodec().decode(json); |
| 26 var nameRegExp = new RegExp(args[1]); |
| 27 matches(e) => nameRegExp.hasMatch(longName(e)); |
| 28 |
| 29 bool noResults = true; |
| 30 void showMethods() { |
| 31 var sources = info.functions.where(matches).toList(); |
| 32 if (sources.isEmpty) return; |
| 33 noResults = false; |
| 34 for (var s in sources) { |
| 35 var params = s.parameters.map((p) => '${p.name}: ${p.type}').join(', '); |
| 36 var name = showLongName ? longName(s) : s.name; |
| 37 print('$name($params): ${s.returnType}'); |
| 38 } |
| 39 } |
| 40 |
| 41 void showFields() { |
| 42 var sources = info.fields.where(matches).toList(); |
| 43 if (sources.isEmpty) return; |
| 44 noResults = false; |
| 45 for (var s in sources) { |
| 46 var name = showLongName ? longName(s) : s.name; |
| 47 print('$name: ${s.inferredType}'); |
| 48 } |
| 49 } |
| 50 |
| 51 showMethods(); |
| 52 showFields(); |
| 53 if (noResults) { |
| 54 print('error: no function or field that matches ${args[1]} was found.'); |
| 55 exit(1); |
| 56 } |
| 57 } |
| 58 |
OLD | NEW |