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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 11361123: Change Dart2JsMethodMirror constructor to factory (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 | « no previous file | no next file » | 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 '../../compiler.dart' as diagnostics; 10 import '../../compiler.dart' as diagnostics;
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 } 1346 }
1347 } 1347 }
1348 1348
1349 //------------------------------------------------------------------------------ 1349 //------------------------------------------------------------------------------
1350 // Member mirrors implementation. 1350 // Member mirrors implementation.
1351 //------------------------------------------------------------------------------ 1351 //------------------------------------------------------------------------------
1352 1352
1353 class Dart2JsMethodMirror extends Dart2JsMemberMirror 1353 class Dart2JsMethodMirror extends Dart2JsMemberMirror
1354 implements MethodMirror { 1354 implements MethodMirror {
1355 final Dart2JsContainerMirror _objectMirror; 1355 final Dart2JsContainerMirror _objectMirror;
1356 String _simpleName; 1356 final String simpleName;
1357 String _displayName; 1357 final String displayName;
1358 String _constructorName; 1358 final String constructorName;
1359 String _operatorName; 1359 final String operatorName;
1360 Dart2JsMethodKind _kind; 1360 final Dart2JsMethodKind _kind;
1361 1361
1362 Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror, 1362 Dart2JsMethodMirror._internal(Dart2JsContainerMirror objectMirror,
1363 FunctionElement function) 1363 FunctionElement function,
1364 String this.simpleName,
1365 String this.displayName,
1366 String this.constructorName,
1367 String this.operatorName,
1368 Dart2JsMethodKind this._kind)
1364 : this._objectMirror = objectMirror, 1369 : this._objectMirror = objectMirror,
1365 super(objectMirror.mirrors, function) { 1370 super(objectMirror.mirrors, function);
1366 _simpleName = _element.name.slowToString(); 1371
1367 if (_function.kind == ElementKind.GETTER) { 1372 factory Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror,
1368 _kind = Dart2JsMethodKind.GETTER; 1373 FunctionElement function) {
1369 _displayName = _simpleName; 1374 String simpleName = function.name.slowToString();
1370 } else if (_function.kind == ElementKind.SETTER) { 1375 String displayName;
1371 _kind = Dart2JsMethodKind.SETTER; 1376 String constructorName = null;
1372 _displayName = _simpleName; 1377 String operatorName = null;
1373 _simpleName = '$_simpleName='; 1378 Dart2JsMethodKind kind;
1374 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 1379 if (function.kind == ElementKind.GETTER) {
1380 kind = Dart2JsMethodKind.GETTER;
1381 displayName = simpleName;
1382 } else if (function.kind == ElementKind.SETTER) {
1383 kind = Dart2JsMethodKind.SETTER;
1384 displayName = simpleName;
1385 simpleName = '$simpleName=';
1386 } else if (function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
1375 // TODO(johnniwinther): Support detection of redirecting constructors. 1387 // TODO(johnniwinther): Support detection of redirecting constructors.
1376 _constructorName = ''; 1388 constructorName = '';
1377 int dollarPos = _simpleName.indexOf('\$'); 1389 int dollarPos = simpleName.indexOf('\$');
1378 if (dollarPos != -1) { 1390 if (dollarPos != -1) {
1379 _constructorName = _simpleName.substring(dollarPos + 1); 1391 constructorName = simpleName.substring(dollarPos + 1);
1380 _simpleName = _simpleName.substring(0, dollarPos); 1392 simpleName = simpleName.substring(0, dollarPos);
1381 // Simple name is TypeName.constructorName. 1393 // Simple name is TypeName.constructorName.
1382 _simpleName = '$_simpleName.$_constructorName'; 1394 simpleName = '$simpleName.$constructorName';
1383 } else { 1395 } else {
1384 // Simple name is TypeName. 1396 // Simple name is TypeName.
1385 } 1397 }
1386 if (_function.modifiers.isConst()) { 1398 if (function.modifiers.isConst()) {
1387 _kind = Dart2JsMethodKind.CONST; 1399 kind = Dart2JsMethodKind.CONST;
1388 } else { 1400 } else {
1389 _kind = Dart2JsMethodKind.GENERATIVE; 1401 kind = Dart2JsMethodKind.GENERATIVE;
1390 } 1402 }
1391 _displayName = _simpleName; 1403 displayName = simpleName;
1392 } else if (_function.modifiers.isFactory()) { 1404 } else if (function.modifiers.isFactory()) {
1393 _kind = Dart2JsMethodKind.FACTORY; 1405 kind = Dart2JsMethodKind.FACTORY;
1394 _constructorName = ''; 1406 constructorName = '';
1395 int dollarPos = _simpleName.indexOf('\$'); 1407 int dollarPos = simpleName.indexOf('\$');
1396 if (dollarPos != -1) { 1408 if (dollarPos != -1) {
1397 _constructorName = _simpleName.substring(dollarPos+1); 1409 constructorName = simpleName.substring(dollarPos+1);
1398 _simpleName = _simpleName.substring(0, dollarPos); 1410 simpleName = simpleName.substring(0, dollarPos);
1399 _simpleName = '$_simpleName.$_constructorName'; 1411 simpleName = '$simpleName.$constructorName';
1400 } 1412 }
1401 // Simple name is TypeName.constructorName. 1413 // Simple name is TypeName.constructorName.
1402 _displayName = _simpleName; 1414 displayName = simpleName;
1403 } else if (_simpleName == 'negate') { 1415 } else if (simpleName == 'negate') {
1404 _kind = Dart2JsMethodKind.OPERATOR; 1416 kind = Dart2JsMethodKind.OPERATOR;
1405 _operatorName = '-'; 1417 operatorName = '-';
1406 // Simple name is 'unary-'. 1418 // Simple name is 'unary-'.
1407 _simpleName = Mirror.UNARY_MINUS; 1419 simpleName = Mirror.UNARY_MINUS;
1408 // Display name is 'operator operatorName'. 1420 // Display name is 'operator operatorName'.
1409 _displayName = 'operator -'; 1421 displayName = 'operator -';
1410 } else if (_simpleName.startsWith('operator\$')) { 1422 } else if (simpleName.startsWith('operator\$')) {
1411 String str = _simpleName.substring(9); 1423 String str = simpleName.substring(9);
1412 _simpleName = 'operator'; 1424 simpleName = 'operator';
1413 _kind = Dart2JsMethodKind.OPERATOR; 1425 kind = Dart2JsMethodKind.OPERATOR;
1414 _operatorName = _getOperatorFromOperatorName(str); 1426 operatorName = _getOperatorFromOperatorName(str);
1415 // Simple name is 'operator operatorName'. 1427 // Simple name is 'operator operatorName'.
1416 _simpleName = _operatorName; 1428 simpleName = operatorName;
1417 // Display name is 'operator operatorName'. 1429 // Display name is 'operator operatorName'.
1418 _displayName = 'operator $_operatorName'; 1430 displayName = 'operator $operatorName';
1419 } else { 1431 } else {
1420 _kind = Dart2JsMethodKind.REGULAR; 1432 kind = Dart2JsMethodKind.REGULAR;
1421 _displayName = _simpleName; 1433 displayName = simpleName;
1422 } 1434 }
1435 return new Dart2JsMethodMirror._internal(objectMirror, function,
1436 simpleName, displayName, constructorName, operatorName, kind);
1423 } 1437 }
1424 1438
1425 FunctionElement get _function => _element; 1439 FunctionElement get _function => _element;
1426 1440
1427 String get simpleName => _simpleName;
1428
1429 String get displayName => _displayName;
1430
1431 String get qualifiedName 1441 String get qualifiedName
1432 => '${owner.qualifiedName}.$simpleName'; 1442 => '${owner.qualifiedName}.$simpleName';
1433 1443
1434 DeclarationMirror get owner => _objectMirror; 1444 DeclarationMirror get owner => _objectMirror;
1435 1445
1436 bool get isTopLevel => _objectMirror is LibraryMirror; 1446 bool get isTopLevel => _objectMirror is LibraryMirror;
1437 1447
1438 bool get isConstructor 1448 bool get isConstructor
1439 => isGenerativeConstructor || isConstConstructor || 1449 => isGenerativeConstructor || isConstConstructor ||
1440 isFactoryConstructor || isRedirectingConstructor; 1450 isFactoryConstructor || isRedirectingConstructor;
(...skipping 19 matching lines...) Expand all
1460 bool get isRegularMethod => !(isGetter || isSetter || isConstructor); 1470 bool get isRegularMethod => !(isGetter || isSetter || isConstructor);
1461 1471
1462 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST; 1472 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST;
1463 1473
1464 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE; 1474 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE;
1465 1475
1466 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING; 1476 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING;
1467 1477
1468 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY; 1478 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY;
1469 1479
1470 String get constructorName => _constructorName;
1471
1472 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; 1480 bool get isGetter => _kind == Dart2JsMethodKind.GETTER;
1473 1481
1474 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; 1482 bool get isSetter => _kind == Dart2JsMethodKind.SETTER;
1475 1483
1476 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; 1484 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR;
1477 1485
1478 String get operatorName => _operatorName;
1479
1480 SourceLocation get location { 1486 SourceLocation get location {
1481 var node = _function.parseNode(_diagnosticListener); 1487 var node = _function.parseNode(_diagnosticListener);
1482 if (node != null) { 1488 if (node != null) {
1483 var script = _function.getCompilationUnit().script; 1489 var script = _function.getCompilationUnit().script;
1484 var span = mirrors.compiler.spanFromNode(node, script.uri); 1490 var span = mirrors.compiler.spanFromNode(node, script.uri);
1485 return new Dart2JsSourceLocation(script, span); 1491 return new Dart2JsSourceLocation(script, span);
1486 } 1492 }
1487 return super.location; 1493 return super.location;
1488 } 1494 }
1489 1495
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 if (node != null) { 1530 if (node != null) {
1525 var span = mirrors.compiler.spanFromNode(node, script.uri); 1531 var span = mirrors.compiler.spanFromNode(node, script.uri);
1526 return new Dart2JsSourceLocation(script, span); 1532 return new Dart2JsSourceLocation(script, span);
1527 } else { 1533 } else {
1528 var span = mirrors.compiler.spanFromElement(_variable); 1534 var span = mirrors.compiler.spanFromElement(_variable);
1529 return new Dart2JsSourceLocation(script, span); 1535 return new Dart2JsSourceLocation(script, span);
1530 } 1536 }
1531 } 1537 }
1532 } 1538 }
1533 1539
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698