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

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

Issue 2629063005: Fasta builders. (Closed)
Patch Set: Address review comments. 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.constructor_reference_builder;
6
7 import 'builder.dart' show
8 PrefixBuilder,
9 ClassBuilder,
10 Builder,
11 TypeBuilder;
12
13 import 'scope.dart' show
14 Scope;
15
16 class ConstructorReferenceBuilder extends Builder {
17 final String name;
18
19 final List<TypeBuilder> typeArguments;
20
21 /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`.
22 final String suffix;
23
24 Builder target;
25
26 ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix);
27
28 String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}";
29
30 void resolveIn(Scope scope) {
31 int index = name.indexOf(".");
32 Builder builder;
33 if (index == -1) {
34 builder = scope.lookup(name);
35 } else {
36 String prefix = name.substring(0, index);
37 String middle = name.substring(index + 1);
38 builder = scope.lookup(prefix);
39 if (builder is PrefixBuilder) {
40 PrefixBuilder prefix = builder;
41 builder = prefix.exports[middle];
42 } else if (builder is ClassBuilder) {
43 ClassBuilder cls = builder;
44 builder = cls.constructors[middle];
45 if (suffix == null) {
46 target = builder;
47 return;
48 }
49 }
50 }
51 if (builder is ClassBuilder) {
52 target = builder.constructors[suffix ?? ""];
53 }
54 if (target == null) {
55 print("Couldn't find constructor $fullNameForErrors.");
56 }
57 }
58 }
OLDNEW
« no previous file with comments | « pkg/fasta/lib/src/builder/class_builder.dart ('k') | pkg/fasta/lib/src/builder/dynamic_type_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698