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

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 11363007: Properties added to MethodMirror (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/dartdoc/lib/mirrors.dart ('k') | tests/compiler/dart2js/mirrors_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_dart2js; 5 library mirrors_dart2js;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 MethodMirror _convertElementMethodToMethodMirror(Dart2JsContainerMirror library, 105 MethodMirror _convertElementMethodToMethodMirror(Dart2JsContainerMirror library,
106 Element element) { 106 Element element) {
107 if (element is FunctionElement) { 107 if (element is FunctionElement) {
108 return new Dart2JsMethodMirror(library, element); 108 return new Dart2JsMethodMirror(library, element);
109 } else { 109 } else {
110 return null; 110 return null;
111 } 111 }
112 } 112 }
113 113
114 class Dart2JsMethodKind { 114 class Dart2JsMethodKind {
115 static const Dart2JsMethodKind NORMAL = const Dart2JsMethodKind("normal"); 115 static const Dart2JsMethodKind REGULAR = const Dart2JsMethodKind("regular");
116 static const Dart2JsMethodKind CONSTRUCTOR 116 static const Dart2JsMethodKind GENERATIVE
117 = const Dart2JsMethodKind("constructor"); 117 = const Dart2JsMethodKind("generative");
kasperl 2012/10/31 13:35:47 Nit: I'd prefer keeping = on the previous line --
Johnni Winther 2012/10/31 13:49:02 Done.
118 static const Dart2JsMethodKind REDIRECTING
119 = const Dart2JsMethodKind("redirecting");
118 static const Dart2JsMethodKind CONST = const Dart2JsMethodKind("const"); 120 static const Dart2JsMethodKind CONST = const Dart2JsMethodKind("const");
119 static const Dart2JsMethodKind FACTORY = const Dart2JsMethodKind("factory"); 121 static const Dart2JsMethodKind FACTORY = const Dart2JsMethodKind("factory");
120 static const Dart2JsMethodKind GETTER = const Dart2JsMethodKind("getter"); 122 static const Dart2JsMethodKind GETTER = const Dart2JsMethodKind("getter");
121 static const Dart2JsMethodKind SETTER = const Dart2JsMethodKind("setter"); 123 static const Dart2JsMethodKind SETTER = const Dart2JsMethodKind("setter");
122 static const Dart2JsMethodKind OPERATOR = const Dart2JsMethodKind("operator"); 124 static const Dart2JsMethodKind OPERATOR = const Dart2JsMethodKind("operator");
123 125
124 final String text; 126 final String text;
125 127
126 const Dart2JsMethodKind(this.text); 128 const Dart2JsMethodKind(this.text);
127 129
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 super(objectMirror.mirrors, function) { 1317 super(objectMirror.mirrors, function) {
1316 _simpleName = _element.name.slowToString(); 1318 _simpleName = _element.name.slowToString();
1317 if (_function.kind == ElementKind.GETTER) { 1319 if (_function.kind == ElementKind.GETTER) {
1318 _kind = Dart2JsMethodKind.GETTER; 1320 _kind = Dart2JsMethodKind.GETTER;
1319 _displayName = _simpleName; 1321 _displayName = _simpleName;
1320 } else if (_function.kind == ElementKind.SETTER) { 1322 } else if (_function.kind == ElementKind.SETTER) {
1321 _kind = Dart2JsMethodKind.SETTER; 1323 _kind = Dart2JsMethodKind.SETTER;
1322 _displayName = _simpleName; 1324 _displayName = _simpleName;
1323 _simpleName = '$_simpleName='; 1325 _simpleName = '$_simpleName=';
1324 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 1326 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
1327 // TODO(johnniwinther): Support detection of redirecting constructors.
1325 _constructorName = ''; 1328 _constructorName = '';
1326 int dollarPos = _simpleName.indexOf('\$'); 1329 int dollarPos = _simpleName.indexOf('\$');
1327 if (dollarPos != -1) { 1330 if (dollarPos != -1) {
1328 _constructorName = _simpleName.substring(dollarPos + 1); 1331 _constructorName = _simpleName.substring(dollarPos + 1);
1329 _simpleName = _simpleName.substring(0, dollarPos); 1332 _simpleName = _simpleName.substring(0, dollarPos);
1330 // Simple name is TypeName.constructorName. 1333 // Simple name is TypeName.constructorName.
1331 _simpleName = '$_simpleName.$_constructorName'; 1334 _simpleName = '$_simpleName.$_constructorName';
1332 } else { 1335 } else {
1333 // Simple name is TypeName. 1336 // Simple name is TypeName.
1334 } 1337 }
1335 if (_function.modifiers.isConst()) { 1338 if (_function.modifiers.isConst()) {
1336 _kind = Dart2JsMethodKind.CONST; 1339 _kind = Dart2JsMethodKind.CONST;
1337 } else { 1340 } else {
1338 _kind = Dart2JsMethodKind.CONSTRUCTOR; 1341 _kind = Dart2JsMethodKind.GENERATIVE;
1339 } 1342 }
1340 _displayName = _simpleName; 1343 _displayName = _simpleName;
1341 } else if (_function.modifiers.isFactory()) { 1344 } else if (_function.modifiers.isFactory()) {
1342 _kind = Dart2JsMethodKind.FACTORY; 1345 _kind = Dart2JsMethodKind.FACTORY;
1343 _constructorName = ''; 1346 _constructorName = '';
1344 int dollarPos = _simpleName.indexOf('\$'); 1347 int dollarPos = _simpleName.indexOf('\$');
1345 if (dollarPos != -1) { 1348 if (dollarPos != -1) {
1346 _constructorName = _simpleName.substring(dollarPos+1); 1349 _constructorName = _simpleName.substring(dollarPos+1);
1347 _simpleName = _simpleName.substring(0, dollarPos); 1350 _simpleName = _simpleName.substring(0, dollarPos);
1348 _simpleName = '$_simpleName.$_constructorName'; 1351 _simpleName = '$_simpleName.$_constructorName';
(...skipping 10 matching lines...) Expand all
1359 } else if (_simpleName.startsWith('operator\$')) { 1362 } else if (_simpleName.startsWith('operator\$')) {
1360 String str = _simpleName.substring(9); 1363 String str = _simpleName.substring(9);
1361 _simpleName = 'operator'; 1364 _simpleName = 'operator';
1362 _kind = Dart2JsMethodKind.OPERATOR; 1365 _kind = Dart2JsMethodKind.OPERATOR;
1363 _operatorName = _getOperatorFromOperatorName(str); 1366 _operatorName = _getOperatorFromOperatorName(str);
1364 // Simple name is 'operator operatorName'. 1367 // Simple name is 'operator operatorName'.
1365 _simpleName = _operatorName; 1368 _simpleName = _operatorName;
1366 // Display name is 'operator operatorName'. 1369 // Display name is 'operator operatorName'.
1367 _displayName = 'operator $_operatorName'; 1370 _displayName = 'operator $_operatorName';
1368 } else { 1371 } else {
1369 _kind = Dart2JsMethodKind.NORMAL; 1372 _kind = Dart2JsMethodKind.REGULAR;
1370 _displayName = _simpleName; 1373 _displayName = _simpleName;
1371 } 1374 }
1372 } 1375 }
1373 1376
1374 FunctionElement get _function => _element; 1377 FunctionElement get _function => _element;
1375 1378
1376 String get simpleName => _simpleName; 1379 String get simpleName => _simpleName;
1377 1380
1378 String get displayName => _displayName; 1381 String get displayName => _displayName;
1379 1382
1380 String get qualifiedName 1383 String get qualifiedName
1381 => '${owner.qualifiedName}.$simpleName'; 1384 => '${owner.qualifiedName}.$simpleName';
1382 1385
1383 DeclarationMirror get owner => _objectMirror; 1386 DeclarationMirror get owner => _objectMirror;
1384 1387
1385 bool get isTopLevel => _objectMirror is LibraryMirror; 1388 bool get isTopLevel => _objectMirror is LibraryMirror;
1386 1389
1387 bool get isConstructor 1390 bool get isConstructor
1388 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory; 1391 => isGenerativeConstructor || isConstConstructor ||
1392 isFactoryConstructor || isRedirectingConstructor;
1389 1393
1390 bool get isMethod => !isConstructor; 1394 bool get isMethod => !isConstructor;
1391 1395
1392 bool get isPrivate => 1396 bool get isPrivate =>
1393 isConstructor ? _isPrivate(constructorName) : _isPrivate(simpleName); 1397 isConstructor ? _isPrivate(constructorName) : _isPrivate(simpleName);
1394 1398
1395 bool get isStatic => _function.modifiers.isStatic(); 1399 bool get isStatic => _function.modifiers.isStatic();
1396 1400
1397 List<ParameterMirror> get parameters { 1401 List<ParameterMirror> get parameters {
1398 return _parametersFromFunctionSignature(mirrors, this, 1402 return _parametersFromFunctionSignature(mirrors, this,
1399 _function.computeSignature(mirrors.compiler)); 1403 _function.computeSignature(mirrors.compiler));
1400 } 1404 }
1401 1405
1402 TypeMirror get returnType => _convertTypeToTypeMirror( 1406 TypeMirror get returnType => _convertTypeToTypeMirror(
1403 mirrors, _function.computeSignature(mirrors.compiler).returnType, 1407 mirrors, _function.computeSignature(mirrors.compiler).returnType,
1404 mirrors.compiler.types.dynamicType); 1408 mirrors.compiler.types.dynamicType);
1405 1409
1406 bool get isAbstract => _function.modifiers.isAbstract(); 1410 bool get isAbstract => _function.isAbstract(mirrors.compiler);
1407 1411
1408 bool get isConst => _kind == Dart2JsMethodKind.CONST; 1412 bool get isRegularMethod => !(isGetter || isSetter || isConstructor);
1409 1413
1410 bool get isFactory => _kind == Dart2JsMethodKind.FACTORY; 1414 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST;
1415
1416 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE;
1417
1418 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING;
1419
1420 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY;
1411 1421
1412 String get constructorName => _constructorName; 1422 String get constructorName => _constructorName;
1413 1423
1414 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; 1424 bool get isGetter => _kind == Dart2JsMethodKind.GETTER;
1415 1425
1416 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; 1426 bool get isSetter => _kind == Dart2JsMethodKind.SETTER;
1417 1427
1418 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; 1428 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR;
1419 1429
1420 String get operatorName => _operatorName; 1430 String get operatorName => _operatorName;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 if (node !== null) { 1476 if (node !== null) {
1467 var span = mirrors.compiler.spanFromNode(node, script.uri); 1477 var span = mirrors.compiler.spanFromNode(node, script.uri);
1468 return new Dart2JsLocation(script, span); 1478 return new Dart2JsLocation(script, span);
1469 } else { 1479 } else {
1470 var span = mirrors.compiler.spanFromElement(_variable); 1480 var span = mirrors.compiler.spanFromElement(_variable);
1471 return new Dart2JsLocation(script, span); 1481 return new Dart2JsLocation(script, span);
1472 } 1482 }
1473 } 1483 }
1474 } 1484 }
1475 1485
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/mirrors.dart ('k') | tests/compiler/dart2js/mirrors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698