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

Side by Side Diff: lib/dartdoc/mirrors/mirrors_util.dart

Issue 10823257: Refactored accessors in mirrors from methods to properties. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('mirrors.util'); 5 #library('mirrors.util');
6 6
7 #import('mirrors.dart'); 7 #import('mirrors.dart');
8 #import('../../compiler/implementation/util/characters.dart'); 8 #import('../../compiler/implementation/util/characters.dart');
9 9
10 //------------------------------------------------------------------------------ 10 //------------------------------------------------------------------------------
11 // Utility functions for using the Mirror API 11 // Utility functions for using the Mirror API
12 //------------------------------------------------------------------------------ 12 //------------------------------------------------------------------------------
13 13
14 /** 14 /**
15 * Returns an iterable over the type declarations directly inheriting from 15 * Returns an iterable over the type declarations directly inheriting from
16 * the declaration of this type. 16 * the declaration of this type.
17 */ 17 */
18 Iterable<InterfaceMirror> computeSubdeclarations(InterfaceMirror type) { 18 Iterable<InterfaceMirror> computeSubdeclarations(InterfaceMirror type) {
19 type = type.declaration; 19 type = type.declaration;
20 var subtypes = <InterfaceMirror>[]; 20 var subtypes = <InterfaceMirror>[];
21 type.system.libraries().forEach((_, library) { 21 type.system.libraries.forEach((_, library) {
22 for (InterfaceMirror otherType in library.types().getValues()) { 22 for (InterfaceMirror otherType in library.types.getValues()) {
23 var superClass = otherType.superclass(); 23 var superClass = otherType.superclass;
24 if (superClass !== null) { 24 if (superClass !== null) {
25 superClass = superClass.declaration; 25 superClass = superClass.declaration;
26 if (type.library() === superClass.library()) { 26 if (type.library === superClass.library) {
27 if (superClass == type) { 27 if (superClass == type) {
28 subtypes.add(otherType); 28 subtypes.add(otherType);
29 } 29 }
30 } 30 }
31 } 31 }
32 final superInterfaces = otherType.interfaces().getValues(); 32 final superInterfaces = otherType.interfaces.getValues();
33 for (InterfaceMirror superInterface in superInterfaces) { 33 for (InterfaceMirror superInterface in superInterfaces) {
34 superInterface = superInterface.declaration; 34 superInterface = superInterface.declaration;
35 if (type.library() === superInterface.library()) { 35 if (type.library === superInterface.library) {
36 if (superInterface == type) { 36 if (superInterface == type) {
37 subtypes.add(otherType); 37 subtypes.add(otherType);
38 } 38 }
39 } 39 }
40 } 40 }
41 } 41 }
42 }); 42 });
43 return subtypes; 43 return subtypes;
44 } 44 }
45 45
46 /** 46 /**
47 * Finds the mirror in [map] by the simple name [name]. If [constructorName] or 47 * Finds the mirror in [map] by the simple name [name]. If [constructorName] or
48 * [operatorName] is provided, a constructor/operator method by that name is 48 * [operatorName] is provided, a constructor/operator method by that name is
49 * returned. 49 * returned.
50 */ 50 */
51 Mirror findMirror(Map<Object,Mirror> map, String name, 51 Mirror findMirror(Map<Object,Mirror> map, String name,
52 [String constructorName, String operatorName]) { 52 [String constructorName, String operatorName]) {
53 var foundMirror = null; 53 var foundMirror = null;
54 map.forEach((_, Mirror mirror) { 54 map.forEach((_, Mirror mirror) {
55 if (mirror.simpleName() == name) { 55 if (mirror.simpleName == name) {
56 if (constructorName !== null) { 56 if (constructorName !== null) {
57 if (mirror is MethodMirror && 57 if (mirror is MethodMirror &&
58 constructorName == mirror.constructorName) { 58 constructorName == mirror.constructorName) {
59 foundMirror = mirror; 59 foundMirror = mirror;
60 } 60 }
61 } else if (operatorName !== null) { 61 } else if (operatorName !== null) {
62 if (mirror is MethodMirror && 62 if (mirror is MethodMirror &&
63 operatorName == mirror.operatorName) { 63 operatorName == mirror.operatorName) {
64 foundMirror = mirror; 64 foundMirror = mirror;
65 } 65 }
66 } else { 66 } else {
67 foundMirror = mirror; 67 foundMirror = mirror;
68 } 68 }
69 } 69 }
70 }); 70 });
71 return foundMirror; 71 return foundMirror;
72 } 72 }
73 73
74 LibraryMirror findLibrary(MemberMirror member) { 74 LibraryMirror findLibrary(MemberMirror member) {
75 ObjectMirror owner = member.surroundingDeclaration(); 75 ObjectMirror owner = member.surroundingDeclaration;
76 if (owner is LibraryMirror) { 76 if (owner is LibraryMirror) {
77 return owner; 77 return owner;
78 } else if (owner is TypeMirror) { 78 } else if (owner is TypeMirror) {
79 return owner.library(); 79 return owner.library();
80 } 80 }
81 throw new Exception('Unexpected owner: ${owner}'); 81 throw new Exception('Unexpected owner: ${owner}');
82 } 82 }
83 83
84 84
85 /** 85 /**
86 * Returns the column of the start of a location. 86 * Returns the column of the start of a location.
87 */ 87 */
88 int getLocationColumn(Location location) { 88 int getLocationColumn(Location location) {
89 String text = location.source().text(); 89 String text = location.source.text;
90 int index = location.start()-1; 90 int index = location.start-1;
91 var column = 0; 91 var column = 0;
92 while (0 <= index && index < text.length) { 92 while (0 <= index && index < text.length) {
93 var charCode = text.charCodeAt(index); 93 var charCode = text.charCodeAt(index);
94 if (charCode == $CR || charCode == $LF) { 94 if (charCode == $CR || charCode == $LF) {
95 break; 95 break;
96 } 96 }
97 index--; 97 index--;
98 column++; 98 column++;
99 } 99 }
100 return column; 100 return column;
101 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698