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 elements.modelx; | 5 library elements.modelx; |
6 | 6 |
7 import 'dart:uri'; | 7 import 'dart:uri'; |
8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
9 | 9 |
10 import 'elements.dart'; | 10 import 'elements.dart'; |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 * When called on the implementation element both members declared in the | 1523 * When called on the implementation element both members declared in the |
1524 * origin and the patch class are returned. | 1524 * origin and the patch class are returned. |
1525 */ | 1525 */ |
1526 Element lookupSelector(Selector selector) { | 1526 Element lookupSelector(Selector selector) { |
1527 return internalLookupSelector(selector, false); | 1527 return internalLookupSelector(selector, false); |
1528 } | 1528 } |
1529 | 1529 |
1530 Element lookupSuperSelector(Selector selector) { | 1530 Element lookupSuperSelector(Selector selector) { |
1531 return internalLookupSelector(selector, true); | 1531 return internalLookupSelector(selector, true); |
1532 } | 1532 } |
1533 | 1533 |
1534 Element internalLookupSelector(Selector selector, bool isSuperLookup) { | 1534 Element internalLookupSelector(Selector selector, bool isSuperLookup) { |
1535 SourceString name = selector.name; | 1535 SourceString name = selector.name; |
1536 bool isPrivate = name.isPrivate(); | 1536 bool isPrivate = name.isPrivate(); |
1537 LibraryElement library = selector.library; | 1537 LibraryElement library = selector.library; |
1538 for (ClassElement current = isSuperLookup ? superclass : this; | 1538 for (ClassElement current = isSuperLookup ? superclass : this; |
1539 current != null; | 1539 current != null; |
1540 current = current.superclass) { | 1540 current = current.superclass) { |
1541 Element member = current.lookupLocalMember(name); | 1541 Element member = current.lookupLocalMember(name); |
1542 if (member == null) continue; | 1542 if (member == null) continue; |
1543 // Private members from a different library are not visible. | 1543 // Private members from a different library are not visible. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 } | 1576 } |
1577 | 1577 |
1578 /** | 1578 /** |
1579 * Returns true if the [fieldMember] is shadowed by another field. The given | 1579 * Returns true if the [fieldMember] is shadowed by another field. The given |
1580 * [fieldMember] must be a member of this class. | 1580 * [fieldMember] must be a member of this class. |
1581 * | 1581 * |
1582 * This method also works if the [fieldMember] is private. | 1582 * This method also works if the [fieldMember] is private. |
1583 */ | 1583 */ |
1584 bool isShadowedByField(Element fieldMember) { | 1584 bool isShadowedByField(Element fieldMember) { |
1585 assert(fieldMember.isField()); | 1585 assert(fieldMember.isField()); |
1586 // Note that we cannot use [lookupMember] or [lookupSuperMember] since it | 1586 SourceString fieldName = fieldMember.name; |
1587 // will not do the right thing for private elements. | 1587 bool isPrivate = fieldName.isPrivate(); |
| 1588 LibraryElement memberLibrary = fieldMember.getLibrary(); |
1588 ClassElement lookupClass = this; | 1589 ClassElement lookupClass = this; |
1589 LibraryElement memberLibrary = fieldMember.getLibrary(); | 1590 while (lookupClass != null) { |
1590 if (fieldMember.name.isPrivate()) { | 1591 Element foundMember = lookupClass.lookupLocalMember(fieldName); |
1591 // We find a super class in the same library as the field. This way the | 1592 if (foundMember != null) { |
1592 // lookupMember will work. | 1593 if (foundMember == fieldMember) return false; |
1593 while (lookupClass.getLibrary() != memberLibrary) { | 1594 if (foundMember.isField()) { |
1594 lookupClass = lookupClass.superclass; | 1595 if (!isPrivate || memberLibrary == foundMember.getLibrary()) { |
| 1596 // Private fields can only be shadowed by a field declared |
| 1597 // in the same library. |
| 1598 return true; |
| 1599 } |
| 1600 } |
1595 } | 1601 } |
| 1602 lookupClass = lookupClass.superclass; |
1596 } | 1603 } |
1597 SourceString fieldName = fieldMember.name; | 1604 return false; |
1598 while (true) { | |
1599 Element foundMember = lookupClass.lookupMember(fieldName); | |
1600 if (foundMember == fieldMember) return false; | |
1601 if (foundMember.isField()) return true; | |
1602 lookupClass = foundMember.getEnclosingClass().superclass; | |
1603 } | |
1604 } | 1605 } |
1605 | 1606 |
1606 Element validateConstructorLookupResults(Selector selector, | 1607 Element validateConstructorLookupResults(Selector selector, |
1607 Element result, | 1608 Element result, |
1608 Element noMatch(Element)) { | 1609 Element noMatch(Element)) { |
1609 if (result == null | 1610 if (result == null |
1610 || !result.isConstructor() | 1611 || !result.isConstructor() |
1611 || (selector.name.isPrivate() | 1612 || (selector.name.isPrivate() |
1612 && result.getLibrary() != selector.library)) { | 1613 && result.getLibrary() != selector.library)) { |
1613 result = noMatch != null ? noMatch(result) : null; | 1614 result = noMatch != null ? noMatch(result) : null; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2018 | 2019 |
2019 MetadataAnnotation ensureResolved(Compiler compiler) { | 2020 MetadataAnnotation ensureResolved(Compiler compiler) { |
2020 if (resolutionState == STATE_NOT_STARTED) { | 2021 if (resolutionState == STATE_NOT_STARTED) { |
2021 compiler.resolver.resolveMetadataAnnotation(this); | 2022 compiler.resolver.resolveMetadataAnnotation(this); |
2022 } | 2023 } |
2023 return this; | 2024 return this; |
2024 } | 2025 } |
2025 | 2026 |
2026 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 2027 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
2027 } | 2028 } |
OLD | NEW |