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

Side by Side Diff: pkg/analyzer/example/resolver_driver.dart

Issue 1131423002: Clean up many generated constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comment change Created 5 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/java_io.dart'; 11 import 'package:analyzer/src/generated/java_io.dart';
12 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 12 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 13 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
14 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
15 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
16 16
17 const _usage =
18 'Usage: resolve_driver <path_to_sdk> <file_to_resolve> [<packages_root>]';
19
20 void main(List<String> args) { 17 void main(List<String> args) {
21 print('working dir ${new File('.').resolveSymbolicLinksSync()}'); 18 print('working dir ${new File('.').resolveSymbolicLinksSync()}');
22 19
23 if (args.length < 2 || args.length > 3) { 20 if (args.length < 2 || args.length > 3) {
24 print(_usage); 21 print(_usage);
25 exit(0); 22 exit(0);
26 } 23 }
27 24
28 String packageRoot; 25 String packageRoot;
29 if (args.length == 3) { 26 if (args.length == 3) {
30 packageRoot = args[2]; 27 packageRoot = args[2];
31 } 28 }
32 29
33 JavaSystemIO.setProperty("com.google.dart.sdk", args[0]); 30 JavaSystemIO.setProperty("com.google.dart.sdk", args[0]);
34 DartSdk sdk = DirectoryBasedDartSdk.defaultSdk; 31 DartSdk sdk = DirectoryBasedDartSdk.defaultSdk;
35 32
36 var resolvers = [new DartUriResolver(sdk), new FileUriResolver()]; 33 var resolvers = [new DartUriResolver(sdk), new FileUriResolver()];
37 34
38 if (packageRoot != null) { 35 if (packageRoot != null) {
39 var packageDirectory = new JavaFile(packageRoot); 36 var packageDirectory = new JavaFile(packageRoot);
40 resolvers.add(new PackageUriResolver([packageDirectory])); 37 resolvers.add(new PackageUriResolver([packageDirectory]));
41 } 38 }
42 39
43 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext() 40 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext()
44 ..sourceFactory = new SourceFactory(resolvers); 41 ..sourceFactory = new SourceFactory(resolvers);
45 42
46 Source source = new FileBasedSource.con1(new JavaFile(args[1])); 43 Source source = new FileBasedSource(new JavaFile(args[1]));
47 ChangeSet changeSet = new ChangeSet()..addedSource(source); 44 ChangeSet changeSet = new ChangeSet()..addedSource(source);
48 context.applyChanges(changeSet); 45 context.applyChanges(changeSet);
49 LibraryElement libElement = context.computeLibraryElement(source); 46 LibraryElement libElement = context.computeLibraryElement(source);
50 print("libElement: $libElement"); 47 print("libElement: $libElement");
51 48
52 CompilationUnit resolvedUnit = 49 CompilationUnit resolvedUnit =
53 context.resolveCompilationUnit(source, libElement); 50 context.resolveCompilationUnit(source, libElement);
54 var visitor = new _ASTVisitor(); 51 var visitor = new _ASTVisitor();
55 resolvedUnit.accept(visitor); 52 resolvedUnit.accept(visitor);
56 } 53 }
57 54
55 const _usage =
56 'Usage: resolve_driver <path_to_sdk> <file_to_resolve> [<packages_root>]';
57
58 class _ASTVisitor extends GeneralizingAstVisitor { 58 class _ASTVisitor extends GeneralizingAstVisitor {
59 visitNode(AstNode node) { 59 visitNode(AstNode node) {
60 var lines = <String>['${node.runtimeType} : <"$node">']; 60 var lines = <String>['${node.runtimeType} : <"$node">'];
61 if (node is SimpleIdentifier) { 61 if (node is SimpleIdentifier) {
62 Element element = node.staticElement; 62 Element element = node.staticElement;
63 if (element != null) { 63 if (element != null) {
64 lines.add(' element: ${element.runtimeType}'); 64 lines.add(' element: ${element.runtimeType}');
65 LibraryElement library = element.library; 65 LibraryElement library = element.library;
66 if (library != null) { 66 if (library != null) {
67 var fullName = 67 var fullName =
68 element.library.definingCompilationUnit.source.fullName; 68 element.library.definingCompilationUnit.source.fullName;
69 lines.add(" from $fullName"); 69 lines.add(" from $fullName");
70 } 70 }
71 } 71 }
72 } 72 }
73 print(lines.join('\n')); 73 print(lines.join('\n'));
74 return super.visitNode(node); 74 return super.visitNode(node);
75 } 75 }
76 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698