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

Side by Side Diff: dart/lib/compiler/implementation/world.dart

Issue 10511008: Support overriding fields with fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 months 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
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 class World { 5 class World {
6 final Map<ClassElement, Set<ClassElement>> subtypes; 6 final Map<ClassElement, Set<ClassElement>> subtypes;
7 7
8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>(); 8 World() : subtypes = new Map<ClassElement, Set<ClassElement>>();
9 9
10 void populate(Compiler compiler, Collection<LibraryElement> libraries) { 10 void populate(Compiler compiler, Collection<LibraryElement> libraries) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 for (ClassElement sub in subtypesOfCls) { 45 for (ClassElement sub in subtypesOfCls) {
46 element = sub.lookupLocalMember(member); 46 element = sub.lookupLocalMember(member);
47 if (element !== null) result.add(element); 47 if (element !== null) result.add(element);
48 } 48 }
49 } 49 }
50 return result; 50 return result;
51 } 51 }
52 52
53 bool isOnlyFields(Type type, SourceString member) { 53 bool isOnlyFields(Type type, SourceString member) {
54 MemberSet memberSet = _memberSetFor(type, member); 54 MemberSet memberSet = _memberSetFor(type, member);
55 return !memberSet.isEmpty() && memberSet.hasJustFields(); 55 return memberSet.hasExactlyOneField();
56 } 56 }
57 } 57 }
58 58
59 /** 59 /**
60 * A [MemberSet] contains all the possible targets for a selector. 60 * A [MemberSet] contains all the possible targets for a selector.
61 */ 61 */
62 class MemberSet { 62 class MemberSet {
63 final Set<Element> elements; 63 final Set<Element> elements;
64 final SourceString name; 64 final SourceString name;
65 65
66 MemberSet(SourceString this.name) : elements = new Set<Element>(); 66 MemberSet(SourceString this.name) : elements = new Set<Element>();
67 67
68 void add(Element element) { 68 void add(Element element) {
69 elements.add(element); 69 elements.add(element);
70 } 70 }
71 71
72 bool isEmpty() => elements.isEmpty(); 72 bool isEmpty() => elements.isEmpty();
73 73
74 bool hasJustFields() { 74 bool hasExactlyOneField() {
75 return elements.every((Element element) => element.isField()); 75 int fieldCount = 0;
76 int nonFieldCount = 0;
77 elements.forEach((Element element) {
78 if (element.isField()) {
79 fieldCount++;
80 } else {
81 nonFieldCount++;
82 }
83 });
84 return fieldCount == 1 && nonFieldCount == 0;
76 } 85 }
77 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698