Chromium Code Reviews

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/js_field_storage.dart

Issue 2571363002: fixes #27385, implement virtual fields in DDC (Closed)
Patch Set: format Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:collection' show HashSet;
6
7 import 'package:analyzer/dart/ast/ast.dart' show Identifier;
8 import 'package:analyzer/dart/element/element.dart';
9
10 class PropertyOverrideResult {
11 final bool foundGetter;
12 final bool foundSetter;
13
14 PropertyOverrideResult(this.foundGetter, this.foundSetter);
15 }
16
17 PropertyOverrideResult checkForPropertyOverride(
18 FieldElement field, List<ClassElement> superclasses) {
19 bool foundGetter = false;
20 bool foundSetter = false;
21
22 for (var superclass in superclasses) {
23 var superprop = getProperty(superclass, field.library, field.name);
24 if (superprop == null) continue;
25
26 var getter = superprop.getter;
27 bool hasGetter = getter != null && !getter.isAbstract;
28 if (hasGetter) foundGetter = true;
29
30 var setter = superprop.setter;
31 bool hasSetter = setter != null && !setter.isAbstract;
32 if (hasSetter) foundSetter = true;
33 }
34
35 return new PropertyOverrideResult(foundGetter, foundSetter);
36 }
37
38 FieldElement getProperty(
39 ClassElement cls, LibraryElement fromLibrary, String name) {
40 // Properties from a different library are not accessible.
41 if (Identifier.isPrivateName(name) && cls.library != fromLibrary) {
42 return null;
43 }
44 for (var accessor in cls.accessors) {
45 var prop = accessor.variable;
46 if (prop.name == name) return prop;
47 }
48 return null;
49 }
50
51 List<ClassElement> getSuperclasses(ClassElement cls) {
52 var result = <ClassElement>[];
53 var visited = new HashSet<ClassElement>();
54 while (cls != null && visited.add(cls)) {
55 for (var mixinType in cls.mixins.reversed) {
56 var mixin = mixinType.element;
57 if (mixin != null) result.add(mixin);
58 }
59 var supertype = cls.supertype;
60 if (supertype == null) break;
61
62 cls = supertype.element;
63 result.add(cls);
64 }
65 return result;
66 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/element_helpers.dart ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine