| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.mirrors_used; | 5 library dart2js.mirrors_used; |
| 6 | 6 |
| 7 import 'common/tasks.dart' show | 7 import 'common/tasks.dart' show |
| 8 CompilerTask; | 8 CompilerTask; |
| 9 import 'compile_time_constants.dart' show | 9 import 'compile_time_constants.dart' show |
| 10 ConstantCompiler; | 10 ConstantCompiler; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 StringConstantValue string = entry; | 402 StringConstantValue string = entry; |
| 403 result.add(string.primitiveValue.slowToString()); | 403 result.add(string.primitiveValue.slowToString()); |
| 404 } else if (!onlyStrings && entry.isType) { | 404 } else if (!onlyStrings && entry.isType) { |
| 405 TypeConstantValue type = entry; | 405 TypeConstantValue type = entry; |
| 406 result.add(type.representedType); | 406 result.add(type.representedType); |
| 407 } else { | 407 } else { |
| 408 Spannable node = positionOf(entry); | 408 Spannable node = positionOf(entry); |
| 409 MessageKind kind = onlyStrings | 409 MessageKind kind = onlyStrings |
| 410 ? MessageKind.MIRRORS_EXPECTED_STRING | 410 ? MessageKind.MIRRORS_EXPECTED_STRING |
| 411 : MessageKind.MIRRORS_EXPECTED_STRING_OR_TYPE; | 411 : MessageKind.MIRRORS_EXPECTED_STRING_OR_TYPE; |
| 412 compiler.reportHint( | 412 compiler.reportHintMessage( |
| 413 node, | 413 node, kind, {'name': node, 'type': apiTypeOf(entry)}); |
| 414 kind, {'name': node, 'type': apiTypeOf(entry)}); | |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 return result; | 416 return result; |
| 418 } else if (!onlyStrings && constant.isType) { | 417 } else if (!onlyStrings && constant.isType) { |
| 419 TypeConstantValue type = constant; | 418 TypeConstantValue type = constant; |
| 420 return [type.representedType]; | 419 return [type.representedType]; |
| 421 } else if (constant.isString) { | 420 } else if (constant.isString) { |
| 422 StringConstantValue string = constant; | 421 StringConstantValue string = constant; |
| 423 var iterable = | 422 var iterable = |
| 424 string.primitiveValue.slowToString().split(',').map((e) => e.trim()); | 423 string.primitiveValue.slowToString().split(',').map((e) => e.trim()); |
| 425 return onlyStrings ? new List<String>.from(iterable) : iterable.toList(); | 424 return onlyStrings ? new List<String>.from(iterable) : iterable.toList(); |
| 426 } else { | 425 } else { |
| 427 Spannable node = positionOf(constant); | 426 Spannable node = positionOf(constant); |
| 428 MessageKind kind = onlyStrings | 427 MessageKind kind = onlyStrings |
| 429 ? MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST | 428 ? MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST |
| 430 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; | 429 : MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST; |
| 431 compiler.reportHint( | 430 compiler.reportHintMessage( |
| 432 node, | 431 node, kind, {'name': node, 'type': apiTypeOf(constant)}); |
| 433 kind, {'name': node, 'type': apiTypeOf(constant)}); | |
| 434 return null; | 432 return null; |
| 435 } | 433 } |
| 436 } | 434 } |
| 437 | 435 |
| 438 /// Find the first non-implementation interface of constant. | 436 /// Find the first non-implementation interface of constant. |
| 439 DartType apiTypeOf(ConstantValue constant) { | 437 DartType apiTypeOf(ConstantValue constant) { |
| 440 DartType type = constant.getType(compiler.coreTypes); | 438 DartType type = constant.getType(compiler.coreTypes); |
| 441 LibraryElement library = type.element.library; | 439 LibraryElement library = type.element.library; |
| 442 if (type.isInterfaceType && library.isInternalLibrary) { | 440 if (type.isInterfaceType && library.isInternalLibrary) { |
| 443 InterfaceType interface = type; | 441 InterfaceType interface = type; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 504 } |
| 507 } | 505 } |
| 508 return result; | 506 return result; |
| 509 } | 507 } |
| 510 | 508 |
| 511 /// Resolve [expression] in [enclosingLibrary]'s import scope. | 509 /// Resolve [expression] in [enclosingLibrary]'s import scope. |
| 512 Element resolveExpression(String expression) { | 510 Element resolveExpression(String expression) { |
| 513 List<String> identifiers = expression.split('.'); | 511 List<String> identifiers = expression.split('.'); |
| 514 Element element = enclosingLibrary.find(identifiers[0]); | 512 Element element = enclosingLibrary.find(identifiers[0]); |
| 515 if (element == null) { | 513 if (element == null) { |
| 516 compiler.reportHint( | 514 compiler.reportHintMessage( |
| 517 spannable, MessageKind.MIRRORS_CANNOT_RESOLVE_IN_CURRENT_LIBRARY, | 515 spannable, |
| 516 MessageKind.MIRRORS_CANNOT_RESOLVE_IN_CURRENT_LIBRARY, |
| 518 {'name': expression}); | 517 {'name': expression}); |
| 519 return null; | 518 return null; |
| 520 } else { | 519 } else { |
| 521 if (identifiers.length == 1) return element; | 520 if (identifiers.length == 1) return element; |
| 522 return resolveLocalExpression(element, identifiers.sublist(1)); | 521 return resolveLocalExpression(element, identifiers.sublist(1)); |
| 523 } | 522 } |
| 524 } | 523 } |
| 525 | 524 |
| 526 /// Resolve [identifiers] in [element]'s local members. | 525 /// Resolve [identifiers] in [element]'s local members. |
| 527 Element resolveLocalExpression(Element element, List<String> identifiers) { | 526 Element resolveLocalExpression(Element element, List<String> identifiers) { |
| 528 Element current = element; | 527 Element current = element; |
| 529 for (String identifier in identifiers) { | 528 for (String identifier in identifiers) { |
| 530 Element e = findLocalMemberIn(current, identifier); | 529 Element e = findLocalMemberIn(current, identifier); |
| 531 if (e == null) { | 530 if (e == null) { |
| 532 if (current.isLibrary) { | 531 if (current.isLibrary) { |
| 533 LibraryElement library = current; | 532 LibraryElement library = current; |
| 534 compiler.reportHint( | 533 compiler.reportHintMessage( |
| 535 spannable, MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY, | 534 spannable, MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY, |
| 536 {'name': identifiers[0], | 535 {'name': identifiers[0], |
| 537 'library': library.libraryOrScriptName}); | 536 'library': library.libraryOrScriptName}); |
| 538 } else { | 537 } else { |
| 539 compiler.reportHint( | 538 compiler.reportHintMessage( |
| 540 spannable, MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT, | 539 spannable, MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT, |
| 541 {'name': identifier, 'element': current.name}); | 540 {'name': identifier, 'element': current.name}); |
| 542 } | 541 } |
| 543 return current; | 542 return current; |
| 544 } | 543 } |
| 545 current = e; | 544 current = e; |
| 546 } | 545 } |
| 547 return current; | 546 return current; |
| 548 } | 547 } |
| 549 | 548 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 // @MirrorsUsed(targets: fisk) | 584 // @MirrorsUsed(targets: fisk) |
| 586 // ^^^^ | 585 // ^^^^ |
| 587 // | 586 // |
| 588 // Instead of saying 'fisk' should pretty print the problematic constant | 587 // Instead of saying 'fisk' should pretty print the problematic constant |
| 589 // value. | 588 // value. |
| 590 return spannable; | 589 return spannable; |
| 591 } | 590 } |
| 592 return node; | 591 return node; |
| 593 } | 592 } |
| 594 } | 593 } |
| OLD | NEW |