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

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 730803003: Use a better way to compute InterfaceTypes least upper bound. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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/analysis_server/test/services/refactoring/extract_method_test.dart ('k') | 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) 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element; 8 library engine.element;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_engine.dart'; 12 import 'java_engine.dart';
13 import 'utilities_collection.dart'; 13 import 'utilities_collection.dart';
14 import 'source.dart'; 14 import 'source.dart';
15 import 'scanner.dart' show Keyword; 15 import 'scanner.dart' show Keyword;
16 import 'ast.dart'; 16 import 'ast.dart';
17 import 'sdk.dart' show DartSdk; 17 import 'sdk.dart' show DartSdk;
18 import 'html.dart' show XmlAttributeNode, XmlTagNode; 18 import 'html.dart' show XmlAttributeNode, XmlTagNode;
19 import 'engine.dart' show AnalysisContext, AnalysisEngine, AnalysisException; 19 import 'engine.dart' show AnalysisContext, AnalysisEngine, AnalysisException;
20 import 'constant.dart' show EvaluationResultImpl; 20 import 'constant.dart' show EvaluationResultImpl;
21 import 'resolver.dart'; 21 import 'resolver.dart';
22 import 'utilities_dart.dart'; 22 import 'utilities_dart.dart';
23 import 'element.dart';
23 24
24 /** 25 /**
25 * Information about Angular application. 26 * Information about Angular application.
26 */ 27 */
27 class AngularApplication { 28 class AngularApplication {
28 final Source entryPoint; 29 final Source entryPoint;
29 30
30 final Set<Source> _librarySources; 31 final Set<Source> _librarySources;
31 32
32 final List<AngularElement> elements; 33 final List<AngularElement> elements;
(...skipping 6666 matching lines...) Expand 10 before | Expand all | Expand 10 after
6699 6700
6700 /** 6701 /**
6701 * Return the type resulting from substituting the given arguments for this 6702 * Return the type resulting from substituting the given arguments for this
6702 * type's parameters. This is fully equivalent to `substitute2(argumentTypes, 6703 * type's parameters. This is fully equivalent to `substitute2(argumentTypes,
6703 * getTypeArguments())`. 6704 * getTypeArguments())`.
6704 */ 6705 */
6705 InterfaceType substitute4(List<DartType> argumentTypes); 6706 InterfaceType substitute4(List<DartType> argumentTypes);
6706 6707
6707 @override 6708 @override
6708 InterfaceType substitute2(List<DartType> argumentTypes, List<DartType> paramet erTypes); 6709 InterfaceType substitute2(List<DartType> argumentTypes, List<DartType> paramet erTypes);
6710
6711 /**
6712 * Returns a "smart" version of the "least upper bound" of the given types.
6713 *
6714 * If these types have the same element and differ only in terms of the type
6715 * arguments, attempts to find a compatible set of type arguments.
6716 *
6717 * Otherwise, calls [DartType.getLeastUpperBound].
6718 */
6719 static InterfaceType getSmartLeastUpperBound(InterfaceType first,
6720 InterfaceType second) {
6721 if (first.element == second.element) {
6722 return _leastUpperBound(first, second);
6723 }
6724 return first.getLeastUpperBound(second);
6725 }
6726
6727 /**
6728 * Return the "least upper bound" of the given types under the assumption that
6729 * the types have the same element and differ only in terms of the type
6730 * arguments.
6731 *
6732 * The resulting type is composed by comparing the corresponding type
6733 * arguments, keeping those that are the same, and using 'dynamic' for those
6734 * that are different.
6735 */
6736 static InterfaceType _leastUpperBound(InterfaceType firstType,
6737 InterfaceType secondType) {
6738 ClassElement firstElement = firstType.element;
6739 ClassElement secondElement = secondType.element;
6740 if (firstElement != secondElement) {
6741 throw new IllegalArgumentException('The same elements expected, but '
6742 '$firstElement and $secondElement are given.');
6743 }
6744 if (firstType == secondType) {
6745 return firstType;
6746 }
6747 List<DartType> firstArguments = firstType.typeArguments;
6748 List<DartType> secondArguments = secondType.typeArguments;
6749 int argumentCount = firstArguments.length;
6750 if (argumentCount == 0) {
6751 return firstType;
6752 }
6753 List<DartType> lubArguments = new List<DartType>(argumentCount);
6754 for (int i = 0; i < argumentCount; i++) {
6755 //
6756 // Ideally we would take the least upper bound of the two argument types,
6757 // but this can cause an infinite recursion (such as when finding the
6758 // least upper bound of String and num).
6759 //
6760 if (firstArguments[i] == secondArguments[i]) {
6761 lubArguments[i] = firstArguments[i];
6762 }
6763 if (lubArguments[i] == null) {
6764 lubArguments[i] = DynamicTypeImpl.instance;
6765 }
6766 }
6767 InterfaceTypeImpl lub = new InterfaceTypeImpl.con1(firstElement);
6768 lub.typeArguments = lubArguments;
6769 return lub;
6770 }
6709 } 6771 }
6710 6772
6711 /** 6773 /**
6712 * Instances of the class `InterfaceTypeImpl` defines the behavior common to obj ects 6774 * Instances of the class `InterfaceTypeImpl` defines the behavior common to obj ects
6713 * representing the type introduced by either a class or an interface, or a refe rence to such a 6775 * representing the type introduced by either a class or an interface, or a refe rence to such a
6714 * type. 6776 * type.
6715 */ 6777 */
6716 class InterfaceTypeImpl extends TypeImpl implements InterfaceType { 6778 class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
6717 /** 6779 /**
6718 * This method computes the longest inheritance path from some passed [Type] t o Object. 6780 * This method computes the longest inheritance path from some passed [Type] t o Object.
(...skipping 5038 matching lines...) Expand 10 before | Expand all | Expand 10 after
11757 if (type is UnionType) { 11819 if (type is UnionType) {
11758 return (type as UnionTypeImpl).internalUnionTypeIsSuperTypeOf(this, visite dTypePairs); 11820 return (type as UnionTypeImpl).internalUnionTypeIsSuperTypeOf(this, visite dTypePairs);
11759 } 11821 }
11760 // The only subtype relations that pertain to void are therefore: 11822 // The only subtype relations that pertain to void are therefore:
11761 // void <: void (by reflexivity) 11823 // void <: void (by reflexivity)
11762 // bottom <: void (as bottom is a subtype of all types). 11824 // bottom <: void (as bottom is a subtype of all types).
11763 // void <: dynamic (as dynamic is a supertype of all types) 11825 // void <: dynamic (as dynamic is a supertype of all types)
11764 return identical(type, this) || type.isDynamic; 11826 return identical(type, this) || type.isDynamic;
11765 } 11827 }
11766 } 11828 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/refactoring/extract_method_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698