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