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' | 7 import 'package:kernel/ast.dart' |
8 show DartType, Expression, Field, Name, NullLiteral; | 8 show DartType, Expression, Field, Name, NullLiteral; |
9 | 9 |
10 import '../../scanner/token.dart' show Token; | 10 import '../../scanner/token.dart' show Token; |
(...skipping 19 matching lines...) Expand all Loading... |
30 import 'kernel_shadow_ast.dart' show KernelField; | 30 import 'kernel_shadow_ast.dart' show KernelField; |
31 | 31 |
32 class KernelFieldBuilder extends FieldBuilder<Expression> { | 32 class KernelFieldBuilder extends FieldBuilder<Expression> { |
33 final KernelField field; | 33 final KernelField field; |
34 final List<MetadataBuilder> metadata; | 34 final List<MetadataBuilder> metadata; |
35 final KernelTypeBuilder type; | 35 final KernelTypeBuilder type; |
36 final Token initializerTokenForInference; | 36 final Token initializerTokenForInference; |
37 final bool hasInitializer; | 37 final bool hasInitializer; |
38 | 38 |
39 KernelFieldBuilder( | 39 KernelFieldBuilder( |
40 String documentationComment, | |
41 this.metadata, | 40 this.metadata, |
42 this.type, | 41 this.type, |
43 String name, | 42 String name, |
44 int modifiers, | 43 int modifiers, |
45 Builder compilationUnit, | 44 Builder compilationUnit, |
46 int charOffset, | 45 int charOffset, |
47 this.initializerTokenForInference, | 46 this.initializerTokenForInference, |
48 this.hasInitializer) | 47 this.hasInitializer) |
49 : field = new KernelField(null, fileUri: compilationUnit?.relativeFileUri) | 48 : field = new KernelField(null, fileUri: compilationUnit?.relativeFileUri) |
50 ..fileOffset = charOffset, | 49 ..fileOffset = charOffset, |
51 super( | 50 super(name, modifiers, compilationUnit, charOffset); |
52 documentationComment, name, modifiers, compilationUnit, charOffset); | |
53 | 51 |
54 void set initializer(Expression value) { | 52 void set initializer(Expression value) { |
55 if (!hasInitializer && value is! NullLiteral && !isConst && !isFinal) { | 53 if (!hasInitializer && value is! NullLiteral && !isConst && !isFinal) { |
56 internalProblem( | 54 internalProblem( |
57 messageInternalProblemAlreadyInitialized, charOffset, fileUri); | 55 messageInternalProblemAlreadyInitialized, charOffset, fileUri); |
58 } | 56 } |
59 field.initializer = value..parent = field; | 57 field.initializer = value..parent = field; |
60 } | 58 } |
61 | 59 |
62 bool get isEligibleForInference => | 60 bool get isEligibleForInference => |
63 type == null && (hasInitializer || isInstanceMember); | 61 type == null && (hasInitializer || isInstanceMember); |
64 | 62 |
65 Field build(SourceLibraryBuilder library) { | 63 Field build(SourceLibraryBuilder library) { |
66 field.documentationComment = documentationComment; | |
67 field.name ??= new Name(name, library.target); | 64 field.name ??= new Name(name, library.target); |
68 if (type != null) { | 65 if (type != null) { |
69 field.type = type.build(library); | 66 field.type = type.build(library); |
70 } | 67 } |
71 bool isInstanceMember = !isStatic && !isTopLevel; | 68 bool isInstanceMember = !isStatic && !isTopLevel; |
72 field | 69 field |
73 ..isFinal = isFinal | 70 ..isFinal = isFinal |
74 ..isConst = isConst | 71 ..isConst = isConst |
75 ..hasImplicitGetter = isInstanceMember | 72 ..hasImplicitGetter = isInstanceMember |
76 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal | 73 ..hasImplicitSetter = isInstanceMember && !isConst && !isFinal |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 110 } |
114 } | 111 } |
115 } | 112 } |
116 | 113 |
117 @override | 114 @override |
118 DartType get builtType => field.type; | 115 DartType get builtType => field.type; |
119 | 116 |
120 @override | 117 @override |
121 bool get hasImplicitType => type == null; | 118 bool get hasImplicitType => type == null; |
122 } | 119 } |
OLD | NEW |