| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 6424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6435 * The analysis context in which the multiply defined elements are defined. | 6435 * The analysis context in which the multiply defined elements are defined. |
| 6436 */ | 6436 */ |
| 6437 final AnalysisContext context; | 6437 final AnalysisContext context; |
| 6438 | 6438 |
| 6439 /** | 6439 /** |
| 6440 * The name of the conflicting elements. | 6440 * The name of the conflicting elements. |
| 6441 */ | 6441 */ |
| 6442 String _name; | 6442 String _name; |
| 6443 | 6443 |
| 6444 /** | 6444 /** |
| 6445 * A list containing all of the elements that conflict. | 6445 * A list containing all of the elements defined in SDK libraries that |
| 6446 * conflict. |
| 6446 */ | 6447 */ |
| 6447 final List<Element> conflictingElements; | 6448 final List<Element> sdkElements; |
| 6449 |
| 6450 /** |
| 6451 * A list containing all of the elements defined in non-SDK libraries that |
| 6452 * conflict. |
| 6453 */ |
| 6454 final List<Element> nonSdkElements; |
| 6448 | 6455 |
| 6449 /** | 6456 /** |
| 6450 * Initialize a newly created element in the given [context] to represent a | 6457 * Initialize a newly created element in the given [context] to represent a |
| 6451 * list of [conflictingElements]. | 6458 * list of conflicting [sdkElements] and [nonSdkElements]. At least one of the |
| 6459 * lists must contain more than one element. |
| 6452 */ | 6460 */ |
| 6453 MultiplyDefinedElementImpl(this.context, this.conflictingElements) { | 6461 MultiplyDefinedElementImpl( |
| 6454 _name = conflictingElements[0].name; | 6462 this.context, this.sdkElements, this.nonSdkElements) { |
| 6463 if (nonSdkElements.length > 0) { |
| 6464 _name = nonSdkElements[0].name; |
| 6465 } else { |
| 6466 _name = sdkElements[0].name; |
| 6467 } |
| 6455 } | 6468 } |
| 6456 | 6469 |
| 6457 @override | 6470 @override |
| 6471 List<Element> get conflictingElements { |
| 6472 if (sdkElements.isEmpty) { |
| 6473 return nonSdkElements; |
| 6474 } else if (nonSdkElements.isEmpty) { |
| 6475 return sdkElements; |
| 6476 } |
| 6477 List<Element> elements = nonSdkElements.toList(); |
| 6478 elements.addAll(sdkElements); |
| 6479 return elements; |
| 6480 } |
| 6481 |
| 6482 @override |
| 6458 String get displayName => _name; | 6483 String get displayName => _name; |
| 6459 | 6484 |
| 6460 @override | 6485 @override |
| 6461 SourceRange get docRange => null; | 6486 SourceRange get docRange => null; |
| 6462 | 6487 |
| 6463 @override | 6488 @override |
| 6464 String get documentationComment => null; | 6489 String get documentationComment => null; |
| 6465 | 6490 |
| 6466 @override | 6491 @override |
| 6467 Element get enclosingElement => null; | 6492 Element get enclosingElement => null; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6560 if (element.isAccessibleIn(library)) { | 6585 if (element.isAccessibleIn(library)) { |
| 6561 return true; | 6586 return true; |
| 6562 } | 6587 } |
| 6563 } | 6588 } |
| 6564 return false; | 6589 return false; |
| 6565 } | 6590 } |
| 6566 | 6591 |
| 6567 @override | 6592 @override |
| 6568 String toString() { | 6593 String toString() { |
| 6569 StringBuffer buffer = new StringBuffer(); | 6594 StringBuffer buffer = new StringBuffer(); |
| 6570 buffer.write("["); | 6595 bool needsSeparator = false; |
| 6571 int count = conflictingElements.length; | 6596 void writeList(List<Element> elements) { |
| 6572 for (int i = 0; i < count; i++) { | 6597 for (Element element in elements) { |
| 6573 if (i > 0) { | 6598 if (needsSeparator) { |
| 6574 buffer.write(", "); | 6599 buffer.write(", "); |
| 6575 } | 6600 } else { |
| 6576 Element element = conflictingElements[i]; | 6601 needsSeparator = true; |
| 6577 if (element is ElementImpl) { | 6602 } |
| 6578 element.appendTo(buffer); | 6603 if (element is ElementImpl) { |
| 6579 } else { | 6604 element.appendTo(buffer); |
| 6580 buffer.write(element); | 6605 } else { |
| 6606 buffer.write(element); |
| 6607 } |
| 6581 } | 6608 } |
| 6582 } | 6609 } |
| 6610 |
| 6611 buffer.write("["); |
| 6612 writeList(nonSdkElements); |
| 6613 writeList(sdkElements); |
| 6583 buffer.write("]"); | 6614 buffer.write("]"); |
| 6584 return buffer.toString(); | 6615 return buffer.toString(); |
| 6585 } | 6616 } |
| 6586 | 6617 |
| 6587 @override | 6618 @override |
| 6588 void visitChildren(ElementVisitor visitor) { | 6619 void visitChildren(ElementVisitor visitor) { |
| 6589 // There are no children to visit | 6620 // There are no children to visit |
| 6590 } | 6621 } |
| 6591 | 6622 |
| 6592 /** | 6623 /** |
| 6593 * Return an element in the given [context] that represents the fact that the | 6624 * Return an element in the given [context] that represents the fact that the |
| 6594 * [firstElement] and [secondElement] conflict. (If the elements are the same, | 6625 * [firstElement] and [secondElement] conflict. (If the elements are the same, |
| 6595 * then one of the two will be returned directly.) | 6626 * then one of the two will be returned directly.) |
| 6596 */ | 6627 */ |
| 6597 static Element fromElements( | 6628 static Element fromElements( |
| 6598 AnalysisContext context, Element firstElement, Element secondElement) { | 6629 AnalysisContext context, Element firstElement, Element secondElement) { |
| 6599 List<Element> conflictingElements = | 6630 Set<Element> sdkElements = new HashSet<Element>.identity(); |
| 6600 _computeConflictingElements(firstElement, secondElement); | 6631 Set<Element> nonSdkElements = new HashSet<Element>.identity(); |
| 6601 int length = conflictingElements.length; | 6632 void add(Element element) { |
| 6602 if (length == 0) { | 6633 if (element != null) { |
| 6603 return null; | 6634 if (element is MultiplyDefinedElementImpl) { |
| 6604 } else if (length == 1) { | 6635 sdkElements.addAll(element.sdkElements); |
| 6605 return conflictingElements[0]; | 6636 nonSdkElements.addAll(element.nonSdkElements); |
| 6637 } else if (element.library.isInSdk) { |
| 6638 sdkElements.add(element); |
| 6639 } else { |
| 6640 nonSdkElements.add(element); |
| 6641 } |
| 6642 } |
| 6606 } | 6643 } |
| 6607 return new MultiplyDefinedElementImpl(context, conflictingElements); | |
| 6608 } | |
| 6609 | 6644 |
| 6610 /** | 6645 add(firstElement); |
| 6611 * Add the given [element] to the list of [elements]. If the element is a | 6646 add(secondElement); |
| 6612 * multiply-defined element, add all of the conflicting elements that it | 6647 int nonSdkCount = nonSdkElements.length; |
| 6613 * represents. | 6648 if (nonSdkCount == 0) { |
| 6614 */ | 6649 int sdkCount = sdkElements.length; |
| 6615 static void _add(HashSet<Element> elements, Element element) { | 6650 if (sdkCount == 0) { |
| 6616 if (element is MultiplyDefinedElementImpl) { | 6651 return null; |
| 6617 for (Element conflictingElement in element.conflictingElements) { | 6652 } else if (sdkCount == 1) { |
| 6618 elements.add(conflictingElement); | 6653 return sdkElements.first; |
| 6619 } | 6654 } |
| 6620 } else { | 6655 } else if (nonSdkCount == 1) { |
| 6621 elements.add(element); | 6656 return nonSdkElements.first; |
| 6622 } | 6657 } |
| 6623 } | 6658 return new MultiplyDefinedElementImpl( |
| 6624 | 6659 context, |
| 6625 /** | 6660 sdkElements.toList(growable: false), |
| 6626 * Use the given elements to construct a list of conflicting elements. If | 6661 nonSdkElements.toList(growable: false)); |
| 6627 * either the [firstElement] or [secondElement] are multiply-defined elements | |
| 6628 * then the conflicting elements they represent will be included in the array. | |
| 6629 * Otherwise, the element itself will be included. | |
| 6630 */ | |
| 6631 static List<Element> _computeConflictingElements( | |
| 6632 Element firstElement, Element secondElement) { | |
| 6633 HashSet<Element> elements = new HashSet<Element>(); | |
| 6634 _add(elements, firstElement); | |
| 6635 _add(elements, secondElement); | |
| 6636 return elements.toList(growable: false); | |
| 6637 } | 6662 } |
| 6638 } | 6663 } |
| 6639 | 6664 |
| 6640 /** | 6665 /** |
| 6641 * A [MethodElementImpl], with the additional information of a list of | 6666 * A [MethodElementImpl], with the additional information of a list of |
| 6642 * [ExecutableElement]s from which this element was composed. | 6667 * [ExecutableElement]s from which this element was composed. |
| 6643 */ | 6668 */ |
| 6644 class MultiplyInheritedMethodElementImpl extends MethodElementImpl | 6669 class MultiplyInheritedMethodElementImpl extends MethodElementImpl |
| 6645 implements MultiplyInheritedExecutableElement { | 6670 implements MultiplyInheritedExecutableElement { |
| 6646 /** | 6671 /** |
| (...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8479 | 8504 |
| 8480 @override | 8505 @override |
| 8481 void visitElement(Element element) { | 8506 void visitElement(Element element) { |
| 8482 int offset = element.nameOffset; | 8507 int offset = element.nameOffset; |
| 8483 if (offset != -1) { | 8508 if (offset != -1) { |
| 8484 map[offset] = element; | 8509 map[offset] = element; |
| 8485 } | 8510 } |
| 8486 super.visitElement(element); | 8511 super.visitElement(element); |
| 8487 } | 8512 } |
| 8488 } | 8513 } |
| OLD | NEW |