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

Side by Side Diff: pkg/fasta/lib/src/builder/class_builder.dart

Issue 2629063005: Fasta builders. (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 library fasta.class_builder;
6
7 import 'builder.dart' show
8 Builder,
9 ConstructorReferenceBuilder,
10 LibraryBuilder,
11 MetadataBuilder,
12 TypeBuilder,
13 TypeDeclarationBuilder,
14 TypeVariableBuilder;
15
16 import 'scope.dart' show
17 AmbiguousBuilder,
18 Scope;
19
20 abstract class ClassBuilder<T extends TypeBuilder, R>
21 extends TypeDeclarationBuilder<T, R> {
22 final List<TypeVariableBuilder> typeVariables;
23
24 T supertype;
25
26 List<T> interfaces;
27
28 final Map<String, Builder> members;
29
30 ClassBuilder(
31 List<MetadataBuilder> metadata, int modifiers,
32 String name, this.typeVariables, this.supertype, this.interfaces,
33 this.members, List<T> types, LibraryBuilder parent)
34 : super(metadata, modifiers, name, types, parent);
35
36 List<ConstructorReferenceBuilder> get constructorReferences => null;
37
38 Map<String, Builder> get constructors;
39
40 Map<String, Builder> get membersInScope => members;
41
42 int resolveTypes(LibraryBuilder library) {
43 Scope scope;
44 int count = 0;
45 if (types != null) {
46 scope = computeInstanceScope(library.scope);
47 for (T t in types) {
48 t.resolveIn(scope);
49 }
50 count += types.length;
51 }
52 return count;
53 }
54
55 int resolveConstructors(LibraryBuilder library) {
56 if (constructorReferences == null) return 0;
57 Scope scope = computeInstanceScope(library.scope);
58 for (ConstructorReferenceBuilder ref in constructorReferences) {
59 ref.resolveIn(scope);
60 }
61 return constructorReferences.length;
62 }
63
64 Scope computeInstanceScope(Scope parent) {
65 if (typeVariables != null) {
66 Map<String, Builder> local = <String, Builder>{};
67 for (TypeVariableBuilder t in typeVariables) {
68 local[t.name] = t;
69 }
70 parent = new Scope(local, parent, isModifiable: false);
71 }
72 return new Scope(membersInScope, parent, isModifiable: false);
73 }
74
75 Builder findStaticBuilder(String name, {bool isSetter: false}) {
Johnni Winther 2017/01/16 13:01:19 Add dartdoc. When is this used? Is it only for get
ahe 2017/01/16 15:26:33 Added: /// Lookup a static member of this class
76 Builder builder = members[name];
77 if (builder?.next != null) {
78 Builder getterBuilder;
79 Builder setterBuilder;
80 Builder current = builder;
81 while (current != null) {
82 if (current.isGetter && getterBuilder == null) {
83 getterBuilder = current;
84 } else if (current.isSetter && setterBuilder == null) {
85 setterBuilder = current;
86 } else {
87 return new AmbiguousBuilder(builder);
88 }
89 current = current.next;
90 }
91 builder = isSetter ? setterBuilder : getterBuilder;
92 }
93 if (builder == null) {
94 return null;
95 } else if (isSetter && builder.isGetter) {
96 return null;
97 } else {
98 return builder.isInstanceMember ? null : builder;
99 }
100 }
101
102 Builder findConstructorOrFactory(String name);
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698