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.kernel_field_builder; | 5 library fasta.kernel_field_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show | 7 import 'package:kernel/ast.dart' show Expression, Field, Library, Name; |
8 Expression, | |
9 Field, | |
10 Library, | |
11 Name; | |
12 | 8 |
13 import 'kernel_builder.dart' show | 9 import 'kernel_builder.dart' |
14 Builder, | 10 show Builder, FieldBuilder, KernelTypeBuilder, MetadataBuilder; |
15 FieldBuilder, | |
16 KernelTypeBuilder, | |
17 MetadataBuilder; | |
18 | 11 |
19 class KernelFieldBuilder extends FieldBuilder<Expression> { | 12 class KernelFieldBuilder extends FieldBuilder<Expression> { |
20 final Field field; | 13 final Field field; |
21 final List<MetadataBuilder> metadata; | 14 final List<MetadataBuilder> metadata; |
22 final KernelTypeBuilder type; | 15 final KernelTypeBuilder type; |
23 | 16 |
24 KernelFieldBuilder(this.metadata, this.type, String name, int modifiers, | 17 KernelFieldBuilder(this.metadata, this.type, String name, int modifiers, |
25 Builder compilationUnit, int charOffset) | 18 Builder compilationUnit, int charOffset) |
26 : field = | 19 : field = new Field(null, fileUri: compilationUnit?.relativeFileUri) |
27 new Field(null, fileUri: compilationUnit?.relativeFileUri) | 20 ..fileOffset = charOffset, |
28 ..fileOffset = charOffset, | |
29 super(name, modifiers, compilationUnit, charOffset); | 21 super(name, modifiers, compilationUnit, charOffset); |
30 | 22 |
31 void set initializer(Expression value) { | 23 void set initializer(Expression value) { |
32 field.initializer = value | 24 field.initializer = value..parent = field; |
33 ..parent = field; | |
34 } | 25 } |
35 | 26 |
36 Field build(Library library) { | 27 Field build(Library library) { |
37 field.name ??= new Name(name, library); | 28 field.name ??= new Name(name, library); |
38 if (type != null) { | 29 if (type != null) { |
39 field.type = type.build(); | 30 field.type = type.build(); |
40 } | 31 } |
41 bool isInstanceMember = !isStatic && !isTopLevel; | 32 bool isInstanceMember = !isStatic && !isTopLevel; |
42 return field | 33 return field |
43 ..isFinal = isFinal | 34 ..isFinal = isFinal |
44 ..isConst = isConst | 35 ..isConst = isConst |
45 ..hasImplicitGetter = isInstanceMember | 36 ..hasImplicitGetter = isInstanceMember |
46 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal | 37 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal |
47 ..isStatic = !isInstanceMember; | 38 ..isStatic = !isInstanceMember; |
48 } | 39 } |
49 | 40 |
50 Field get target => field; | 41 Field get target => field; |
51 } | 42 } |
OLD | NEW |