OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 library fasta.constructor_reference_builder; | 5 library fasta.constructor_reference_builder; |
6 | 6 |
7 import 'builder.dart' | 7 import 'builder.dart' |
8 show Builder, ClassBuilder, PrefixBuilder, Scope, TypeBuilder; | 8 show |
| 9 Builder, |
| 10 ClassBuilder, |
| 11 LibraryBuilder, |
| 12 PrefixBuilder, |
| 13 Scope, |
| 14 TypeBuilder; |
9 | 15 |
10 import '../messages.dart' show warning; | 16 import '../messages.dart' show warning; |
11 | 17 |
12 class ConstructorReferenceBuilder extends Builder { | 18 class ConstructorReferenceBuilder extends Builder { |
13 final String name; | 19 final String name; |
14 | 20 |
15 final List<TypeBuilder> typeArguments; | 21 final List<TypeBuilder> typeArguments; |
16 | 22 |
17 /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`. | 23 /// This is the name of a named constructor. As `bar` in `new Foo<T>.bar()`. |
18 final String suffix; | 24 final String suffix; |
19 | 25 |
20 Builder target; | 26 Builder target; |
21 | 27 |
22 ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix, | 28 ConstructorReferenceBuilder(this.name, this.typeArguments, this.suffix, |
23 Builder parent, int charOffset) | 29 Builder parent, int charOffset) |
24 : super(parent, charOffset, parent.fileUri); | 30 : super(parent, charOffset, parent.fileUri); |
25 | 31 |
26 String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}"; | 32 String get fullNameForErrors => "$name${suffix == null ? '' : '.$suffix'}"; |
27 | 33 |
28 void resolveIn(Scope scope) { | 34 void resolveIn(Scope scope, LibraryBuilder accessingLibrary) { |
29 int index = name.indexOf("."); | 35 int index = name.indexOf("."); |
30 Builder builder; | 36 Builder builder; |
31 if (index == -1) { | 37 if (index == -1) { |
32 builder = scope.lookup(name, charOffset, fileUri); | 38 builder = scope.lookup(name, charOffset, fileUri); |
33 } else { | 39 } else { |
34 String prefix = name.substring(0, index); | 40 String prefix = name.substring(0, index); |
35 String middle = name.substring(index + 1); | 41 String middle = name.substring(index + 1); |
36 builder = scope.lookup(prefix, charOffset, fileUri); | 42 builder = scope.lookup(prefix, charOffset, fileUri); |
37 if (builder is PrefixBuilder) { | 43 if (builder is PrefixBuilder) { |
38 PrefixBuilder prefix = builder; | 44 PrefixBuilder prefix = builder; |
39 builder = prefix.lookup(middle, charOffset, fileUri); | 45 builder = prefix.lookup(middle, charOffset, fileUri); |
40 } else if (builder is ClassBuilder) { | 46 } else if (builder is ClassBuilder) { |
41 ClassBuilder cls = builder; | 47 ClassBuilder cls = builder; |
42 builder = cls.findConstructorOrFactory(middle, charOffset, fileUri); | 48 builder = cls.findConstructorOrFactory( |
| 49 middle, charOffset, fileUri, accessingLibrary); |
43 if (suffix == null) { | 50 if (suffix == null) { |
44 target = builder; | 51 target = builder; |
45 return; | 52 return; |
46 } | 53 } |
47 } | 54 } |
48 } | 55 } |
49 if (builder is ClassBuilder) { | 56 if (builder is ClassBuilder) { |
50 target = | 57 target = builder.findConstructorOrFactory( |
51 builder.findConstructorOrFactory(suffix ?? "", charOffset, fileUri); | 58 suffix ?? "", charOffset, fileUri, accessingLibrary); |
52 } | 59 } |
53 if (target == null) { | 60 if (target == null) { |
54 warning(fileUri, charOffset, | 61 warning(fileUri, charOffset, |
55 "Couldn't find constructor '$fullNameForErrors'."); | 62 "Couldn't find constructor '$fullNameForErrors'."); |
56 } | 63 } |
57 } | 64 } |
58 } | 65 } |
OLD | NEW |