| 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 import 'dart:async'; |
| 5 import 'dart:convert'; | 6 import 'dart:convert'; |
| 6 | 7 |
| 7 import 'package:analysis_server/src/services/index/index_unit.dart'; | 8 import 'package:analysis_server/src/services/index/index_unit.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/summary/format.dart'; | 11 import 'package:analyzer/src/summary/format.dart'; |
| 11 import 'package:analyzer/src/summary/idl.dart'; | 12 import 'package:analyzer/src/summary/idl.dart'; |
| 12 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 | 15 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 49 |
| 49 _NameIndexAssert assertThatName(String name) { | 50 _NameIndexAssert assertThatName(String name) { |
| 50 return new _NameIndexAssert(this, name); | 51 return new _NameIndexAssert(this, name); |
| 51 } | 52 } |
| 52 | 53 |
| 53 CompilationUnitElement importedUnit({int index: 0}) { | 54 CompilationUnitElement importedUnit({int index: 0}) { |
| 54 List<ImportElement> imports = testLibraryElement.imports; | 55 List<ImportElement> imports = testLibraryElement.imports; |
| 55 return imports[index].importedLibrary.definingCompilationUnit; | 56 return imports[index].importedLibrary.definingCompilationUnit; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void test_definedName_classMember_field() { | 59 test_definedName_classMember_field() async { |
| 59 _indexTestUnit(''' | 60 await _indexTestUnit(''' |
| 60 class A { | 61 class A { |
| 61 int f; | 62 int f; |
| 62 }'''); | 63 }'''); |
| 63 _assertDefinedName('f', IndexNameKind.classMember, 'f;'); | 64 _assertDefinedName('f', IndexNameKind.classMember, 'f;'); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void test_definedName_classMember_getter() { | 67 test_definedName_classMember_getter() async { |
| 67 _indexTestUnit(''' | 68 await _indexTestUnit(''' |
| 68 class A { | 69 class A { |
| 69 int get g => 0; | 70 int get g => 0; |
| 70 }'''); | 71 }'''); |
| 71 _assertDefinedName('g', IndexNameKind.classMember, 'g => 0;'); | 72 _assertDefinedName('g', IndexNameKind.classMember, 'g => 0;'); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void test_definedName_classMember_method() { | 75 test_definedName_classMember_method() async { |
| 75 _indexTestUnit(''' | 76 await _indexTestUnit(''' |
| 76 class A { | 77 class A { |
| 77 m() {} | 78 m() {} |
| 78 }'''); | 79 }'''); |
| 79 _assertDefinedName('m', IndexNameKind.classMember, 'm() {}'); | 80 _assertDefinedName('m', IndexNameKind.classMember, 'm() {}'); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void test_definedName_classMember_operator() { | 83 test_definedName_classMember_operator() async { |
| 83 _indexTestUnit(''' | 84 await _indexTestUnit(''' |
| 84 class A { | 85 class A { |
| 85 operator +(o) {} | 86 operator +(o) {} |
| 86 }'''); | 87 }'''); |
| 87 _assertDefinedName('+', IndexNameKind.classMember, '+(o) {}'); | 88 _assertDefinedName('+', IndexNameKind.classMember, '+(o) {}'); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void test_definedName_classMember_setter() { | 91 test_definedName_classMember_setter() async { |
| 91 _indexTestUnit(''' | 92 await _indexTestUnit(''' |
| 92 class A { | 93 class A { |
| 93 int set s (_) {} | 94 int set s (_) {} |
| 94 }'''); | 95 }'''); |
| 95 _assertDefinedName('s', IndexNameKind.classMember, 's (_) {}'); | 96 _assertDefinedName('s', IndexNameKind.classMember, 's (_) {}'); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void test_definedName_topLevel_class() { | 99 test_definedName_topLevel_class() async { |
| 99 _indexTestUnit('class A {}'); | 100 await _indexTestUnit('class A {}'); |
| 100 _assertDefinedName('A', IndexNameKind.topLevel, 'A {}'); | 101 _assertDefinedName('A', IndexNameKind.topLevel, 'A {}'); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void test_definedName_topLevel_class2() { | 104 test_definedName_topLevel_class2() async { |
| 104 _indexTestUnit('class A {}', declOnly: true); | 105 await _indexTestUnit('class A {}', declOnly: true); |
| 105 _assertDefinedName('A', IndexNameKind.topLevel, 'A {}'); | 106 _assertDefinedName('A', IndexNameKind.topLevel, 'A {}'); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void test_definedName_topLevel_classAlias() { | 109 test_definedName_topLevel_classAlias() async { |
| 109 _indexTestUnit(''' | 110 await _indexTestUnit(''' |
| 110 class M {} | 111 class M {} |
| 111 class C = Object with M;'''); | 112 class C = Object with M;'''); |
| 112 _assertDefinedName('C', IndexNameKind.topLevel, 'C ='); | 113 _assertDefinedName('C', IndexNameKind.topLevel, 'C ='); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void test_definedName_topLevel_enum() { | 116 test_definedName_topLevel_enum() async { |
| 116 _indexTestUnit('enum E {a, b, c}'); | 117 await _indexTestUnit('enum E {a, b, c}'); |
| 117 _assertDefinedName('E', IndexNameKind.topLevel, 'E {'); | 118 _assertDefinedName('E', IndexNameKind.topLevel, 'E {'); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void test_definedName_topLevel_function() { | 121 test_definedName_topLevel_function() async { |
| 121 _indexTestUnit('foo() {}'); | 122 await _indexTestUnit('foo() {}'); |
| 122 _assertDefinedName('foo', IndexNameKind.topLevel, 'foo() {}'); | 123 _assertDefinedName('foo', IndexNameKind.topLevel, 'foo() {}'); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void test_definedName_topLevel_functionTypeAlias() { | 126 test_definedName_topLevel_functionTypeAlias() async { |
| 126 _indexTestUnit('typedef F(int p);'); | 127 await _indexTestUnit('typedef F(int p);'); |
| 127 _assertDefinedName('F', IndexNameKind.topLevel, 'F(int p);'); | 128 _assertDefinedName('F', IndexNameKind.topLevel, 'F(int p);'); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void test_definedName_topLevel_getter() { | 131 test_definedName_topLevel_getter() async { |
| 131 _indexTestUnit(''' | 132 await _indexTestUnit(''' |
| 132 int get g => 0; | 133 int get g => 0; |
| 133 '''); | 134 '''); |
| 134 _assertDefinedName('g', IndexNameKind.topLevel, 'g => 0;'); | 135 _assertDefinedName('g', IndexNameKind.topLevel, 'g => 0;'); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void test_definedName_topLevel_setter() { | 138 test_definedName_topLevel_setter() async { |
| 138 _indexTestUnit(''' | 139 await _indexTestUnit(''' |
| 139 int set s (_) {} | 140 int set s (_) {} |
| 140 '''); | 141 '''); |
| 141 _assertDefinedName('s', IndexNameKind.topLevel, 's (_) {}'); | 142 _assertDefinedName('s', IndexNameKind.topLevel, 's (_) {}'); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void test_definedName_topLevel_topLevelVariable() { | 145 test_definedName_topLevel_topLevelVariable() async { |
| 145 _indexTestUnit('var V = 42;'); | 146 await _indexTestUnit('var V = 42;'); |
| 146 _assertDefinedName('V', IndexNameKind.topLevel, 'V = 42;'); | 147 _assertDefinedName('V', IndexNameKind.topLevel, 'V = 42;'); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void test_hasAncestor_ClassDeclaration() { | 150 test_hasAncestor_ClassDeclaration() async { |
| 150 _indexTestUnit(''' | 151 await _indexTestUnit(''' |
| 151 class A {} | 152 class A {} |
| 152 class B1 extends A {} | 153 class B1 extends A {} |
| 153 class B2 implements A {} | 154 class B2 implements A {} |
| 154 class C1 extends B1 {} | 155 class C1 extends B1 {} |
| 155 class C2 extends B2 {} | 156 class C2 extends B2 {} |
| 156 class C3 implements B1 {} | 157 class C3 implements B1 {} |
| 157 class C4 implements B2 {} | 158 class C4 implements B2 {} |
| 158 class M extends Object with A {} | 159 class M extends Object with A {} |
| 159 '''); | 160 '''); |
| 160 ClassElement classElementA = findElement("A"); | 161 ClassElement classElementA = findElement("A"); |
| 161 assertThat(classElementA) | 162 assertThat(classElementA) |
| 162 ..isAncestorOf('B1 extends A') | 163 ..isAncestorOf('B1 extends A') |
| 163 ..isAncestorOf('B2 implements A') | 164 ..isAncestorOf('B2 implements A') |
| 164 ..isAncestorOf('C1 extends B1') | 165 ..isAncestorOf('C1 extends B1') |
| 165 ..isAncestorOf('C2 extends B2') | 166 ..isAncestorOf('C2 extends B2') |
| 166 ..isAncestorOf('C3 implements B1') | 167 ..isAncestorOf('C3 implements B1') |
| 167 ..isAncestorOf('C4 implements B2') | 168 ..isAncestorOf('C4 implements B2') |
| 168 ..isAncestorOf('M extends Object with A'); | 169 ..isAncestorOf('M extends Object with A'); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void test_hasAncestor_ClassTypeAlias() { | 172 test_hasAncestor_ClassTypeAlias() async { |
| 172 _indexTestUnit(''' | 173 await _indexTestUnit(''' |
| 173 class A {} | 174 class A {} |
| 174 class B extends A {} | 175 class B extends A {} |
| 175 class C1 = Object with A; | 176 class C1 = Object with A; |
| 176 class C2 = Object with B; | 177 class C2 = Object with B; |
| 177 '''); | 178 '''); |
| 178 ClassElement classElementA = findElement('A'); | 179 ClassElement classElementA = findElement('A'); |
| 179 ClassElement classElementB = findElement('B'); | 180 ClassElement classElementB = findElement('B'); |
| 180 assertThat(classElementA) | 181 assertThat(classElementA) |
| 181 ..isAncestorOf('C1 = Object with A') | 182 ..isAncestorOf('C1 = Object with A') |
| 182 ..isAncestorOf('C2 = Object with B'); | 183 ..isAncestorOf('C2 = Object with B'); |
| 183 assertThat(classElementB)..isAncestorOf('C2 = Object with B'); | 184 assertThat(classElementB)..isAncestorOf('C2 = Object with B'); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void test_isExtendedBy_ClassDeclaration() { | 187 test_isExtendedBy_ClassDeclaration() async { |
| 187 _indexTestUnit(''' | 188 await _indexTestUnit(''' |
| 188 class A {} // 1 | 189 class A {} // 1 |
| 189 class B extends A {} // 2 | 190 class B extends A {} // 2 |
| 190 '''); | 191 '''); |
| 191 ClassElement elementA = findElement('A'); | 192 ClassElement elementA = findElement('A'); |
| 192 assertThat(elementA) | 193 assertThat(elementA) |
| 193 ..isExtendedAt('A {} // 2', false) | 194 ..isExtendedAt('A {} // 2', false) |
| 194 ..isReferencedAt('A {} // 2', false); | 195 ..isReferencedAt('A {} // 2', false); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void test_isExtendedBy_ClassDeclaration_isQualified() { | 198 test_isExtendedBy_ClassDeclaration_isQualified() async { |
| 198 addSource( | 199 addSource( |
| 199 '/lib.dart', | 200 '/lib.dart', |
| 200 ''' | 201 ''' |
| 201 class A {} | 202 class A {} |
| 202 '''); | 203 '''); |
| 203 _indexTestUnit(''' | 204 await _indexTestUnit(''' |
| 204 import 'lib.dart' as p; | 205 import 'lib.dart' as p; |
| 205 class B extends p.A {} // 2 | 206 class B extends p.A {} // 2 |
| 206 '''); | 207 '''); |
| 207 ClassElement elementA = importedUnit().getType('A'); | 208 ClassElement elementA = importedUnit().getType('A'); |
| 208 assertThat(elementA).isExtendedAt('A {} // 2', true); | 209 assertThat(elementA).isExtendedAt('A {} // 2', true); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void test_isExtendedBy_ClassDeclaration_Object() { | 212 test_isExtendedBy_ClassDeclaration_Object() async { |
| 212 _indexTestUnit(''' | 213 await _indexTestUnit(''' |
| 213 class A {} | 214 class A {} |
| 214 '''); | 215 '''); |
| 215 ClassElement elementA = findElement('A'); | 216 ClassElement elementA = findElement('A'); |
| 216 ClassElement elementObject = elementA.supertype.element; | 217 ClassElement elementObject = elementA.supertype.element; |
| 217 assertThat(elementObject).isExtendedAt('A {}', true, length: 0); | 218 assertThat(elementObject).isExtendedAt('A {}', true, length: 0); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void test_isExtendedBy_ClassTypeAlias() { | 221 test_isExtendedBy_ClassTypeAlias() async { |
| 221 _indexTestUnit(''' | 222 await _indexTestUnit(''' |
| 222 class A {} | 223 class A {} |
| 223 class B {} | 224 class B {} |
| 224 class C = A with B; | 225 class C = A with B; |
| 225 '''); | 226 '''); |
| 226 ClassElement elementA = findElement('A'); | 227 ClassElement elementA = findElement('A'); |
| 227 assertThat(elementA) | 228 assertThat(elementA) |
| 228 ..isExtendedAt('A with', false) | 229 ..isExtendedAt('A with', false) |
| 229 ..isReferencedAt('A with', false); | 230 ..isReferencedAt('A with', false); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void test_isExtendedBy_ClassTypeAlias_isQualified() { | 233 test_isExtendedBy_ClassTypeAlias_isQualified() async { |
| 233 addSource( | 234 addSource( |
| 234 '/lib.dart', | 235 '/lib.dart', |
| 235 ''' | 236 ''' |
| 236 class A {} | 237 class A {} |
| 237 '''); | 238 '''); |
| 238 _indexTestUnit(''' | 239 await _indexTestUnit(''' |
| 239 import 'lib.dart' as p; | 240 import 'lib.dart' as p; |
| 240 class B {} | 241 class B {} |
| 241 class C = p.A with B; | 242 class C = p.A with B; |
| 242 '''); | 243 '''); |
| 243 ClassElement elementA = importedUnit().getType('A'); | 244 ClassElement elementA = importedUnit().getType('A'); |
| 244 assertThat(elementA) | 245 assertThat(elementA) |
| 245 ..isExtendedAt('A with', true) | 246 ..isExtendedAt('A with', true) |
| 246 ..isReferencedAt('A with', true); | 247 ..isReferencedAt('A with', true); |
| 247 } | 248 } |
| 248 | 249 |
| 249 void test_isImplementedBy_ClassDeclaration() { | 250 test_isImplementedBy_ClassDeclaration() async { |
| 250 _indexTestUnit(''' | 251 await _indexTestUnit(''' |
| 251 class A {} // 1 | 252 class A {} // 1 |
| 252 class B implements A {} // 2 | 253 class B implements A {} // 2 |
| 253 '''); | 254 '''); |
| 254 ClassElement elementA = findElement('A'); | 255 ClassElement elementA = findElement('A'); |
| 255 assertThat(elementA) | 256 assertThat(elementA) |
| 256 ..isImplementedAt('A {} // 2', false) | 257 ..isImplementedAt('A {} // 2', false) |
| 257 ..isReferencedAt('A {} // 2', false); | 258 ..isReferencedAt('A {} // 2', false); |
| 258 } | 259 } |
| 259 | 260 |
| 260 void test_isImplementedBy_ClassDeclaration_isQualified() { | 261 test_isImplementedBy_ClassDeclaration_isQualified() async { |
| 261 addSource( | 262 addSource( |
| 262 '/lib.dart', | 263 '/lib.dart', |
| 263 ''' | 264 ''' |
| 264 class A {} | 265 class A {} |
| 265 '''); | 266 '''); |
| 266 _indexTestUnit(''' | 267 await _indexTestUnit(''' |
| 267 import 'lib.dart' as p; | 268 import 'lib.dart' as p; |
| 268 class B implements p.A {} // 2 | 269 class B implements p.A {} // 2 |
| 269 '''); | 270 '''); |
| 270 ClassElement elementA = importedUnit().getType('A'); | 271 ClassElement elementA = importedUnit().getType('A'); |
| 271 assertThat(elementA) | 272 assertThat(elementA) |
| 272 ..isImplementedAt('A {} // 2', true) | 273 ..isImplementedAt('A {} // 2', true) |
| 273 ..isReferencedAt('A {} // 2', true); | 274 ..isReferencedAt('A {} // 2', true); |
| 274 } | 275 } |
| 275 | 276 |
| 276 void test_isImplementedBy_ClassTypeAlias() { | 277 test_isImplementedBy_ClassTypeAlias() async { |
| 277 _indexTestUnit(''' | 278 await _indexTestUnit(''' |
| 278 class A {} // 1 | 279 class A {} // 1 |
| 279 class B {} // 2 | 280 class B {} // 2 |
| 280 class C = Object with A implements B; // 3 | 281 class C = Object with A implements B; // 3 |
| 281 '''); | 282 '''); |
| 282 ClassElement elementB = findElement('B'); | 283 ClassElement elementB = findElement('B'); |
| 283 assertThat(elementB) | 284 assertThat(elementB) |
| 284 ..isImplementedAt('B; // 3', false) | 285 ..isImplementedAt('B; // 3', false) |
| 285 ..isReferencedAt('B; // 3', false); | 286 ..isReferencedAt('B; // 3', false); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void test_isInvokedBy_FieldElement() { | 289 test_isInvokedBy_FieldElement() async { |
| 289 _indexTestUnit(''' | 290 await _indexTestUnit(''' |
| 290 class A { | 291 class A { |
| 291 var field; | 292 var field; |
| 292 main() { | 293 main() { |
| 293 this.field(); // q | 294 this.field(); // q |
| 294 field(); // nq | 295 field(); // nq |
| 295 } | 296 } |
| 296 }'''); | 297 }'''); |
| 297 FieldElement field = findElement('field'); | 298 FieldElement field = findElement('field'); |
| 298 assertThat(field.getter) | 299 assertThat(field.getter) |
| 299 ..isInvokedAt('field(); // q', true) | 300 ..isInvokedAt('field(); // q', true) |
| 300 ..isInvokedAt('field(); // nq', false); | 301 ..isInvokedAt('field(); // nq', false); |
| 301 } | 302 } |
| 302 | 303 |
| 303 void test_isInvokedBy_FunctionElement() { | 304 test_isInvokedBy_FunctionElement() async { |
| 304 addSource( | 305 addSource( |
| 305 '/lib.dart', | 306 '/lib.dart', |
| 306 ''' | 307 ''' |
| 307 library lib; | 308 library lib; |
| 308 foo() {} | 309 foo() {} |
| 309 '''); | 310 '''); |
| 310 _indexTestUnit(''' | 311 await _indexTestUnit(''' |
| 311 import 'lib.dart'; | 312 import 'lib.dart'; |
| 312 import 'lib.dart' as pref; | 313 import 'lib.dart' as pref; |
| 313 main() { | 314 main() { |
| 314 pref.foo(); // q | 315 pref.foo(); // q |
| 315 foo(); // nq | 316 foo(); // nq |
| 316 }'''); | 317 }'''); |
| 317 FunctionElement element = importedUnit().functions[0]; | 318 FunctionElement element = importedUnit().functions[0]; |
| 318 assertThat(element) | 319 assertThat(element) |
| 319 ..isInvokedAt('foo(); // q', true) | 320 ..isInvokedAt('foo(); // q', true) |
| 320 ..isInvokedAt('foo(); // nq', false); | 321 ..isInvokedAt('foo(); // nq', false); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void test_isInvokedBy_FunctionElement_synthetic_loadLibrary() { | 324 test_isInvokedBy_FunctionElement_synthetic_loadLibrary() async { |
| 324 verifyNoTestUnitErrors = false; | 325 verifyNoTestUnitErrors = false; |
| 325 _indexTestUnit(''' | 326 await _indexTestUnit(''' |
| 326 import 'dart:math' deferred as math; | 327 import 'dart:math' deferred as math; |
| 327 main() { | 328 main() { |
| 328 math.loadLibrary(); // 1 | 329 math.loadLibrary(); // 1 |
| 329 math.loadLibrary(); // 2 | 330 math.loadLibrary(); // 2 |
| 330 } | 331 } |
| 331 '''); | 332 '''); |
| 332 LibraryElement mathLib = testLibraryElement.imports[0].importedLibrary; | 333 LibraryElement mathLib = testLibraryElement.imports[0].importedLibrary; |
| 333 FunctionElement element = mathLib.loadLibraryFunction; | 334 FunctionElement element = mathLib.loadLibraryFunction; |
| 334 assertThat(element).isInvokedAt('loadLibrary(); // 1', true); | 335 assertThat(element).isInvokedAt('loadLibrary(); // 1', true); |
| 335 assertThat(element).isInvokedAt('loadLibrary(); // 2', true); | 336 assertThat(element).isInvokedAt('loadLibrary(); // 2', true); |
| 336 } | 337 } |
| 337 | 338 |
| 338 void test_isInvokedBy_MethodElement() { | 339 test_isInvokedBy_MethodElement() async { |
| 339 _indexTestUnit(''' | 340 await _indexTestUnit(''' |
| 340 class A { | 341 class A { |
| 341 foo() {} | 342 foo() {} |
| 342 main() { | 343 main() { |
| 343 this.foo(); // q | 344 this.foo(); // q |
| 344 foo(); // nq | 345 foo(); // nq |
| 345 } | 346 } |
| 346 }'''); | 347 }'''); |
| 347 Element element = findElement('foo'); | 348 Element element = findElement('foo'); |
| 348 assertThat(element) | 349 assertThat(element) |
| 349 ..isInvokedAt('foo(); // q', true) | 350 ..isInvokedAt('foo(); // q', true) |
| 350 ..isInvokedAt('foo(); // nq', false); | 351 ..isInvokedAt('foo(); // nq', false); |
| 351 } | 352 } |
| 352 | 353 |
| 353 void test_isInvokedBy_MethodElement_propagatedType() { | 354 test_isInvokedBy_MethodElement_propagatedType() async { |
| 354 _indexTestUnit(''' | 355 await _indexTestUnit(''' |
| 355 class A { | 356 class A { |
| 356 foo() {} | 357 foo() {} |
| 357 } | 358 } |
| 358 main() { | 359 main() { |
| 359 var a = new A(); | 360 var a = new A(); |
| 360 a.foo(); | 361 a.foo(); |
| 361 } | 362 } |
| 362 '''); | 363 '''); |
| 363 Element element = findElement('foo'); | 364 Element element = findElement('foo'); |
| 364 assertThat(element).isInvokedAt('foo();', true); | 365 assertThat(element).isInvokedAt('foo();', true); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void test_isInvokedBy_operator_binary() { | 368 test_isInvokedBy_operator_binary() async { |
| 368 _indexTestUnit(''' | 369 await _indexTestUnit(''' |
| 369 class A { | 370 class A { |
| 370 operator +(other) => this; | 371 operator +(other) => this; |
| 371 } | 372 } |
| 372 main(A a) { | 373 main(A a) { |
| 373 print(a + 1); | 374 print(a + 1); |
| 374 a += 2; | 375 a += 2; |
| 375 ++a; | 376 ++a; |
| 376 a++; | 377 a++; |
| 377 } | 378 } |
| 378 '''); | 379 '''); |
| 379 MethodElement element = findElement('+'); | 380 MethodElement element = findElement('+'); |
| 380 assertThat(element) | 381 assertThat(element) |
| 381 ..isInvokedAt('+ 1', true, length: 1) | 382 ..isInvokedAt('+ 1', true, length: 1) |
| 382 ..isInvokedAt('+= 2', true, length: 2) | 383 ..isInvokedAt('+= 2', true, length: 2) |
| 383 ..isInvokedAt('++a', true, length: 2) | 384 ..isInvokedAt('++a', true, length: 2) |
| 384 ..isInvokedAt('++;', true, length: 2); | 385 ..isInvokedAt('++;', true, length: 2); |
| 385 } | 386 } |
| 386 | 387 |
| 387 void test_isInvokedBy_operator_index() { | 388 test_isInvokedBy_operator_index() async { |
| 388 _indexTestUnit(''' | 389 await _indexTestUnit(''' |
| 389 class A { | 390 class A { |
| 390 operator [](i) => null; | 391 operator [](i) => null; |
| 391 operator []=(i, v) {} | 392 operator []=(i, v) {} |
| 392 } | 393 } |
| 393 main(A a) { | 394 main(A a) { |
| 394 print(a[0]); | 395 print(a[0]); |
| 395 a[1] = 42; | 396 a[1] = 42; |
| 396 } | 397 } |
| 397 '''); | 398 '''); |
| 398 MethodElement readElement = findElement('[]'); | 399 MethodElement readElement = findElement('[]'); |
| 399 MethodElement writeElement = findElement('[]='); | 400 MethodElement writeElement = findElement('[]='); |
| 400 assertThat(readElement).isInvokedAt('[0]', true, length: 1); | 401 assertThat(readElement).isInvokedAt('[0]', true, length: 1); |
| 401 assertThat(writeElement).isInvokedAt('[1]', true, length: 1); | 402 assertThat(writeElement).isInvokedAt('[1]', true, length: 1); |
| 402 } | 403 } |
| 403 | 404 |
| 404 void test_isInvokedBy_operator_prefix() { | 405 test_isInvokedBy_operator_prefix() async { |
| 405 _indexTestUnit(''' | 406 await _indexTestUnit(''' |
| 406 class A { | 407 class A { |
| 407 A operator ~() => this; | 408 A operator ~() => this; |
| 408 } | 409 } |
| 409 main(A a) { | 410 main(A a) { |
| 410 print(~a); | 411 print(~a); |
| 411 } | 412 } |
| 412 '''); | 413 '''); |
| 413 MethodElement element = findElement('~'); | 414 MethodElement element = findElement('~'); |
| 414 assertThat(element).isInvokedAt('~a', true, length: 1); | 415 assertThat(element).isInvokedAt('~a', true, length: 1); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void test_isInvokedBy_PropertyAccessorElement_getter() { | 418 test_isInvokedBy_PropertyAccessorElement_getter() async { |
| 418 _indexTestUnit(''' | 419 await _indexTestUnit(''' |
| 419 class A { | 420 class A { |
| 420 get ggg => null; | 421 get ggg => null; |
| 421 main() { | 422 main() { |
| 422 this.ggg(); // q | 423 this.ggg(); // q |
| 423 ggg(); // nq | 424 ggg(); // nq |
| 424 } | 425 } |
| 425 }'''); | 426 }'''); |
| 426 PropertyAccessorElement element = findElement('ggg', ElementKind.GETTER); | 427 PropertyAccessorElement element = findElement('ggg', ElementKind.GETTER); |
| 427 assertThat(element) | 428 assertThat(element) |
| 428 ..isInvokedAt('ggg(); // q', true) | 429 ..isInvokedAt('ggg(); // q', true) |
| 429 ..isInvokedAt('ggg(); // nq', false); | 430 ..isInvokedAt('ggg(); // nq', false); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void test_isMixedInBy_ClassDeclaration() { | 433 test_isMixedInBy_ClassDeclaration() async { |
| 433 _indexTestUnit(''' | 434 await _indexTestUnit(''' |
| 434 class A {} // 1 | 435 class A {} // 1 |
| 435 class B extends Object with A {} // 2 | 436 class B extends Object with A {} // 2 |
| 436 '''); | 437 '''); |
| 437 ClassElement elementA = findElement('A'); | 438 ClassElement elementA = findElement('A'); |
| 438 assertThat(elementA) | 439 assertThat(elementA) |
| 439 ..isMixedInAt('A {} // 2', false) | 440 ..isMixedInAt('A {} // 2', false) |
| 440 ..isReferencedAt('A {} // 2', false); | 441 ..isReferencedAt('A {} // 2', false); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void test_isMixedInBy_ClassDeclaration_isQualified() { | 444 test_isMixedInBy_ClassDeclaration_isQualified() async { |
| 444 addSource( | 445 addSource( |
| 445 '/lib.dart', | 446 '/lib.dart', |
| 446 ''' | 447 ''' |
| 447 class A {} | 448 class A {} |
| 448 '''); | 449 '''); |
| 449 _indexTestUnit(''' | 450 await _indexTestUnit(''' |
| 450 import 'lib.dart' as p; | 451 import 'lib.dart' as p; |
| 451 class B extends Object with p.A {} // 2 | 452 class B extends Object with p.A {} // 2 |
| 452 '''); | 453 '''); |
| 453 ClassElement elementA = importedUnit().getType('A'); | 454 ClassElement elementA = importedUnit().getType('A'); |
| 454 assertThat(elementA).isMixedInAt('A {} // 2', true); | 455 assertThat(elementA).isMixedInAt('A {} // 2', true); |
| 455 } | 456 } |
| 456 | 457 |
| 457 void test_isMixedInBy_ClassTypeAlias() { | 458 test_isMixedInBy_ClassTypeAlias() async { |
| 458 _indexTestUnit(''' | 459 await _indexTestUnit(''' |
| 459 class A {} // 1 | 460 class A {} // 1 |
| 460 class B = Object with A; // 2 | 461 class B = Object with A; // 2 |
| 461 '''); | 462 '''); |
| 462 ClassElement elementA = findElement('A'); | 463 ClassElement elementA = findElement('A'); |
| 463 assertThat(elementA).isMixedInAt('A; // 2', false); | 464 assertThat(elementA).isMixedInAt('A; // 2', false); |
| 464 } | 465 } |
| 465 | 466 |
| 466 void test_isReferencedBy_ClassElement() { | 467 test_isReferencedBy_ClassElement() async { |
| 467 _indexTestUnit(''' | 468 await _indexTestUnit(''' |
| 468 class A { | 469 class A { |
| 469 static var field; | 470 static var field; |
| 470 } | 471 } |
| 471 main(A p) { | 472 main(A p) { |
| 472 A v; | 473 A v; |
| 473 new A(); // 2 | 474 new A(); // 2 |
| 474 A.field = 1; | 475 A.field = 1; |
| 475 print(A.field); // 3 | 476 print(A.field); // 3 |
| 476 } | 477 } |
| 477 '''); | 478 '''); |
| 478 ClassElement element = findElement('A'); | 479 ClassElement element = findElement('A'); |
| 479 assertThat(element) | 480 assertThat(element) |
| 480 ..isReferencedAt('A p) {', false) | 481 ..isReferencedAt('A p) {', false) |
| 481 ..isReferencedAt('A v;', false) | 482 ..isReferencedAt('A v;', false) |
| 482 ..isReferencedAt('A(); // 2', false) | 483 ..isReferencedAt('A(); // 2', false) |
| 483 ..isReferencedAt('A.field = 1;', false) | 484 ..isReferencedAt('A.field = 1;', false) |
| 484 ..isReferencedAt('A.field); // 3', false); | 485 ..isReferencedAt('A.field); // 3', false); |
| 485 } | 486 } |
| 486 | 487 |
| 487 void test_isReferencedBy_ClassElement_invocation() { | 488 test_isReferencedBy_ClassElement_invocation() async { |
| 488 verifyNoTestUnitErrors = false; | 489 verifyNoTestUnitErrors = false; |
| 489 _indexTestUnit(''' | 490 await _indexTestUnit(''' |
| 490 class A {} | 491 class A {} |
| 491 main() { | 492 main() { |
| 492 A(); // invalid code, but still a reference | 493 A(); // invalid code, but still a reference |
| 493 }'''); | 494 }'''); |
| 494 Element element = findElement('A'); | 495 Element element = findElement('A'); |
| 495 assertThat(element).isReferencedAt('A();', false); | 496 assertThat(element).isReferencedAt('A();', false); |
| 496 } | 497 } |
| 497 | 498 |
| 498 void test_isReferencedBy_ClassElement_invocation_isQualified() { | 499 test_isReferencedBy_ClassElement_invocation_isQualified() async { |
| 499 verifyNoTestUnitErrors = false; | 500 verifyNoTestUnitErrors = false; |
| 500 addSource( | 501 addSource( |
| 501 '/lib.dart', | 502 '/lib.dart', |
| 502 ''' | 503 ''' |
| 503 class A {} | 504 class A {} |
| 504 '''); | 505 '''); |
| 505 _indexTestUnit(''' | 506 await _indexTestUnit(''' |
| 506 import 'lib.dart' as p; | 507 import 'lib.dart' as p; |
| 507 main() { | 508 main() { |
| 508 p.A(); // invalid code, but still a reference | 509 p.A(); // invalid code, but still a reference |
| 509 }'''); | 510 }'''); |
| 510 Element element = importedUnit().getType('A'); | 511 Element element = importedUnit().getType('A'); |
| 511 assertThat(element).isReferencedAt('A();', true); | 512 assertThat(element).isReferencedAt('A();', true); |
| 512 } | 513 } |
| 513 | 514 |
| 514 void test_isReferencedBy_ClassTypeAlias() { | 515 test_isReferencedBy_ClassTypeAlias() async { |
| 515 _indexTestUnit(''' | 516 await _indexTestUnit(''' |
| 516 class A {} | 517 class A {} |
| 517 class B = Object with A; | 518 class B = Object with A; |
| 518 main(B p) { | 519 main(B p) { |
| 519 B v; | 520 B v; |
| 520 } | 521 } |
| 521 '''); | 522 '''); |
| 522 ClassElement element = findElement('B'); | 523 ClassElement element = findElement('B'); |
| 523 assertThat(element) | 524 assertThat(element) |
| 524 ..isReferencedAt('B p) {', false) | 525 ..isReferencedAt('B p) {', false) |
| 525 ..isReferencedAt('B v;', false); | 526 ..isReferencedAt('B v;', false); |
| 526 } | 527 } |
| 527 | 528 |
| 528 void test_isReferencedBy_CompilationUnitElement_export() { | 529 test_isReferencedBy_CompilationUnitElement_export() async { |
| 529 addSource( | 530 addSource( |
| 530 '/lib.dart', | 531 '/lib.dart', |
| 531 ''' | 532 ''' |
| 532 library lib; | 533 library lib; |
| 533 '''); | 534 '''); |
| 534 _indexTestUnit(''' | 535 await _indexTestUnit(''' |
| 535 export 'lib.dart'; | 536 export 'lib.dart'; |
| 536 '''); | 537 '''); |
| 537 LibraryElement element = testLibraryElement.exports[0].exportedLibrary; | 538 LibraryElement element = testLibraryElement.exports[0].exportedLibrary; |
| 538 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); | 539 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); |
| 539 } | 540 } |
| 540 | 541 |
| 541 void test_isReferencedBy_CompilationUnitElement_import() { | 542 test_isReferencedBy_CompilationUnitElement_import() async { |
| 542 addSource( | 543 addSource( |
| 543 '/lib.dart', | 544 '/lib.dart', |
| 544 ''' | 545 ''' |
| 545 library lib; | 546 library lib; |
| 546 '''); | 547 '''); |
| 547 _indexTestUnit(''' | 548 await _indexTestUnit(''' |
| 548 import 'lib.dart'; | 549 import 'lib.dart'; |
| 549 '''); | 550 '''); |
| 550 LibraryElement element = testLibraryElement.imports[0].importedLibrary; | 551 LibraryElement element = testLibraryElement.imports[0].importedLibrary; |
| 551 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); | 552 assertThat(element)..isReferencedAt("'lib.dart'", true, length: 10); |
| 552 } | 553 } |
| 553 | 554 |
| 554 void test_isReferencedBy_CompilationUnitElement_part() { | 555 test_isReferencedBy_CompilationUnitElement_part() async { |
| 555 addSource('/my_unit.dart', 'part of my_lib;'); | 556 addSource('/my_unit.dart', 'part of my_lib;'); |
| 556 _indexTestUnit(''' | 557 await _indexTestUnit(''' |
| 557 library my_lib; | 558 library my_lib; |
| 558 part 'my_unit.dart'; | 559 part 'my_unit.dart'; |
| 559 '''); | 560 '''); |
| 560 CompilationUnitElement element = testLibraryElement.parts[0]; | 561 CompilationUnitElement element = testLibraryElement.parts[0]; |
| 561 assertThat(element)..isReferencedAt("'my_unit.dart';", true, length: 14); | 562 assertThat(element)..isReferencedAt("'my_unit.dart';", true, length: 14); |
| 562 } | 563 } |
| 563 | 564 |
| 564 void test_isReferencedBy_ConstructorElement() { | 565 test_isReferencedBy_ConstructorElement() async { |
| 565 _indexTestUnit(''' | 566 await _indexTestUnit(''' |
| 566 class A implements B { | 567 class A implements B { |
| 567 A() {} | 568 A() {} |
| 568 A.foo() {} | 569 A.foo() {} |
| 569 } | 570 } |
| 570 class B extends A { | 571 class B extends A { |
| 571 B() : super(); // 1 | 572 B() : super(); // 1 |
| 572 B.foo() : super.foo(); // 2 | 573 B.foo() : super.foo(); // 2 |
| 573 factory B.bar() = A.foo; // 3 | 574 factory B.bar() = A.foo; // 3 |
| 574 } | 575 } |
| 575 main() { | 576 main() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 586 ..isReferencedAt('(); // 1', true, length: 0) | 587 ..isReferencedAt('(); // 1', true, length: 0) |
| 587 ..isReferencedAt('(); // 4', true, length: 0); | 588 ..isReferencedAt('(); // 4', true, length: 0); |
| 588 // A.foo() | 589 // A.foo() |
| 589 assertThat(constA_foo) | 590 assertThat(constA_foo) |
| 590 ..hasRelationCount(3) | 591 ..hasRelationCount(3) |
| 591 ..isReferencedAt('.foo(); // 2', true, length: 4) | 592 ..isReferencedAt('.foo(); // 2', true, length: 4) |
| 592 ..isReferencedAt('.foo; // 3', true, length: 4) | 593 ..isReferencedAt('.foo; // 3', true, length: 4) |
| 593 ..isReferencedAt('.foo(); // 5', true, length: 4); | 594 ..isReferencedAt('.foo(); // 5', true, length: 4); |
| 594 } | 595 } |
| 595 | 596 |
| 596 void test_isReferencedBy_ConstructorElement_classTypeAlias() { | 597 test_isReferencedBy_ConstructorElement_classTypeAlias() async { |
| 597 _indexTestUnit(''' | 598 await _indexTestUnit(''' |
| 598 class M {} | 599 class M {} |
| 599 class A implements B { | 600 class A implements B { |
| 600 A() {} | 601 A() {} |
| 601 A.named() {} | 602 A.named() {} |
| 602 } | 603 } |
| 603 class B = A with M; | 604 class B = A with M; |
| 604 class C = B with M; | 605 class C = B with M; |
| 605 main() { | 606 main() { |
| 606 new B(); // B1 | 607 new B(); // B1 |
| 607 new B.named(); // B2 | 608 new B.named(); // B2 |
| 608 new C(); // C1 | 609 new C(); // C1 |
| 609 new C.named(); // C2 | 610 new C.named(); // C2 |
| 610 } | 611 } |
| 611 '''); | 612 '''); |
| 612 ClassElement classA = findElement('A'); | 613 ClassElement classA = findElement('A'); |
| 613 ConstructorElement constA = classA.constructors[0]; | 614 ConstructorElement constA = classA.constructors[0]; |
| 614 ConstructorElement constA_named = classA.constructors[1]; | 615 ConstructorElement constA_named = classA.constructors[1]; |
| 615 assertThat(constA) | 616 assertThat(constA) |
| 616 ..isReferencedAt('(); // B1', true, length: 0) | 617 ..isReferencedAt('(); // B1', true, length: 0) |
| 617 ..isReferencedAt('(); // C1', true, length: 0); | 618 ..isReferencedAt('(); // C1', true, length: 0); |
| 618 assertThat(constA_named) | 619 assertThat(constA_named) |
| 619 ..isReferencedAt('.named(); // B2', true, length: 6) | 620 ..isReferencedAt('.named(); // B2', true, length: 6) |
| 620 ..isReferencedAt('.named(); // C2', true, length: 6); | 621 ..isReferencedAt('.named(); // C2', true, length: 6); |
| 621 } | 622 } |
| 622 | 623 |
| 623 void test_isReferencedBy_ConstructorElement_classTypeAlias_cycle() { | 624 test_isReferencedBy_ConstructorElement_classTypeAlias_cycle() async { |
| 624 _indexTestUnit(''' | 625 await _indexTestUnit(''' |
| 625 class M {} | 626 class M {} |
| 626 class A = B with M; | 627 class A = B with M; |
| 627 class B = A with M; | 628 class B = A with M; |
| 628 main() { | 629 main() { |
| 629 new A(); | 630 new A(); |
| 630 new B(); | 631 new B(); |
| 631 } | 632 } |
| 632 '''); | 633 '''); |
| 633 // No additional validation, but it should not fail with stack overflow. | 634 // No additional validation, but it should not fail with stack overflow. |
| 634 } | 635 } |
| 635 | 636 |
| 636 void test_isReferencedBy_ConstructorElement_namedOnlyWithDot() { | 637 test_isReferencedBy_ConstructorElement_namedOnlyWithDot() async { |
| 637 _indexTestUnit(''' | 638 await _indexTestUnit(''' |
| 638 class A { | 639 class A { |
| 639 A.named() {} | 640 A.named() {} |
| 640 } | 641 } |
| 641 main() { | 642 main() { |
| 642 new A.named(); | 643 new A.named(); |
| 643 } | 644 } |
| 644 '''); | 645 '''); |
| 645 // has ".named()", but does not have "named()" | 646 // has ".named()", but does not have "named()" |
| 646 int offsetWithoutDot = findOffset('named();'); | 647 int offsetWithoutDot = findOffset('named();'); |
| 647 int offsetWithDot = findOffset('.named();'); | 648 int offsetWithDot = findOffset('.named();'); |
| 648 expect(unitIndex.usedElementOffsets, isNot(contains(offsetWithoutDot))); | 649 expect(unitIndex.usedElementOffsets, isNot(contains(offsetWithoutDot))); |
| 649 expect(unitIndex.usedElementOffsets, contains(offsetWithDot)); | 650 expect(unitIndex.usedElementOffsets, contains(offsetWithDot)); |
| 650 } | 651 } |
| 651 | 652 |
| 652 void test_isReferencedBy_ConstructorElement_redirection() { | 653 test_isReferencedBy_ConstructorElement_redirection() async { |
| 653 _indexTestUnit(''' | 654 await _indexTestUnit(''' |
| 654 class A { | 655 class A { |
| 655 A() : this.bar(); // 1 | 656 A() : this.bar(); // 1 |
| 656 A.foo() : this(); // 2 | 657 A.foo() : this(); // 2 |
| 657 A.bar(); | 658 A.bar(); |
| 658 } | 659 } |
| 659 '''); | 660 '''); |
| 660 ClassElement classA = findElement('A'); | 661 ClassElement classA = findElement('A'); |
| 661 ConstructorElement constA = classA.constructors[0]; | 662 ConstructorElement constA = classA.constructors[0]; |
| 662 ConstructorElement constA_bar = classA.constructors[2]; | 663 ConstructorElement constA_bar = classA.constructors[2]; |
| 663 assertThat(constA).isReferencedAt('(); // 2', true, length: 0); | 664 assertThat(constA).isReferencedAt('(); // 2', true, length: 0); |
| 664 assertThat(constA_bar).isReferencedAt('.bar(); // 1', true, length: 4); | 665 assertThat(constA_bar).isReferencedAt('.bar(); // 1', true, length: 4); |
| 665 } | 666 } |
| 666 | 667 |
| 667 void test_isReferencedBy_ConstructorElement_synthetic() { | 668 test_isReferencedBy_ConstructorElement_synthetic() async { |
| 668 _indexTestUnit(''' | 669 await _indexTestUnit(''' |
| 669 class A {} | 670 class A {} |
| 670 main() { | 671 main() { |
| 671 new A(); // 1 | 672 new A(); // 1 |
| 672 } | 673 } |
| 673 '''); | 674 '''); |
| 674 ClassElement classA = findElement('A'); | 675 ClassElement classA = findElement('A'); |
| 675 ConstructorElement constA = classA.constructors[0]; | 676 ConstructorElement constA = classA.constructors[0]; |
| 676 // A() | 677 // A() |
| 677 assertThat(constA)..isReferencedAt('(); // 1', true, length: 0); | 678 assertThat(constA)..isReferencedAt('(); // 1', true, length: 0); |
| 678 } | 679 } |
| 679 | 680 |
| 680 void test_isReferencedBy_DynamicElement() { | 681 test_isReferencedBy_DynamicElement() async { |
| 681 _indexTestUnit(''' | 682 await _indexTestUnit(''' |
| 682 dynamic f() { | 683 dynamic f() { |
| 683 }'''); | 684 }'''); |
| 684 expect(unitIndex.usedElementOffsets, isEmpty); | 685 expect(unitIndex.usedElementOffsets, isEmpty); |
| 685 } | 686 } |
| 686 | 687 |
| 687 void test_isReferencedBy_FieldElement() { | 688 test_isReferencedBy_FieldElement() async { |
| 688 _indexTestUnit(''' | 689 await _indexTestUnit(''' |
| 689 class A { | 690 class A { |
| 690 var field; | 691 var field; |
| 691 A({this.field}); | 692 A({this.field}); |
| 692 m() { | 693 m() { |
| 693 field = 2; // nq | 694 field = 2; // nq |
| 694 print(field); // nq | 695 print(field); // nq |
| 695 } | 696 } |
| 696 } | 697 } |
| 697 main(A a) { | 698 main(A a) { |
| 698 a.field = 3; // q | 699 a.field = 3; // q |
| 699 print(a.field); // q | 700 print(a.field); // q |
| 700 new A(field: 4); | 701 new A(field: 4); |
| 701 } | 702 } |
| 702 '''); | 703 '''); |
| 703 FieldElement field = findElement('field', ElementKind.FIELD); | 704 FieldElement field = findElement('field', ElementKind.FIELD); |
| 704 PropertyAccessorElement getter = field.getter; | 705 PropertyAccessorElement getter = field.getter; |
| 705 PropertyAccessorElement setter = field.setter; | 706 PropertyAccessorElement setter = field.setter; |
| 706 // A() | 707 // A() |
| 707 assertThat(field)..isWrittenAt('field});', true); | 708 assertThat(field)..isWrittenAt('field});', true); |
| 708 // m() | 709 // m() |
| 709 assertThat(setter)..isReferencedAt('field = 2; // nq', false); | 710 assertThat(setter)..isReferencedAt('field = 2; // nq', false); |
| 710 assertThat(getter)..isReferencedAt('field); // nq', false); | 711 assertThat(getter)..isReferencedAt('field); // nq', false); |
| 711 // main() | 712 // main() |
| 712 assertThat(setter)..isReferencedAt('field = 3; // q', true); | 713 assertThat(setter)..isReferencedAt('field = 3; // q', true); |
| 713 assertThat(getter)..isReferencedAt('field); // q', true); | 714 assertThat(getter)..isReferencedAt('field); // q', true); |
| 714 assertThat(field)..isReferencedAt('field: 4', true); | 715 assertThat(field)..isReferencedAt('field: 4', true); |
| 715 } | 716 } |
| 716 | 717 |
| 717 void test_isReferencedBy_FieldElement_multiple() { | 718 test_isReferencedBy_FieldElement_multiple() async { |
| 718 _indexTestUnit(''' | 719 await _indexTestUnit(''' |
| 719 class A { | 720 class A { |
| 720 var aaa; | 721 var aaa; |
| 721 var bbb; | 722 var bbb; |
| 722 A(this.aaa, this.bbb) {} | 723 A(this.aaa, this.bbb) {} |
| 723 m() { | 724 m() { |
| 724 print(aaa); | 725 print(aaa); |
| 725 aaa = 1; | 726 aaa = 1; |
| 726 print(bbb); | 727 print(bbb); |
| 727 bbb = 2; | 728 bbb = 2; |
| 728 } | 729 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 741 { | 742 { |
| 742 FieldElement field = findElement('bbb', ElementKind.FIELD); | 743 FieldElement field = findElement('bbb', ElementKind.FIELD); |
| 743 PropertyAccessorElement getter = field.getter; | 744 PropertyAccessorElement getter = field.getter; |
| 744 PropertyAccessorElement setter = field.setter; | 745 PropertyAccessorElement setter = field.setter; |
| 745 assertThat(field)..isWrittenAt('bbb) {}', true); | 746 assertThat(field)..isWrittenAt('bbb) {}', true); |
| 746 assertThat(getter)..isReferencedAt('bbb);', false); | 747 assertThat(getter)..isReferencedAt('bbb);', false); |
| 747 assertThat(setter)..isReferencedAt('bbb = 2;', false); | 748 assertThat(setter)..isReferencedAt('bbb = 2;', false); |
| 748 } | 749 } |
| 749 } | 750 } |
| 750 | 751 |
| 751 void test_isReferencedBy_FieldElement_ofEnum() { | 752 test_isReferencedBy_FieldElement_ofEnum() async { |
| 752 verifyNoTestUnitErrors = false; | 753 verifyNoTestUnitErrors = false; |
| 753 _indexTestUnit(''' | 754 await _indexTestUnit(''' |
| 754 enum MyEnum { | 755 enum MyEnum { |
| 755 A, B, C | 756 A, B, C |
| 756 } | 757 } |
| 757 main() { | 758 main() { |
| 758 print(MyEnum.values); | 759 print(MyEnum.values); |
| 759 print(MyEnum.A.index); | 760 print(MyEnum.A.index); |
| 760 print(MyEnum.A); | 761 print(MyEnum.A); |
| 761 print(MyEnum.B); | 762 print(MyEnum.B); |
| 762 } | 763 } |
| 763 '''); | 764 '''); |
| 764 ClassElement enumElement = findElement('MyEnum'); | 765 ClassElement enumElement = findElement('MyEnum'); |
| 765 assertThat(enumElement.getGetter('values')) | 766 assertThat(enumElement.getGetter('values')) |
| 766 ..isReferencedAt('values);', true); | 767 ..isReferencedAt('values);', true); |
| 767 assertThat(enumElement.getGetter('index'))..isReferencedAt('index);', true); | 768 assertThat(enumElement.getGetter('index'))..isReferencedAt('index);', true); |
| 768 assertThat(enumElement.getGetter('A'))..isReferencedAt('A);', true); | 769 assertThat(enumElement.getGetter('A'))..isReferencedAt('A);', true); |
| 769 assertThat(enumElement.getGetter('B'))..isReferencedAt('B);', true); | 770 assertThat(enumElement.getGetter('B'))..isReferencedAt('B);', true); |
| 770 } | 771 } |
| 771 | 772 |
| 772 void test_isReferencedBy_FieldElement_synthetic_hasGetter() { | 773 test_isReferencedBy_FieldElement_synthetic_hasGetter() async { |
| 773 verifyNoTestUnitErrors = false; | 774 verifyNoTestUnitErrors = false; |
| 774 _indexTestUnit(''' | 775 await _indexTestUnit(''' |
| 775 class A { | 776 class A { |
| 776 A() : f = 42; | 777 A() : f = 42; |
| 777 int get f => 0; | 778 int get f => 0; |
| 778 } | 779 } |
| 779 '''); | 780 '''); |
| 780 ClassElement element2 = findElement('A'); | 781 ClassElement element2 = findElement('A'); |
| 781 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); | 782 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); |
| 782 } | 783 } |
| 783 | 784 |
| 784 void test_isReferencedBy_FieldElement_synthetic_hasGetterSetter() { | 785 test_isReferencedBy_FieldElement_synthetic_hasGetterSetter() async { |
| 785 verifyNoTestUnitErrors = false; | 786 verifyNoTestUnitErrors = false; |
| 786 _indexTestUnit(''' | 787 await _indexTestUnit(''' |
| 787 class A { | 788 class A { |
| 788 A() : f = 42; | 789 A() : f = 42; |
| 789 int get f => 0; | 790 int get f => 0; |
| 790 set f(_) {} | 791 set f(_) {} |
| 791 } | 792 } |
| 792 '''); | 793 '''); |
| 793 ClassElement element2 = findElement('A'); | 794 ClassElement element2 = findElement('A'); |
| 794 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); | 795 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); |
| 795 } | 796 } |
| 796 | 797 |
| 797 void test_isReferencedBy_FieldElement_synthetic_hasSetter() { | 798 test_isReferencedBy_FieldElement_synthetic_hasSetter() async { |
| 798 verifyNoTestUnitErrors = false; | 799 verifyNoTestUnitErrors = false; |
| 799 _indexTestUnit(''' | 800 await _indexTestUnit(''' |
| 800 class A { | 801 class A { |
| 801 A() : f = 42; | 802 A() : f = 42; |
| 802 set f(_) {} | 803 set f(_) {} |
| 803 } | 804 } |
| 804 '''); | 805 '''); |
| 805 ClassElement element2 = findElement('A'); | 806 ClassElement element2 = findElement('A'); |
| 806 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); | 807 assertThat(element2.getField('f')).isWrittenAt('f = 42', true); |
| 807 } | 808 } |
| 808 | 809 |
| 809 void test_isReferencedBy_FunctionElement() { | 810 test_isReferencedBy_FunctionElement() async { |
| 810 _indexTestUnit(''' | 811 await _indexTestUnit(''' |
| 811 foo() {} | 812 foo() {} |
| 812 main() { | 813 main() { |
| 813 print(foo); | 814 print(foo); |
| 814 print(foo()); | 815 print(foo()); |
| 815 } | 816 } |
| 816 '''); | 817 '''); |
| 817 FunctionElement element = findElement('foo'); | 818 FunctionElement element = findElement('foo'); |
| 818 assertThat(element) | 819 assertThat(element) |
| 819 ..isReferencedAt('foo);', false) | 820 ..isReferencedAt('foo);', false) |
| 820 ..isInvokedAt('foo());', false); | 821 ..isInvokedAt('foo());', false); |
| 821 } | 822 } |
| 822 | 823 |
| 823 void test_isReferencedBy_FunctionElement_with_LibraryElement() { | 824 test_isReferencedBy_FunctionElement_with_LibraryElement() async { |
| 824 addSource( | 825 addSource( |
| 825 '/foo.dart', | 826 '/foo.dart', |
| 826 r''' | 827 r''' |
| 827 bar() {} | 828 bar() {} |
| 828 '''); | 829 '''); |
| 829 _indexTestUnit(''' | 830 await _indexTestUnit(''' |
| 830 import "foo.dart"; | 831 import "foo.dart"; |
| 831 main() { | 832 main() { |
| 832 bar(); | 833 bar(); |
| 833 } | 834 } |
| 834 '''); | 835 '''); |
| 835 LibraryElement fooLibrary = testLibraryElement.imports[0].importedLibrary; | 836 LibraryElement fooLibrary = testLibraryElement.imports[0].importedLibrary; |
| 836 assertThat(fooLibrary)..isReferencedAt('"foo.dart";', true, length: 10); | 837 assertThat(fooLibrary)..isReferencedAt('"foo.dart";', true, length: 10); |
| 837 { | 838 { |
| 838 FunctionElement bar = fooLibrary.definingCompilationUnit.functions[0]; | 839 FunctionElement bar = fooLibrary.definingCompilationUnit.functions[0]; |
| 839 assertThat(bar)..isInvokedAt('bar();', false); | 840 assertThat(bar)..isInvokedAt('bar();', false); |
| 840 } | 841 } |
| 841 } | 842 } |
| 842 | 843 |
| 843 void test_isReferencedBy_FunctionTypeAliasElement() { | 844 test_isReferencedBy_FunctionTypeAliasElement() async { |
| 844 _indexTestUnit(''' | 845 await _indexTestUnit(''' |
| 845 typedef A(); | 846 typedef A(); |
| 846 main(A p) { | 847 main(A p) { |
| 847 } | 848 } |
| 848 '''); | 849 '''); |
| 849 Element element = findElement('A'); | 850 Element element = findElement('A'); |
| 850 assertThat(element)..isReferencedAt('A p) {', false); | 851 assertThat(element)..isReferencedAt('A p) {', false); |
| 851 } | 852 } |
| 852 | 853 |
| 853 /** | 854 /** |
| 854 * There was a bug in the AST structure, when single [Comment] was cloned and | 855 * There was a bug in the AST structure, when single [Comment] was cloned and |
| 855 * assigned to both [FieldDeclaration] and [VariableDeclaration]. | 856 * assigned to both [FieldDeclaration] and [VariableDeclaration]. |
| 856 * | 857 * |
| 857 * This caused duplicate indexing. | 858 * This caused duplicate indexing. |
| 858 * Here we test that the problem is fixed one way or another. | 859 * Here we test that the problem is fixed one way or another. |
| 859 */ | 860 */ |
| 860 void test_isReferencedBy_identifierInComment() { | 861 test_isReferencedBy_identifierInComment() async { |
| 861 _indexTestUnit(''' | 862 await _indexTestUnit(''' |
| 862 class A {} | 863 class A {} |
| 863 /// [A] text | 864 /// [A] text |
| 864 var myVariable = null; | 865 var myVariable = null; |
| 865 '''); | 866 '''); |
| 866 Element element = findElement('A'); | 867 Element element = findElement('A'); |
| 867 assertThat(element)..isReferencedAt('A] text', false); | 868 assertThat(element)..isReferencedAt('A] text', false); |
| 868 } | 869 } |
| 869 | 870 |
| 870 void test_isReferencedBy_MethodElement() { | 871 test_isReferencedBy_MethodElement() async { |
| 871 _indexTestUnit(''' | 872 await _indexTestUnit(''' |
| 872 class A { | 873 class A { |
| 873 method() {} | 874 method() {} |
| 874 main() { | 875 main() { |
| 875 print(this.method); // q | 876 print(this.method); // q |
| 876 print(method); // nq | 877 print(method); // nq |
| 877 } | 878 } |
| 878 }'''); | 879 }'''); |
| 879 MethodElement element = findElement('method'); | 880 MethodElement element = findElement('method'); |
| 880 assertThat(element) | 881 assertThat(element) |
| 881 ..isReferencedAt('method); // q', true) | 882 ..isReferencedAt('method); // q', true) |
| 882 ..isReferencedAt('method); // nq', false); | 883 ..isReferencedAt('method); // nq', false); |
| 883 } | 884 } |
| 884 | 885 |
| 885 void test_isReferencedBy_ParameterElement() { | 886 test_isReferencedBy_ParameterElement() async { |
| 886 _indexTestUnit(''' | 887 await _indexTestUnit(''' |
| 887 foo({var p}) {} | 888 foo({var p}) {} |
| 888 main() { | 889 main() { |
| 889 foo(p: 1); | 890 foo(p: 1); |
| 890 } | 891 } |
| 891 '''); | 892 '''); |
| 892 Element element = findElement('p'); | 893 Element element = findElement('p'); |
| 893 assertThat(element)..isReferencedAt('p: 1', true); | 894 assertThat(element)..isReferencedAt('p: 1', true); |
| 894 } | 895 } |
| 895 | 896 |
| 896 void test_isReferencedBy_TopLevelVariableElement() { | 897 test_isReferencedBy_TopLevelVariableElement() async { |
| 897 addSource( | 898 addSource( |
| 898 '/lib.dart', | 899 '/lib.dart', |
| 899 ''' | 900 ''' |
| 900 library lib; | 901 library lib; |
| 901 var V; | 902 var V; |
| 902 '''); | 903 '''); |
| 903 _indexTestUnit(''' | 904 await _indexTestUnit(''' |
| 904 import 'lib.dart' show V; // imp | 905 import 'lib.dart' show V; // imp |
| 905 import 'lib.dart' as pref; | 906 import 'lib.dart' as pref; |
| 906 main() { | 907 main() { |
| 907 pref.V = 5; // q | 908 pref.V = 5; // q |
| 908 print(pref.V); // q | 909 print(pref.V); // q |
| 909 V = 5; // nq | 910 V = 5; // nq |
| 910 print(V); // nq | 911 print(V); // nq |
| 911 }'''); | 912 }'''); |
| 912 TopLevelVariableElement variable = importedUnit().topLevelVariables[0]; | 913 TopLevelVariableElement variable = importedUnit().topLevelVariables[0]; |
| 913 assertThat(variable)..isReferencedAt('V; // imp', true); | 914 assertThat(variable)..isReferencedAt('V; // imp', true); |
| 914 assertThat(variable.getter) | 915 assertThat(variable.getter) |
| 915 ..isReferencedAt('V); // q', true) | 916 ..isReferencedAt('V); // q', true) |
| 916 ..isReferencedAt('V); // nq', false); | 917 ..isReferencedAt('V); // nq', false); |
| 917 assertThat(variable.setter) | 918 assertThat(variable.setter) |
| 918 ..isReferencedAt('V = 5; // q', true) | 919 ..isReferencedAt('V = 5; // q', true) |
| 919 ..isReferencedAt('V = 5; // nq', false); | 920 ..isReferencedAt('V = 5; // nq', false); |
| 920 } | 921 } |
| 921 | 922 |
| 922 void test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() { | 923 test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() async
{ |
| 923 verifyNoTestUnitErrors = false; | 924 verifyNoTestUnitErrors = false; |
| 924 addSource( | 925 addSource( |
| 925 '/lib.dart', | 926 '/lib.dart', |
| 926 ''' | 927 ''' |
| 927 int get V => 0; | 928 int get V => 0; |
| 928 void set V(_) {} | 929 void set V(_) {} |
| 929 '''); | 930 '''); |
| 930 _indexTestUnit(''' | 931 await _indexTestUnit(''' |
| 931 import 'lib.dart' show V; | 932 import 'lib.dart' show V; |
| 932 '''); | 933 '''); |
| 933 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; | 934 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; |
| 934 assertThat(element).isReferencedAt('V;', true); | 935 assertThat(element).isReferencedAt('V;', true); |
| 935 } | 936 } |
| 936 | 937 |
| 937 void test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() { | 938 test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() async { |
| 938 verifyNoTestUnitErrors = false; | 939 verifyNoTestUnitErrors = false; |
| 939 addSource( | 940 addSource( |
| 940 '/lib.dart', | 941 '/lib.dart', |
| 941 ''' | 942 ''' |
| 942 void set V(_) {} | 943 void set V(_) {} |
| 943 '''); | 944 '''); |
| 944 _indexTestUnit(''' | 945 await _indexTestUnit(''' |
| 945 import 'lib.dart' show V; | 946 import 'lib.dart' show V; |
| 946 '''); | 947 '''); |
| 947 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; | 948 TopLevelVariableElement element = importedUnit().topLevelVariables[0]; |
| 948 assertThat(element).isReferencedAt('V;', true); | 949 assertThat(element).isReferencedAt('V;', true); |
| 949 } | 950 } |
| 950 | 951 |
| 951 void test_isReferencedBy_typeInVariableList() { | 952 test_isReferencedBy_typeInVariableList() async { |
| 952 _indexTestUnit(''' | 953 await _indexTestUnit(''' |
| 953 class A {} | 954 class A {} |
| 954 A myVariable = null; | 955 A myVariable = null; |
| 955 '''); | 956 '''); |
| 956 Element element = findElement('A'); | 957 Element element = findElement('A'); |
| 957 assertThat(element).isReferencedAt('A myVariable', false); | 958 assertThat(element).isReferencedAt('A myVariable', false); |
| 958 } | 959 } |
| 959 | 960 |
| 960 void test_isWrittenBy_FieldElement() { | 961 test_isWrittenBy_FieldElement() async { |
| 961 _indexTestUnit(''' | 962 await _indexTestUnit(''' |
| 962 class A { | 963 class A { |
| 963 int field; | 964 int field; |
| 964 A.foo({this.field}); | 965 A.foo({this.field}); |
| 965 A.bar() : field = 5; | 966 A.bar() : field = 5; |
| 966 } | 967 } |
| 967 '''); | 968 '''); |
| 968 FieldElement element = findElement('field', ElementKind.FIELD); | 969 FieldElement element = findElement('field', ElementKind.FIELD); |
| 969 assertThat(element) | 970 assertThat(element) |
| 970 ..isWrittenAt('field})', true) | 971 ..isWrittenAt('field})', true) |
| 971 ..isWrittenAt('field = 5', true); | 972 ..isWrittenAt('field = 5', true); |
| 972 } | 973 } |
| 973 | 974 |
| 974 void test_usedName_inLibraryIdentifier() { | 975 test_usedName_inLibraryIdentifier() async { |
| 975 verifyNoTestUnitErrors = false; | 976 verifyNoTestUnitErrors = false; |
| 976 _indexTestUnit(''' | 977 await _indexTestUnit(''' |
| 977 library aaa.bbb.ccc; | 978 library aaa.bbb.ccc; |
| 978 class C { | 979 class C { |
| 979 var bbb; | 980 var bbb; |
| 980 } | 981 } |
| 981 main(p) { | 982 main(p) { |
| 982 p.bbb = 1; | 983 p.bbb = 1; |
| 983 } | 984 } |
| 984 '''); | 985 '''); |
| 985 assertThatName('bbb') | 986 assertThatName('bbb') |
| 986 ..isNotUsed('bbb.ccc', IndexRelationKind.IS_READ_BY) | 987 ..isNotUsed('bbb.ccc', IndexRelationKind.IS_READ_BY) |
| 987 ..isUsedQ('bbb = 1;', IndexRelationKind.IS_WRITTEN_BY); | 988 ..isUsedQ('bbb = 1;', IndexRelationKind.IS_WRITTEN_BY); |
| 988 } | 989 } |
| 989 | 990 |
| 990 void test_usedName_qualified_resolved() { | 991 test_usedName_qualified_resolved() async { |
| 991 verifyNoTestUnitErrors = false; | 992 verifyNoTestUnitErrors = false; |
| 992 _indexTestUnit(''' | 993 await _indexTestUnit(''' |
| 993 class C { | 994 class C { |
| 994 var x; | 995 var x; |
| 995 } | 996 } |
| 996 main(C c) { | 997 main(C c) { |
| 997 c.x; | 998 c.x; |
| 998 c.x = 1; | 999 c.x = 1; |
| 999 c.x += 2; | 1000 c.x += 2; |
| 1000 c.x(); | 1001 c.x(); |
| 1001 } | 1002 } |
| 1002 '''); | 1003 '''); |
| 1003 assertThatName('x') | 1004 assertThatName('x') |
| 1004 ..isNotUsedQ('x;', IndexRelationKind.IS_READ_BY) | 1005 ..isNotUsedQ('x;', IndexRelationKind.IS_READ_BY) |
| 1005 ..isNotUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 1006 ..isNotUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
| 1006 ..isNotUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) | 1007 ..isNotUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
| 1007 ..isNotUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); | 1008 ..isNotUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); |
| 1008 } | 1009 } |
| 1009 | 1010 |
| 1010 void test_usedName_qualified_unresolved() { | 1011 test_usedName_qualified_unresolved() async { |
| 1011 verifyNoTestUnitErrors = false; | 1012 verifyNoTestUnitErrors = false; |
| 1012 _indexTestUnit(''' | 1013 await _indexTestUnit(''' |
| 1013 main(p) { | 1014 main(p) { |
| 1014 p.x; | 1015 p.x; |
| 1015 p.x = 1; | 1016 p.x = 1; |
| 1016 p.x += 2; | 1017 p.x += 2; |
| 1017 p.x(); | 1018 p.x(); |
| 1018 } | 1019 } |
| 1019 '''); | 1020 '''); |
| 1020 assertThatName('x') | 1021 assertThatName('x') |
| 1021 ..isUsedQ('x;', IndexRelationKind.IS_READ_BY) | 1022 ..isUsedQ('x;', IndexRelationKind.IS_READ_BY) |
| 1022 ..isUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 1023 ..isUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
| 1023 ..isUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) | 1024 ..isUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
| 1024 ..isUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); | 1025 ..isUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); |
| 1025 } | 1026 } |
| 1026 | 1027 |
| 1027 void test_usedName_unqualified_resolved() { | 1028 test_usedName_unqualified_resolved() async { |
| 1028 verifyNoTestUnitErrors = false; | 1029 verifyNoTestUnitErrors = false; |
| 1029 _indexTestUnit(''' | 1030 await _indexTestUnit(''' |
| 1030 class C { | 1031 class C { |
| 1031 var x; | 1032 var x; |
| 1032 m() { | 1033 m() { |
| 1033 x; | 1034 x; |
| 1034 x = 1; | 1035 x = 1; |
| 1035 x += 2; | 1036 x += 2; |
| 1036 x(); | 1037 x(); |
| 1037 } | 1038 } |
| 1038 } | 1039 } |
| 1039 '''); | 1040 '''); |
| 1040 assertThatName('x') | 1041 assertThatName('x') |
| 1041 ..isNotUsedQ('x;', IndexRelationKind.IS_READ_BY) | 1042 ..isNotUsedQ('x;', IndexRelationKind.IS_READ_BY) |
| 1042 ..isNotUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 1043 ..isNotUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
| 1043 ..isNotUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) | 1044 ..isNotUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
| 1044 ..isNotUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); | 1045 ..isNotUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 void test_usedName_unqualified_unresolved() { | 1048 test_usedName_unqualified_unresolved() async { |
| 1048 verifyNoTestUnitErrors = false; | 1049 verifyNoTestUnitErrors = false; |
| 1049 _indexTestUnit(''' | 1050 await _indexTestUnit(''' |
| 1050 main() { | 1051 main() { |
| 1051 x; | 1052 x; |
| 1052 x = 1; | 1053 x = 1; |
| 1053 x += 2; | 1054 x += 2; |
| 1054 x(); | 1055 x(); |
| 1055 } | 1056 } |
| 1056 '''); | 1057 '''); |
| 1057 assertThatName('x') | 1058 assertThatName('x') |
| 1058 ..isUsed('x;', IndexRelationKind.IS_READ_BY) | 1059 ..isUsed('x;', IndexRelationKind.IS_READ_BY) |
| 1059 ..isUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 1060 ..isUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 } | 1211 } |
| 1211 _failWithIndexDump('Unit $unitElement of $element is not referenced'); | 1212 _failWithIndexDump('Unit $unitElement of $element is not referenced'); |
| 1212 return -1; | 1213 return -1; |
| 1213 } | 1214 } |
| 1214 | 1215 |
| 1215 int _getUriId(Uri uri) { | 1216 int _getUriId(Uri uri) { |
| 1216 String str = uri.toString(); | 1217 String str = uri.toString(); |
| 1217 return _getStringId(str); | 1218 return _getStringId(str); |
| 1218 } | 1219 } |
| 1219 | 1220 |
| 1220 void _indexTestUnit(String code, {bool declOnly: false}) { | 1221 Future<Null> _indexTestUnit(String code, {bool declOnly: false}) async { |
| 1221 resolveTestUnit(code); | 1222 await resolveTestUnit(code); |
| 1222 PackageIndexAssembler assembler = new PackageIndexAssembler(); | 1223 PackageIndexAssembler assembler = new PackageIndexAssembler(); |
| 1223 if (declOnly) { | 1224 if (declOnly) { |
| 1224 assembler.indexDeclarations(testUnit); | 1225 assembler.indexDeclarations(testUnit); |
| 1225 } else { | 1226 } else { |
| 1226 assembler.indexUnit(testUnit); | 1227 assembler.indexUnit(testUnit); |
| 1227 } | 1228 } |
| 1228 // assemble, write and read | 1229 // assemble, write and read |
| 1229 PackageIndexBuilder indexBuilder = assembler.assemble(); | 1230 PackageIndexBuilder indexBuilder = assembler.assemble(); |
| 1230 List<int> indexBytes = indexBuilder.toBuffer(); | 1231 List<int> indexBytes = indexBuilder.toBuffer(); |
| 1231 packageIndex = new PackageIndex.fromBuffer(indexBytes); | 1232 packageIndex = new PackageIndex.fromBuffer(indexBytes); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 final bool isQualified; | 1333 final bool isQualified; |
| 1333 | 1334 |
| 1334 _Relation(this.kind, this.offset, this.length, this.isQualified); | 1335 _Relation(this.kind, this.offset, this.length, this.isQualified); |
| 1335 | 1336 |
| 1336 @override | 1337 @override |
| 1337 String toString() { | 1338 String toString() { |
| 1338 return '_Relation{kind: $kind, offset: $offset, length: $length, ' | 1339 return '_Relation{kind: $kind, offset: $offset, length: $length, ' |
| 1339 'isQualified: $isQualified}'; | 1340 'isQualified: $isQualified}'; |
| 1340 } | 1341 } |
| 1341 } | 1342 } |
| OLD | NEW |