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