OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of resolution; | 5 part of resolution; |
6 | 6 |
| 7 enum ResultKind { |
| 8 NONE, |
| 9 ELEMENT, |
| 10 TYPE, |
| 11 ASSERT, |
| 12 CONSTANT, |
| 13 } |
| 14 |
7 /// The result of resolving a node. | 15 /// The result of resolving a node. |
8 abstract class ResolutionResult { | 16 abstract class ResolutionResult { |
9 Element get element; | 17 const ResolutionResult(); |
| 18 |
| 19 // TODO(johnniwinther): Remove this factory constructor when `null` is never |
| 20 // passed as an element result. |
| 21 factory ResolutionResult.forElement(Element element) { |
| 22 return element != null ? new ElementResult(element) : const NoneResult(); |
| 23 } |
| 24 |
| 25 ResultKind get kind; |
| 26 Element get element => null; |
| 27 DartType get type => null; |
| 28 ConstantExpression get constant => null; |
| 29 bool get isConstant => false; |
10 } | 30 } |
11 | 31 |
12 /// The result for the resolution of a node that points to an [Element]. | 32 /// The result for the resolution of a node that points to an [Element]. |
13 class ElementResult implements ResolutionResult { | 33 class ElementResult extends ResolutionResult { |
14 final Element element; | 34 final Element element; |
15 | 35 |
16 // TODO(johnniwinther): Remove this factory constructor when `null` is never | 36 ResultKind get kind => ResultKind.ELEMENT; |
17 // passed as an element result. | |
18 factory ElementResult(Element element) { | |
19 return element != null ? new ElementResult.internal(element) : null; | |
20 } | |
21 | 37 |
22 ElementResult.internal(this.element); | 38 ElementResult(this.element); |
23 | 39 |
24 String toString() => 'ElementResult($element)'; | 40 String toString() => 'ElementResult($element)'; |
25 } | 41 } |
26 | 42 |
27 /// The result for the resolution of a node that points to an [DartType]. | 43 /// The result for the resolution of a node that points to an [DartType]. |
28 class TypeResult implements ResolutionResult { | 44 class TypeResult extends ResolutionResult { |
29 final DartType type; | 45 final DartType type; |
30 | 46 |
31 TypeResult(this.type) { | 47 TypeResult(this.type) { |
32 assert(type != null); | 48 assert(type != null); |
33 } | 49 } |
34 | 50 |
| 51 ResultKind get kind => ResultKind.TYPE; |
| 52 |
35 Element get element => type.element; | 53 Element get element => type.element; |
36 | 54 |
37 String toString() => 'TypeResult($type)'; | 55 String toString() => 'TypeResult($type)'; |
38 } | 56 } |
39 | 57 |
40 /// The result for the resolution of the `assert` method. | 58 /// The result for the resolution of the `assert` method. |
41 class AssertResult implements ResolutionResult { | 59 class AssertResult extends ResolutionResult { |
42 const AssertResult(); | 60 const AssertResult(); |
43 | 61 |
44 Element get element => null; | 62 ResultKind get kind => ResultKind.ASSERT; |
45 | 63 |
46 String toString() => 'AssertResult()'; | 64 String toString() => 'AssertResult()'; |
47 } | 65 } |
| 66 |
| 67 class ConstantResult extends ResolutionResult { |
| 68 final Node node; |
| 69 final ConstantExpression constant; |
| 70 |
| 71 ConstantResult(this.node, this.constant); |
| 72 |
| 73 bool get isConstant => true; |
| 74 |
| 75 ResultKind get kind => ResultKind.CONSTANT; |
| 76 |
| 77 String toString() => 'ConstantResult(${constant.getText()})'; |
| 78 } |
| 79 |
| 80 class NoneResult extends ResolutionResult { |
| 81 const NoneResult(); |
| 82 |
| 83 ResultKind get kind => ResultKind.NONE; |
| 84 |
| 85 String toString() => 'NoneResult()'; |
| 86 } |
OLD | NEW |