| 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 library analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 const v = C; | 2005 const v = C; |
| 2006 '''); | 2006 '''); |
| 2007 _assertUnlinkedConst(variable.constExpr, operators: [ | 2007 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2008 UnlinkedConstOperation.pushReference | 2008 UnlinkedConstOperation.pushReference |
| 2009 ], referenceValidators: [ | 2009 ], referenceValidators: [ |
| 2010 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 2010 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 2011 expectedKind: ReferenceKind.classOrEnum) | 2011 expectedKind: ReferenceKind.classOrEnum) |
| 2012 ]); | 2012 ]); |
| 2013 } | 2013 } |
| 2014 | 2014 |
| 2015 test_constExpr_pushReference_class_field() { | |
| 2016 // TODO(scheglov) Not sure for to represent a field reference | |
| 2017 // using TypeRef. | |
| 2018 // UnlinkedVariable variable = serializeVariableText(''' | |
| 2019 //class C { | |
| 2020 // static const int F = 1; | |
| 2021 //} | |
| 2022 //const v = C.F; | |
| 2023 //'''); | |
| 2024 // _assertUnlinkedConst(variable.constExpr, operators: [ | |
| 2025 // UnlinkedConstOperation.pushReference | |
| 2026 // ], references: [ | |
| 2027 // (TypeRef r) => checkTypeRef(r, null, null, 'F', | |
| 2028 // expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C') | |
| 2029 // ]); | |
| 2030 } | |
| 2031 | |
| 2032 test_constExpr_pushReference_enum() { | 2015 test_constExpr_pushReference_enum() { |
| 2033 UnlinkedVariable variable = serializeVariableText(''' | 2016 UnlinkedVariable variable = serializeVariableText(''' |
| 2034 enum C {V1, V2, V3} | 2017 enum C {V1, V2, V3} |
| 2035 const v = C; | 2018 const v = C; |
| 2036 '''); | 2019 '''); |
| 2037 _assertUnlinkedConst(variable.constExpr, operators: [ | 2020 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2038 UnlinkedConstOperation.pushReference | 2021 UnlinkedConstOperation.pushReference |
| 2039 ], referenceValidators: [ | 2022 ], referenceValidators: [ |
| 2040 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 2023 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 2041 expectedKind: ReferenceKind.classOrEnum) | 2024 expectedKind: ReferenceKind.classOrEnum) |
| 2042 ]); | 2025 ]); |
| 2043 } | 2026 } |
| 2044 | 2027 |
| 2028 test_constExpr_pushReference_field() { |
| 2029 UnlinkedVariable variable = serializeVariableText(''' |
| 2030 class C { |
| 2031 static const int F = 1; |
| 2032 } |
| 2033 const v = C.F; |
| 2034 '''); |
| 2035 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2036 UnlinkedConstOperation.pushReference |
| 2037 ], referenceValidators: [ |
| 2038 (EntityRef r) => checkTypeRef(r, null, null, 'F', |
| 2039 expectedKind: ReferenceKind.constField, |
| 2040 prefixExpectations: [ |
| 2041 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C') |
| 2042 ]) |
| 2043 ]); |
| 2044 } |
| 2045 |
| 2046 test_constExpr_pushReference_field_imported() { |
| 2047 addNamedSource( |
| 2048 '/a.dart', |
| 2049 ''' |
| 2050 class C { |
| 2051 static const int F = 1; |
| 2052 } |
| 2053 '''); |
| 2054 UnlinkedVariable variable = serializeVariableText(''' |
| 2055 import 'a.dart'; |
| 2056 const v = C.F; |
| 2057 '''); |
| 2058 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2059 UnlinkedConstOperation.pushReference |
| 2060 ], referenceValidators: [ |
| 2061 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'F', |
| 2062 expectedKind: ReferenceKind.constField, |
| 2063 prefixExpectations: [ |
| 2064 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C') |
| 2065 ]) |
| 2066 ]); |
| 2067 } |
| 2068 |
| 2069 test_constExpr_pushReference_field_imported_withPrefix() { |
| 2070 addNamedSource( |
| 2071 '/a.dart', |
| 2072 ''' |
| 2073 class C { |
| 2074 static const int F = 1; |
| 2075 } |
| 2076 '''); |
| 2077 UnlinkedVariable variable = serializeVariableText(''' |
| 2078 import 'a.dart' as p; |
| 2079 const v = p.C.F; |
| 2080 '''); |
| 2081 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2082 UnlinkedConstOperation.pushReference |
| 2083 ], referenceValidators: [ |
| 2084 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'F', |
| 2085 expectedKind: ReferenceKind.constField, |
| 2086 prefixExpectations: [ |
| 2087 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C'), |
| 2088 new _PrefixExpectation(ReferenceKind.prefix, 'p', |
| 2089 inLibraryDefiningUnit: true), |
| 2090 ]) |
| 2091 ]); |
| 2092 } |
| 2093 |
| 2094 test_constExpr_pushReference_topLevelVariable() { |
| 2095 UnlinkedVariable variable = serializeVariableText(''' |
| 2096 const int a = 1; |
| 2097 const v = a; |
| 2098 '''); |
| 2099 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2100 UnlinkedConstOperation.pushReference |
| 2101 ], referenceValidators: [ |
| 2102 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 2103 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 2104 ]); |
| 2105 } |
| 2106 |
| 2045 test_constExpr_pushReference_topLevelVariable_imported() { | 2107 test_constExpr_pushReference_topLevelVariable_imported() { |
| 2046 addNamedSource('/a.dart', 'const int a = 1;'); | 2108 addNamedSource('/a.dart', 'const int a = 1;'); |
| 2047 UnlinkedVariable variable = serializeVariableText(''' | 2109 UnlinkedVariable variable = serializeVariableText(''' |
| 2048 import 'a.dart'; | 2110 import 'a.dart'; |
| 2049 const v = a; | 2111 const v = a; |
| 2050 '''); | 2112 '''); |
| 2051 _assertUnlinkedConst(variable.constExpr, operators: [ | 2113 _assertUnlinkedConst(variable.constExpr, operators: [ |
| 2052 UnlinkedConstOperation.pushReference | 2114 UnlinkedConstOperation.pushReference |
| 2053 ], referenceValidators: [ | 2115 ], referenceValidators: [ |
| 2054 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', | 2116 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2066 UnlinkedConstOperation.pushReference | 2128 UnlinkedConstOperation.pushReference |
| 2067 ], referenceValidators: [ | 2129 ], referenceValidators: [ |
| 2068 (EntityRef r) { | 2130 (EntityRef r) { |
| 2069 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', | 2131 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| 2070 expectedKind: ReferenceKind.topLevelPropertyAccessor, | 2132 expectedKind: ReferenceKind.topLevelPropertyAccessor, |
| 2071 expectedPrefix: 'p'); | 2133 expectedPrefix: 'p'); |
| 2072 } | 2134 } |
| 2073 ]); | 2135 ]); |
| 2074 } | 2136 } |
| 2075 | 2137 |
| 2076 test_constExpr_pushReference_topLevelVariable_local() { | |
| 2077 // TODO(scheglov) use `a + b` | |
| 2078 UnlinkedVariable variable = serializeVariableText(''' | |
| 2079 const int a = 1; | |
| 2080 const v = a; | |
| 2081 '''); | |
| 2082 _assertUnlinkedConst(variable.constExpr, operators: [ | |
| 2083 UnlinkedConstOperation.pushReference | |
| 2084 ], referenceValidators: [ | |
| 2085 (EntityRef r) => checkTypeRef(r, null, null, 'a', | |
| 2086 expectedKind: ReferenceKind.topLevelPropertyAccessor) | |
| 2087 ]); | |
| 2088 } | |
| 2089 | |
| 2090 test_constExpr_pushString_adjacent() { | 2138 test_constExpr_pushString_adjacent() { |
| 2091 UnlinkedVariable variable = | 2139 UnlinkedVariable variable = |
| 2092 serializeVariableText('const v = "aaa" "b" "ccc";'); | 2140 serializeVariableText('const v = "aaa" "b" "ccc";'); |
| 2093 _assertUnlinkedConst(variable.constExpr, | 2141 _assertUnlinkedConst(variable.constExpr, |
| 2094 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']); | 2142 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']); |
| 2095 } | 2143 } |
| 2096 | 2144 |
| 2097 test_constExpr_pushString_adjacent_interpolation() { | 2145 test_constExpr_pushString_adjacent_interpolation() { |
| 2098 UnlinkedVariable variable = | 2146 UnlinkedVariable variable = |
| 2099 serializeVariableText(r'const v = "aaa" "bb ${42} bbb" "cccc";'); | 2147 serializeVariableText(r'const v = "aaa" "bb ${42} bbb" "cccc";'); |
| (...skipping 2603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4703 */ | 4751 */ |
| 4704 class _PrefixExpectation { | 4752 class _PrefixExpectation { |
| 4705 final ReferenceKind kind; | 4753 final ReferenceKind kind; |
| 4706 final String name; | 4754 final String name; |
| 4707 final bool inLibraryDefiningUnit; | 4755 final bool inLibraryDefiningUnit; |
| 4708 final int numTypeParameters; | 4756 final int numTypeParameters; |
| 4709 | 4757 |
| 4710 _PrefixExpectation(this.kind, this.name, | 4758 _PrefixExpectation(this.kind, this.name, |
| 4711 {this.inLibraryDefiningUnit: false, this.numTypeParameters: 0}); | 4759 {this.inLibraryDefiningUnit: false, this.numTypeParameters: 0}); |
| 4712 } | 4760 } |
| OLD | NEW |