| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 import com.google.dart.engine.search.MatchQuality; | 50 import com.google.dart.engine.search.MatchQuality; |
| 51 import com.google.dart.engine.search.SearchEngine; | 51 import com.google.dart.engine.search.SearchEngine; |
| 52 import com.google.dart.engine.search.SearchEngineFactory; | 52 import com.google.dart.engine.search.SearchEngineFactory; |
| 53 import com.google.dart.engine.search.SearchFilter; | 53 import com.google.dart.engine.search.SearchFilter; |
| 54 import com.google.dart.engine.search.SearchListener; | 54 import com.google.dart.engine.search.SearchListener; |
| 55 import com.google.dart.engine.search.SearchMatch; | 55 import com.google.dart.engine.search.SearchMatch; |
| 56 import com.google.dart.engine.search.SearchPattern; | 56 import com.google.dart.engine.search.SearchPattern; |
| 57 import com.google.dart.engine.search.SearchPatternFactory; | 57 import com.google.dart.engine.search.SearchPatternFactory; |
| 58 import com.google.dart.engine.search.SearchScope; | 58 import com.google.dart.engine.search.SearchScope; |
| 59 import com.google.dart.engine.search.SearchScopeFactory; | 59 import com.google.dart.engine.search.SearchScopeFactory; |
| 60 import com.google.dart.engine.source.Source; |
| 60 import com.google.dart.engine.type.Type; | 61 import com.google.dart.engine.type.Type; |
| 61 import com.google.dart.engine.utilities.source.SourceRange; | 62 import com.google.dart.engine.utilities.source.SourceRange; |
| 62 | 63 |
| 63 import static org.fest.assertions.Assertions.assertThat; | 64 import static org.fest.assertions.Assertions.assertThat; |
| 64 import static org.mockito.Mockito.mock; | 65 import static org.mockito.Mockito.mock; |
| 65 import static org.mockito.Mockito.when; | 66 import static org.mockito.Mockito.when; |
| 66 | 67 |
| 67 import java.util.List; | 68 import java.util.List; |
| 68 import java.util.Set; | 69 import java.util.Set; |
| 69 import java.util.concurrent.CountDownLatch; | 70 import java.util.concurrent.CountDownLatch; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 found = true; | 119 found = true; |
| 119 break; | 120 break; |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 if (!found) { | 123 if (!found) { |
| 123 fail("Not found: " + msg); | 124 fail("Not found: " + msg); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 private static <T extends Element> T mock2(Class<T> clazz, ElementKind kind) { | 129 private final IndexStore indexStore = IndexFactory.newMemoryIndexStore(); |
| 129 T element = mock(clazz); | |
| 130 when(element.getContext()).thenReturn(CONTEXT); | |
| 131 when(element.getKind()).thenReturn(kind); | |
| 132 return element; | |
| 133 } | |
| 134 | 130 |
| 135 private final IndexStore indexStore = IndexFactory.newMemoryIndexStore(); | |
| 136 private static final AnalysisContext CONTEXT = mock(AnalysisContext.class); | 131 private static final AnalysisContext CONTEXT = mock(AnalysisContext.class); |
| 137 private SearchScope scope; | 132 private SearchScope scope; |
| 138 private SearchPattern pattern = null; | 133 private SearchPattern pattern = null; |
| 139 private SearchFilter filter = null; | 134 private SearchFilter filter = null; |
| 135 private final Source source = mock(Source.class); |
| 140 private final Element elementA = mock(Element.class); | 136 private final Element elementA = mock(Element.class); |
| 141 private final Element elementB = mock(Element.class); | 137 private final Element elementB = mock(Element.class); |
| 142 private final Element elementC = mock(Element.class); | 138 private final Element elementC = mock(Element.class); |
| 143 private final Element elementD = mock(Element.class); | 139 private final Element elementD = mock(Element.class); |
| 144 private final Element elementE = mock(Element.class); | 140 private final Element elementE = mock(Element.class); |
| 145 | 141 |
| 146 public void test_searchAssignedTypes_assignments() throws Exception { | 142 public void test_searchAssignedTypes_assignments() throws Exception { |
| 147 final PropertyAccessorElement setterElement = mock2( | 143 final PropertyAccessorElement setterElement = mockElement( |
| 148 PropertyAccessorElement.class, | 144 PropertyAccessorElement.class, |
| 149 ElementKind.SETTER); | 145 ElementKind.SETTER); |
| 150 final FieldElement fieldElement = mock2(FieldElement.class, ElementKind.FIEL
D); | 146 final FieldElement fieldElement = mockElement(FieldElement.class, ElementKin
d.FIELD); |
| 151 when(fieldElement.getSetter()).thenReturn(setterElement); | 147 when(fieldElement.getSetter()).thenReturn(setterElement); |
| 152 final Type typeA = mock(Type.class); | 148 final Type typeA = mock(Type.class); |
| 153 final Type typeB = mock(Type.class); | 149 final Type typeB = mock(Type.class); |
| 154 final Type typeC = mock(Type.class); | 150 final Type typeC = mock(Type.class); |
| 155 { | 151 { |
| 156 Location location = new Location(elementA, 1, 10); | 152 Location location = new Location(elementA, 1, 10); |
| 157 location = new LocationWithData<Type>(location, typeA); | 153 location = new LocationWithData<Type>(location, typeA); |
| 158 indexStore.recordRelationship( | 154 indexStore.recordRelationship( |
| 159 setterElement, | 155 setterElement, |
| 160 IndexConstants.IS_REFERENCED_BY_QUALIFIED, | 156 IndexConstants.IS_REFERENCED_BY_QUALIFIED, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 public boolean encloses(Element element) { | 191 public boolean encloses(Element element) { |
| 196 return element != elementC; | 192 return element != elementC; |
| 197 } | 193 } |
| 198 }); | 194 }); |
| 199 } | 195 } |
| 200 }); | 196 }); |
| 201 assertThat(types).containsOnly(typeA, typeB); | 197 assertThat(types).containsOnly(typeA, typeB); |
| 202 } | 198 } |
| 203 | 199 |
| 204 public void test_searchAssignedTypes_initializers() throws Exception { | 200 public void test_searchAssignedTypes_initializers() throws Exception { |
| 205 final FieldElement fieldElement = mock2(FieldElement.class, ElementKind.FIEL
D); | 201 final FieldElement fieldElement = mockElement(FieldElement.class, ElementKin
d.FIELD); |
| 206 final Type typeA = mock(Type.class); | 202 final Type typeA = mock(Type.class); |
| 207 final Type typeB = mock(Type.class); | 203 final Type typeB = mock(Type.class); |
| 208 { | 204 { |
| 209 Location location = new Location(elementA, 10, 1); | 205 Location location = new Location(elementA, 10, 1); |
| 210 location = new LocationWithData<Type>(location, typeA); | 206 location = new LocationWithData<Type>(location, typeA); |
| 211 indexStore.recordRelationship(fieldElement, IndexConstants.IS_DEFINED_BY,
location); | 207 indexStore.recordRelationship(fieldElement, IndexConstants.IS_DEFINED_BY,
location); |
| 212 } | 208 } |
| 213 { | 209 { |
| 214 Location location = new Location(elementB, 20, 1); | 210 Location location = new Location(elementB, 20, 1); |
| 215 location = new LocationWithData<Type>(location, typeB); | 211 location = new LocationWithData<Type>(location, typeB); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 245 } | 241 } |
| 246 }); | 242 }); |
| 247 // verify | 243 // verify |
| 248 assertMatches( | 244 assertMatches( |
| 249 matches, | 245 matches, |
| 250 new ExpectedMatch(elementA, MatchKind.NAME_DECLARATION, 1, 2), | 246 new ExpectedMatch(elementA, MatchKind.NAME_DECLARATION, 1, 2), |
| 251 new ExpectedMatch(elementB, MatchKind.NAME_DECLARATION, 10, 20)); | 247 new ExpectedMatch(elementB, MatchKind.NAME_DECLARATION, 10, 20)); |
| 252 } | 248 } |
| 253 | 249 |
| 254 public void test_searchFunctionDeclarations() throws Exception { | 250 public void test_searchFunctionDeclarations() throws Exception { |
| 255 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 251 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 256 defineFunctionsAB(library); | 252 defineFunctionsAB(library); |
| 257 scope = new LibrarySearchScope(library); | 253 scope = new LibrarySearchScope(library); |
| 258 // search matches | 254 // search matches |
| 259 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 255 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 260 // verify | 256 // verify |
| 261 assertMatches( | 257 assertMatches( |
| 262 matches, | 258 matches, |
| 263 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), | 259 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), |
| 264 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); | 260 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); |
| 265 } | 261 } |
| 266 | 262 |
| 267 public void test_searchFunctionDeclarations_async() throws Exception { | 263 public void test_searchFunctionDeclarations_async() throws Exception { |
| 268 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 264 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 269 defineFunctionsAB(library); | 265 defineFunctionsAB(library); |
| 270 scope = new LibrarySearchScope(library); | 266 scope = new LibrarySearchScope(library); |
| 271 // search matches | 267 // search matches |
| 272 List<SearchMatch> matches = searchFunctionDeclarationsAsync(); | 268 List<SearchMatch> matches = searchFunctionDeclarationsAsync(); |
| 273 // verify | 269 // verify |
| 274 assertMatches( | 270 assertMatches( |
| 275 matches, | 271 matches, |
| 276 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), | 272 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), |
| 277 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); | 273 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); |
| 278 } | 274 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 296 // search matches | 292 // search matches |
| 297 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 293 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 298 // verify | 294 // verify |
| 299 assertMatches( | 295 assertMatches( |
| 300 matches, | 296 matches, |
| 301 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), | 297 new ExpectedMatch(elementA, MatchKind.FUNCTION_DECLARATION, 1, 2), |
| 302 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); | 298 new ExpectedMatch(elementB, MatchKind.FUNCTION_DECLARATION, 10, 20)); |
| 303 } | 299 } |
| 304 | 300 |
| 305 public void test_searchFunctionDeclarations_useFilter() throws Exception { | 301 public void test_searchFunctionDeclarations_useFilter() throws Exception { |
| 306 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 302 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 307 defineFunctionsAB(library); | 303 defineFunctionsAB(library); |
| 308 scope = new LibrarySearchScope(library); | 304 scope = new LibrarySearchScope(library); |
| 309 // search "elementA" | 305 // search "elementA" |
| 310 { | 306 { |
| 311 filter = new SearchFilter() { | 307 filter = new SearchFilter() { |
| 312 @Override | 308 @Override |
| 313 public boolean passes(SearchMatch match) { | 309 public boolean passes(SearchMatch match) { |
| 314 return match.getElement() == elementA; | 310 return match.getElement() == elementA; |
| 315 } | 311 } |
| 316 }; | 312 }; |
| 317 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 313 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 318 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_DECL
ARATION, 1, 2)); | 314 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_DECL
ARATION, 1, 2)); |
| 319 } | 315 } |
| 320 // search "elementB" | 316 // search "elementB" |
| 321 { | 317 { |
| 322 filter = new SearchFilter() { | 318 filter = new SearchFilter() { |
| 323 @Override | 319 @Override |
| 324 public boolean passes(SearchMatch match) { | 320 public boolean passes(SearchMatch match) { |
| 325 return match.getElement() == elementB; | 321 return match.getElement() == elementB; |
| 326 } | 322 } |
| 327 }; | 323 }; |
| 328 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 324 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 329 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.FUNCTION_DECL
ARATION, 10, 20)); | 325 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.FUNCTION_DECL
ARATION, 10, 20)); |
| 330 } | 326 } |
| 331 } | 327 } |
| 332 | 328 |
| 333 public void test_searchFunctionDeclarations_usePattern() throws Exception { | 329 public void test_searchFunctionDeclarations_usePattern() throws Exception { |
| 334 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 330 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 335 defineFunctionsAB(library); | 331 defineFunctionsAB(library); |
| 336 scope = new LibrarySearchScope(library); | 332 scope = new LibrarySearchScope(library); |
| 337 // search "A" | 333 // search "A" |
| 338 { | 334 { |
| 339 pattern = SearchPatternFactory.createExactPattern("A", true); | 335 pattern = SearchPatternFactory.createExactPattern("A", true); |
| 340 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 336 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 341 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_DECL
ARATION, 1, 2)); | 337 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_DECL
ARATION, 1, 2)); |
| 342 } | 338 } |
| 343 // search "B" | 339 // search "B" |
| 344 { | 340 { |
| 345 pattern = SearchPatternFactory.createExactPattern("B", true); | 341 pattern = SearchPatternFactory.createExactPattern("B", true); |
| 346 List<SearchMatch> matches = searchFunctionDeclarationsSync(); | 342 List<SearchMatch> matches = searchFunctionDeclarationsSync(); |
| 347 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.FUNCTION_DECL
ARATION, 10, 20)); | 343 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.FUNCTION_DECL
ARATION, 10, 20)); |
| 348 } | 344 } |
| 349 } | 345 } |
| 350 | 346 |
| 351 public void test_searchReferences_ClassElement() throws Exception { | 347 public void test_searchReferences_ClassElement() throws Exception { |
| 352 ClassElement referencedElement = mock2(ClassElement.class, ElementKind.CLASS
); | 348 ClassElement referencedElement = mockElement(ClassElement.class, ElementKind
.CLASS); |
| 353 { | 349 { |
| 354 Location locationA = new Location(elementA, 1, 2); | 350 Location locationA = new Location(elementA, 1, 2); |
| 355 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); | 351 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); |
| 356 } | 352 } |
| 357 { | 353 { |
| 358 Location locationB = new Location(elementB, 10, 20); | 354 Location locationB = new Location(elementB, 10, 20); |
| 359 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); | 355 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); |
| 360 } | 356 } |
| 361 // search matches | 357 // search matches |
| 362 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 358 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 363 // verify | 359 // verify |
| 364 assertMatches( | 360 assertMatches( |
| 365 matches, | 361 matches, |
| 366 new ExpectedMatch(elementA, MatchKind.TYPE_REFERENCE, 1, 2), | 362 new ExpectedMatch(elementA, MatchKind.TYPE_REFERENCE, 1, 2), |
| 367 new ExpectedMatch(elementB, MatchKind.TYPE_REFERENCE, 10, 20)); | 363 new ExpectedMatch(elementB, MatchKind.TYPE_REFERENCE, 10, 20)); |
| 368 } | 364 } |
| 369 | 365 |
| 370 public void test_searchReferences_ClassElement_useScope() throws Exception { | 366 public void test_searchReferences_ClassElement_useScope() throws Exception { |
| 371 LibraryElement libraryA = mock2(LibraryElement.class, ElementKind.LIBRARY); | 367 LibraryElement libraryA = mockElement(LibraryElement.class, ElementKind.LIBR
ARY); |
| 372 LibraryElement libraryB = mock2(LibraryElement.class, ElementKind.LIBRARY); | 368 LibraryElement libraryB = mockElement(LibraryElement.class, ElementKind.LIBR
ARY); |
| 373 ClassElement referencedElement = mock2(ClassElement.class, ElementKind.CLASS
); | 369 ClassElement referencedElement = mockElement(ClassElement.class, ElementKind
.CLASS); |
| 374 { | 370 { |
| 375 when(elementA.getAncestor(LibraryElement.class)).thenReturn(libraryA); | 371 when(elementA.getAncestor(LibraryElement.class)).thenReturn(libraryA); |
| 376 Location locationA = new Location(elementA, 1, 2); | 372 Location locationA = new Location(elementA, 1, 2); |
| 377 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); | 373 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); |
| 378 } | 374 } |
| 379 { | 375 { |
| 380 when(elementB.getAncestor(LibraryElement.class)).thenReturn(libraryB); | 376 when(elementB.getAncestor(LibraryElement.class)).thenReturn(libraryB); |
| 381 Location locationB = new Location(elementB, 10, 20); | 377 Location locationB = new Location(elementB, 10, 20); |
| 382 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); | 378 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); |
| 383 } | 379 } |
| 384 // search matches, in "libraryA" | 380 // search matches, in "libraryA" |
| 385 scope = SearchScopeFactory.createLibraryScope(libraryA); | 381 scope = SearchScopeFactory.createLibraryScope(libraryA); |
| 386 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 382 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 387 // verify | 383 // verify |
| 388 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.TYPE_REFERENCE,
1, 2)); | 384 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.TYPE_REFERENCE,
1, 2)); |
| 389 } | 385 } |
| 390 | 386 |
| 391 public void test_searchReferences_CompilationUnitElement() throws Exception { | 387 public void test_searchReferences_CompilationUnitElement() throws Exception { |
| 392 CompilationUnitElement referencedElement = mock2( | 388 CompilationUnitElement referencedElement = mockElement( |
| 393 CompilationUnitElement.class, | 389 CompilationUnitElement.class, |
| 394 ElementKind.COMPILATION_UNIT); | 390 ElementKind.COMPILATION_UNIT); |
| 395 { | 391 { |
| 396 Location location = new Location(elementA, 1, 2); | 392 Location location = new Location(elementA, 1, 2); |
| 397 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 393 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 398 } | 394 } |
| 399 // search matches | 395 // search matches |
| 400 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 396 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 401 // verify | 397 // verify |
| 402 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.UNIT_REFERENCE,
1, 2)); | 398 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.UNIT_REFERENCE,
1, 2)); |
| 403 } | 399 } |
| 404 | 400 |
| 405 public void test_searchReferences_ConstructorElement() throws Exception { | 401 public void test_searchReferences_ConstructorElement() throws Exception { |
| 406 ConstructorElement referencedElement = mock2(ConstructorElement.class, Eleme
ntKind.CONSTRUCTOR); | 402 ConstructorElement referencedElement = mockElement( |
| 403 ConstructorElement.class, |
| 404 ElementKind.CONSTRUCTOR); |
| 407 { | 405 { |
| 408 Location location = new Location(elementA, 10, 1); | 406 Location location = new Location(elementA, 10, 1); |
| 409 indexStore.recordRelationship(referencedElement, IndexConstants.IS_DEFINED
_BY, location); | 407 indexStore.recordRelationship(referencedElement, IndexConstants.IS_DEFINED
_BY, location); |
| 410 } | 408 } |
| 411 { | 409 { |
| 412 Location location = new Location(elementB, 20, 2); | 410 Location location = new Location(elementB, 20, 2); |
| 413 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 411 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 414 } | 412 } |
| 415 { | 413 { |
| 416 Location location = new Location(elementC, 30, 3); | 414 Location location = new Location(elementC, 30, 3); |
| 417 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 415 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 418 } | 416 } |
| 419 // search matches | 417 // search matches |
| 420 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 418 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 421 // verify | 419 // verify |
| 422 assertMatches( | 420 assertMatches( |
| 423 matches, | 421 matches, |
| 424 new ExpectedMatch(elementA, MatchKind.CONSTRUCTOR_DECLARATION, 10, 1), | 422 new ExpectedMatch(elementA, MatchKind.CONSTRUCTOR_DECLARATION, 10, 1), |
| 425 new ExpectedMatch(elementB, MatchKind.CONSTRUCTOR_REFERENCE, 20, 2), | 423 new ExpectedMatch(elementB, MatchKind.CONSTRUCTOR_REFERENCE, 20, 2), |
| 426 new ExpectedMatch(elementC, MatchKind.CONSTRUCTOR_REFERENCE, 30, 3)); | 424 new ExpectedMatch(elementC, MatchKind.CONSTRUCTOR_REFERENCE, 30, 3)); |
| 427 } | 425 } |
| 428 | 426 |
| 429 public void test_searchReferences_Element_unknown() throws Exception { | 427 public void test_searchReferences_Element_unknown() throws Exception { |
| 430 List<SearchMatch> matches = searchReferencesSync(Element.class, null); | 428 List<SearchMatch> matches = searchReferencesSync(Element.class, null); |
| 431 assertThat(matches).isEmpty(); | 429 assertThat(matches).isEmpty(); |
| 432 } | 430 } |
| 433 | 431 |
| 434 public void test_searchReferences_FieldElement() throws Exception { | 432 public void test_searchReferences_FieldElement() throws Exception { |
| 435 PropertyAccessorElement getterElement = mock2(PropertyAccessorElement.class,
ElementKind.GETTER); | 433 PropertyAccessorElement getterElement = mockElement( |
| 436 PropertyAccessorElement setterElement = mock2(PropertyAccessorElement.class,
ElementKind.SETTER); | 434 PropertyAccessorElement.class, |
| 437 FieldElement fieldElement = mock2(FieldElement.class, ElementKind.FIELD); | 435 ElementKind.GETTER); |
| 436 PropertyAccessorElement setterElement = mockElement( |
| 437 PropertyAccessorElement.class, |
| 438 ElementKind.SETTER); |
| 439 FieldElement fieldElement = mockElement(FieldElement.class, ElementKind.FIEL
D); |
| 438 when(fieldElement.getGetter()).thenReturn(getterElement); | 440 when(fieldElement.getGetter()).thenReturn(getterElement); |
| 439 when(fieldElement.getSetter()).thenReturn(setterElement); | 441 when(fieldElement.getSetter()).thenReturn(setterElement); |
| 440 { | 442 { |
| 441 Location location = new Location(elementA, 1, 10); | 443 Location location = new Location(elementA, 1, 10); |
| 442 indexStore.recordRelationship( | 444 indexStore.recordRelationship( |
| 443 getterElement, | 445 getterElement, |
| 444 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, | 446 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, |
| 445 location); | 447 location); |
| 446 } | 448 } |
| 447 { | 449 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 470 // verify | 472 // verify |
| 471 assertMatches( | 473 assertMatches( |
| 472 matches, | 474 matches, |
| 473 new ExpectedMatch(elementA, MatchKind.FIELD_READ, 1, 10, false), | 475 new ExpectedMatch(elementA, MatchKind.FIELD_READ, 1, 10, false), |
| 474 new ExpectedMatch(elementB, MatchKind.FIELD_READ, 2, 20, true), | 476 new ExpectedMatch(elementB, MatchKind.FIELD_READ, 2, 20, true), |
| 475 new ExpectedMatch(elementC, MatchKind.FIELD_WRITE, 3, 30, false), | 477 new ExpectedMatch(elementC, MatchKind.FIELD_WRITE, 3, 30, false), |
| 476 new ExpectedMatch(elementD, MatchKind.FIELD_WRITE, 4, 40, true)); | 478 new ExpectedMatch(elementD, MatchKind.FIELD_WRITE, 4, 40, true)); |
| 477 } | 479 } |
| 478 | 480 |
| 479 public void test_searchReferences_FieldElement2() throws Exception { | 481 public void test_searchReferences_FieldElement2() throws Exception { |
| 480 FieldElement fieldElement = mock2(FieldElement.class, ElementKind.FIELD); | 482 FieldElement fieldElement = mockElement(FieldElement.class, ElementKind.FIEL
D); |
| 481 { | 483 { |
| 482 Location location = new Location(elementA, 1, 10); | 484 Location location = new Location(elementA, 1, 10); |
| 483 indexStore.recordRelationship(fieldElement, IndexConstants.IS_REFERENCED_B
Y, location); | 485 indexStore.recordRelationship(fieldElement, IndexConstants.IS_REFERENCED_B
Y, location); |
| 484 } | 486 } |
| 485 { | 487 { |
| 486 Location location = new Location(elementB, 2, 20); | 488 Location location = new Location(elementB, 2, 20); |
| 487 indexStore.recordRelationship( | 489 indexStore.recordRelationship( |
| 488 fieldElement, | 490 fieldElement, |
| 489 IndexConstants.IS_REFERENCED_BY_QUALIFIED, | 491 IndexConstants.IS_REFERENCED_BY_QUALIFIED, |
| 490 location); | 492 location); |
| 491 } | 493 } |
| 492 // search matches | 494 // search matches |
| 493 List<SearchMatch> matches = searchReferencesSync(Element.class, fieldElement
); | 495 List<SearchMatch> matches = searchReferencesSync(Element.class, fieldElement
); |
| 494 // verify | 496 // verify |
| 495 assertMatches( | 497 assertMatches( |
| 496 matches, | 498 matches, |
| 497 new ExpectedMatch(elementA, MatchKind.FIELD_REFERENCE, 1, 10, false), | 499 new ExpectedMatch(elementA, MatchKind.FIELD_REFERENCE, 1, 10, false), |
| 498 new ExpectedMatch(elementB, MatchKind.FIELD_REFERENCE, 2, 20, true)); | 500 new ExpectedMatch(elementB, MatchKind.FIELD_REFERENCE, 2, 20, true)); |
| 499 } | 501 } |
| 500 | 502 |
| 501 public void test_searchReferences_FunctionElement() throws Exception { | 503 public void test_searchReferences_FunctionElement() throws Exception { |
| 502 FunctionElement referencedElement = mock2(FunctionElement.class, ElementKind
.FUNCTION); | 504 FunctionElement referencedElement = mockElement(FunctionElement.class, Eleme
ntKind.FUNCTION); |
| 503 { | 505 { |
| 504 Location location = new Location(elementA, 1, 10); | 506 Location location = new Location(elementA, 1, 10); |
| 505 indexStore.recordRelationship(referencedElement, IndexConstants.IS_INVOKED
_BY, location); | 507 indexStore.recordRelationship(referencedElement, IndexConstants.IS_INVOKED
_BY, location); |
| 506 } | 508 } |
| 507 { | 509 { |
| 508 Location location = new Location(elementB, 2, 20); | 510 Location location = new Location(elementB, 2, 20); |
| 509 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 511 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 510 } | 512 } |
| 511 // search matches | 513 // search matches |
| 512 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 514 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 513 // verify | 515 // verify |
| 514 assertMatches( | 516 assertMatches( |
| 515 matches, | 517 matches, |
| 516 new ExpectedMatch(elementA, MatchKind.FUNCTION_EXECUTION, 1, 10), | 518 new ExpectedMatch(elementA, MatchKind.FUNCTION_EXECUTION, 1, 10), |
| 517 new ExpectedMatch(elementB, MatchKind.FUNCTION_REFERENCE, 2, 20)); | 519 new ExpectedMatch(elementB, MatchKind.FUNCTION_REFERENCE, 2, 20)); |
| 518 } | 520 } |
| 519 | 521 |
| 520 public void test_searchReferences_ImportElement() throws Exception { | 522 public void test_searchReferences_ImportElement() throws Exception { |
| 521 ImportElement referencedElement = mock2(ImportElement.class, ElementKind.IMP
ORT); | 523 ImportElement referencedElement = mockElement(ImportElement.class, ElementKi
nd.IMPORT); |
| 522 { | 524 { |
| 523 Location locationA = new Location(elementA, 1, 2); | 525 Location locationA = new Location(elementA, 1, 2); |
| 524 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); | 526 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); |
| 525 } | 527 } |
| 526 { | 528 { |
| 527 Location locationB = new Location(elementB, 10, 0); | 529 Location locationB = new Location(elementB, 10, 0); |
| 528 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); | 530 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); |
| 529 } | 531 } |
| 530 // search matches | 532 // search matches |
| 531 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 533 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 532 // verify | 534 // verify |
| 533 assertMatches( | 535 assertMatches( |
| 534 matches, | 536 matches, |
| 535 new ExpectedMatch(elementA, MatchKind.IMPORT_REFERENCE, 1, 2), | 537 new ExpectedMatch(elementA, MatchKind.IMPORT_REFERENCE, 1, 2), |
| 536 new ExpectedMatch(elementB, MatchKind.IMPORT_REFERENCE, 10, 0)); | 538 new ExpectedMatch(elementB, MatchKind.IMPORT_REFERENCE, 10, 0)); |
| 537 } | 539 } |
| 538 | 540 |
| 539 public void test_searchReferences_LibraryElement() throws Exception { | 541 public void test_searchReferences_LibraryElement() throws Exception { |
| 540 LibraryElement referencedElement = mock2(LibraryElement.class, ElementKind.L
IBRARY); | 542 LibraryElement referencedElement = mockElement(LibraryElement.class, Element
Kind.LIBRARY); |
| 541 { | 543 { |
| 542 Location location = new Location(elementA, 1, 2); | 544 Location location = new Location(elementA, 1, 2); |
| 543 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 545 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 544 } | 546 } |
| 545 // search matches | 547 // search matches |
| 546 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 548 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 547 // verify | 549 // verify |
| 548 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.LIBRARY_REFEREN
CE, 1, 2)); | 550 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.LIBRARY_REFEREN
CE, 1, 2)); |
| 549 } | 551 } |
| 550 | 552 |
| 551 public void test_searchReferences_MethodElement() throws Exception { | 553 public void test_searchReferences_MethodElement() throws Exception { |
| 552 MethodElement referencedElement = mock2(MethodElement.class, ElementKind.MET
HOD); | 554 MethodElement referencedElement = mockElement(MethodElement.class, ElementKi
nd.METHOD); |
| 553 { | 555 { |
| 554 Location location = new Location(elementA, 1, 10); | 556 Location location = new Location(elementA, 1, 10); |
| 555 indexStore.recordRelationship( | 557 indexStore.recordRelationship( |
| 556 referencedElement, | 558 referencedElement, |
| 557 IndexConstants.IS_INVOKED_BY_UNQUALIFIED, | 559 IndexConstants.IS_INVOKED_BY_UNQUALIFIED, |
| 558 location); | 560 location); |
| 559 } | 561 } |
| 560 { | 562 { |
| 561 Location location = new Location(elementB, 2, 20); | 563 Location location = new Location(elementB, 2, 20); |
| 562 indexStore.recordRelationship( | 564 indexStore.recordRelationship( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 583 // verify | 585 // verify |
| 584 assertMatches( | 586 assertMatches( |
| 585 matches, | 587 matches, |
| 586 new ExpectedMatch(elementA, MatchKind.METHOD_INVOCATION, 1, 10, false), | 588 new ExpectedMatch(elementA, MatchKind.METHOD_INVOCATION, 1, 10, false), |
| 587 new ExpectedMatch(elementB, MatchKind.METHOD_INVOCATION, 2, 20, true), | 589 new ExpectedMatch(elementB, MatchKind.METHOD_INVOCATION, 2, 20, true), |
| 588 new ExpectedMatch(elementC, MatchKind.METHOD_REFERENCE, 3, 30, false), | 590 new ExpectedMatch(elementC, MatchKind.METHOD_REFERENCE, 3, 30, false), |
| 589 new ExpectedMatch(elementD, MatchKind.METHOD_REFERENCE, 4, 40, true)); | 591 new ExpectedMatch(elementD, MatchKind.METHOD_REFERENCE, 4, 40, true)); |
| 590 } | 592 } |
| 591 | 593 |
| 592 public void test_searchReferences_MethodMember() throws Exception { | 594 public void test_searchReferences_MethodMember() throws Exception { |
| 593 MethodElement referencedElement = mock2(MethodElement.class, ElementKind.MET
HOD); | 595 MethodElement referencedElement = mockElement(MethodElement.class, ElementKi
nd.METHOD); |
| 594 { | 596 { |
| 595 Location location = new Location(elementA, 1, 10); | 597 Location location = new Location(elementA, 1, 10); |
| 596 indexStore.recordRelationship( | 598 indexStore.recordRelationship( |
| 597 referencedElement, | 599 referencedElement, |
| 598 IndexConstants.IS_INVOKED_BY_UNQUALIFIED, | 600 IndexConstants.IS_INVOKED_BY_UNQUALIFIED, |
| 599 location); | 601 location); |
| 600 } | 602 } |
| 601 { | 603 { |
| 602 Location location = new Location(elementB, 2, 20); | 604 Location location = new Location(elementB, 2, 20); |
| 603 indexStore.recordRelationship( | 605 indexStore.recordRelationship( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 625 // verify | 627 // verify |
| 626 assertMatches( | 628 assertMatches( |
| 627 matches, | 629 matches, |
| 628 new ExpectedMatch(elementA, MatchKind.METHOD_INVOCATION, 1, 10, false), | 630 new ExpectedMatch(elementA, MatchKind.METHOD_INVOCATION, 1, 10, false), |
| 629 new ExpectedMatch(elementB, MatchKind.METHOD_INVOCATION, 2, 20, true), | 631 new ExpectedMatch(elementB, MatchKind.METHOD_INVOCATION, 2, 20, true), |
| 630 new ExpectedMatch(elementC, MatchKind.METHOD_REFERENCE, 3, 30, false), | 632 new ExpectedMatch(elementC, MatchKind.METHOD_REFERENCE, 3, 30, false), |
| 631 new ExpectedMatch(elementD, MatchKind.METHOD_REFERENCE, 4, 40, true)); | 633 new ExpectedMatch(elementD, MatchKind.METHOD_REFERENCE, 4, 40, true)); |
| 632 } | 634 } |
| 633 | 635 |
| 634 public void test_searchReferences_ParameterElement() throws Exception { | 636 public void test_searchReferences_ParameterElement() throws Exception { |
| 635 ParameterElement referencedElement = mock2(ParameterElement.class, ElementKi
nd.PARAMETER); | 637 ParameterElement referencedElement = mockElement(ParameterElement.class, Ele
mentKind.PARAMETER); |
| 636 { | 638 { |
| 637 Location location = new Location(elementA, 1, 10); | 639 Location location = new Location(elementA, 1, 10); |
| 638 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_BY
, location); | 640 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_BY
, location); |
| 639 } | 641 } |
| 640 { | 642 { |
| 641 Location location = new Location(elementB, 2, 20); | 643 Location location = new Location(elementB, 2, 20); |
| 642 indexStore.recordRelationship(referencedElement, IndexConstants.IS_WRITTEN
_BY, location); | 644 indexStore.recordRelationship(referencedElement, IndexConstants.IS_WRITTEN
_BY, location); |
| 643 } | 645 } |
| 644 { | 646 { |
| 645 Location location = new Location(elementC, 3, 30); | 647 Location location = new Location(elementC, 3, 30); |
| 646 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_WR
ITTEN_BY, location); | 648 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_WR
ITTEN_BY, location); |
| 647 } | 649 } |
| 648 { | 650 { |
| 649 Location location = new Location(elementD, 4, 40); | 651 Location location = new Location(elementD, 4, 40); |
| 650 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); | 652 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, location); |
| 651 } | 653 } |
| 652 // search matches | 654 // search matches |
| 653 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 655 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 654 // verify | 656 // verify |
| 655 // TODO(scheglov) why no MatchKind.FIELD_READ_WRITE ? | 657 // TODO(scheglov) why no MatchKind.FIELD_READ_WRITE ? |
| 656 assertMatches( | 658 assertMatches( |
| 657 matches, | 659 matches, |
| 658 new ExpectedMatch(elementA, MatchKind.VARIABLE_READ, 1, 10), | 660 new ExpectedMatch(elementA, MatchKind.VARIABLE_READ, 1, 10), |
| 659 new ExpectedMatch(elementB, MatchKind.VARIABLE_WRITE, 2, 20), | 661 new ExpectedMatch(elementB, MatchKind.VARIABLE_WRITE, 2, 20), |
| 660 new ExpectedMatch(elementC, MatchKind.VARIABLE_READ_WRITE, 3, 30), | 662 new ExpectedMatch(elementC, MatchKind.VARIABLE_READ_WRITE, 3, 30), |
| 661 new ExpectedMatch(elementD, MatchKind.NAMED_PARAMETER_REFERENCE, 4, 40))
; | 663 new ExpectedMatch(elementD, MatchKind.NAMED_PARAMETER_REFERENCE, 4, 40))
; |
| 662 } | 664 } |
| 663 | 665 |
| 664 public void test_searchReferences_PropertyAccessorElement_getter() throws Exce
ption { | 666 public void test_searchReferences_PropertyAccessorElement_getter() throws Exce
ption { |
| 665 PropertyAccessorElement accessor = mock2(PropertyAccessorElement.class, Elem
entKind.GETTER); | 667 PropertyAccessorElement accessor = mockElement( |
| 668 PropertyAccessorElement.class, |
| 669 ElementKind.GETTER); |
| 666 { | 670 { |
| 667 Location location = new Location(elementA, 1, 10); | 671 Location location = new Location(elementA, 1, 10); |
| 668 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_UN
QUALIFIED, location); | 672 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_UN
QUALIFIED, location); |
| 669 } | 673 } |
| 670 { | 674 { |
| 671 Location location = new Location(elementB, 2, 20); | 675 Location location = new Location(elementB, 2, 20); |
| 672 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); | 676 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); |
| 673 } | 677 } |
| 674 // search matches | 678 // search matches |
| 675 List<SearchMatch> matches = searchReferencesSync(Element.class, accessor); | 679 List<SearchMatch> matches = searchReferencesSync(Element.class, accessor); |
| 676 // verify | 680 // verify |
| 677 assertMatches(matches, new ExpectedMatch( | 681 assertMatches(matches, new ExpectedMatch( |
| 678 elementA, | 682 elementA, |
| 679 MatchKind.PROPERTY_ACCESSOR_REFERENCE, | 683 MatchKind.PROPERTY_ACCESSOR_REFERENCE, |
| 680 1, | 684 1, |
| 681 10, | 685 10, |
| 682 false), new ExpectedMatch(elementB, MatchKind.PROPERTY_ACCESSOR_REFERENC
E, 2, 20, true)); | 686 false), new ExpectedMatch(elementB, MatchKind.PROPERTY_ACCESSOR_REFERENC
E, 2, 20, true)); |
| 683 } | 687 } |
| 684 | 688 |
| 685 public void test_searchReferences_PropertyAccessorElement_setter() throws Exce
ption { | 689 public void test_searchReferences_PropertyAccessorElement_setter() throws Exce
ption { |
| 686 PropertyAccessorElement accessor = mock2(PropertyAccessorElement.class, Elem
entKind.SETTER); | 690 PropertyAccessorElement accessor = mockElement( |
| 691 PropertyAccessorElement.class, |
| 692 ElementKind.SETTER); |
| 687 { | 693 { |
| 688 Location location = new Location(elementA, 1, 10); | 694 Location location = new Location(elementA, 1, 10); |
| 689 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_UN
QUALIFIED, location); | 695 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_UN
QUALIFIED, location); |
| 690 } | 696 } |
| 691 { | 697 { |
| 692 Location location = new Location(elementB, 2, 20); | 698 Location location = new Location(elementB, 2, 20); |
| 693 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); | 699 indexStore.recordRelationship(accessor, IndexConstants.IS_REFERENCED_BY_QU
ALIFIED, location); |
| 694 } | 700 } |
| 695 // search matches | 701 // search matches |
| 696 List<SearchMatch> matches = searchReferencesSync(Element.class, accessor); | 702 List<SearchMatch> matches = searchReferencesSync(Element.class, accessor); |
| 697 // verify | 703 // verify |
| 698 assertMatches(matches, new ExpectedMatch( | 704 assertMatches(matches, new ExpectedMatch( |
| 699 elementA, | 705 elementA, |
| 700 MatchKind.PROPERTY_ACCESSOR_REFERENCE, | 706 MatchKind.PROPERTY_ACCESSOR_REFERENCE, |
| 701 1, | 707 1, |
| 702 10, | 708 10, |
| 703 false), new ExpectedMatch(elementB, MatchKind.PROPERTY_ACCESSOR_REFERENC
E, 2, 20, true)); | 709 false), new ExpectedMatch(elementB, MatchKind.PROPERTY_ACCESSOR_REFERENC
E, 2, 20, true)); |
| 704 } | 710 } |
| 705 | 711 |
| 706 public void test_searchReferences_TopLevelVariableElement() throws Exception { | 712 public void test_searchReferences_TopLevelVariableElement() throws Exception { |
| 707 PropertyAccessorElement getterElement = mock2(PropertyAccessorElement.class,
ElementKind.GETTER); | 713 PropertyAccessorElement getterElement = mockElement( |
| 708 PropertyAccessorElement setterElement = mock2(PropertyAccessorElement.class,
ElementKind.SETTER); | 714 PropertyAccessorElement.class, |
| 709 TopLevelVariableElement topVariableElement = mock2( | 715 ElementKind.GETTER); |
| 716 PropertyAccessorElement setterElement = mockElement( |
| 717 PropertyAccessorElement.class, |
| 718 ElementKind.SETTER); |
| 719 TopLevelVariableElement topVariableElement = mockElement( |
| 710 TopLevelVariableElement.class, | 720 TopLevelVariableElement.class, |
| 711 ElementKind.TOP_LEVEL_VARIABLE); | 721 ElementKind.TOP_LEVEL_VARIABLE); |
| 712 when(topVariableElement.getGetter()).thenReturn(getterElement); | 722 when(topVariableElement.getGetter()).thenReturn(getterElement); |
| 713 when(topVariableElement.getSetter()).thenReturn(setterElement); | 723 when(topVariableElement.getSetter()).thenReturn(setterElement); |
| 714 { | 724 { |
| 715 Location location = new Location(elementA, 1, 10); | 725 Location location = new Location(elementA, 1, 10); |
| 716 indexStore.recordRelationship( | 726 indexStore.recordRelationship( |
| 717 getterElement, | 727 getterElement, |
| 718 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, | 728 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, |
| 719 location); | 729 location); |
| 720 } | 730 } |
| 721 { | 731 { |
| 722 Location location = new Location(elementC, 2, 20); | 732 Location location = new Location(elementC, 2, 20); |
| 723 indexStore.recordRelationship( | 733 indexStore.recordRelationship( |
| 724 setterElement, | 734 setterElement, |
| 725 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, | 735 IndexConstants.IS_REFERENCED_BY_UNQUALIFIED, |
| 726 location); | 736 location); |
| 727 } | 737 } |
| 728 // search matches | 738 // search matches |
| 729 List<SearchMatch> matches = searchReferencesSync(Element.class, topVariableE
lement); | 739 List<SearchMatch> matches = searchReferencesSync(Element.class, topVariableE
lement); |
| 730 // verify | 740 // verify |
| 731 assertMatches( | 741 assertMatches( |
| 732 matches, | 742 matches, |
| 733 new ExpectedMatch(elementA, MatchKind.FIELD_READ, 1, 10, false), | 743 new ExpectedMatch(elementA, MatchKind.FIELD_READ, 1, 10, false), |
| 734 new ExpectedMatch(elementC, MatchKind.FIELD_WRITE, 2, 20, false)); | 744 new ExpectedMatch(elementC, MatchKind.FIELD_WRITE, 2, 20, false)); |
| 735 } | 745 } |
| 736 | 746 |
| 737 public void test_searchReferences_TypeAliasElement() throws Exception { | 747 public void test_searchReferences_TypeAliasElement() throws Exception { |
| 738 FunctionTypeAliasElement referencedElement = mock2( | 748 FunctionTypeAliasElement referencedElement = mockElement( |
| 739 FunctionTypeAliasElement.class, | 749 FunctionTypeAliasElement.class, |
| 740 ElementKind.FUNCTION_TYPE_ALIAS); | 750 ElementKind.FUNCTION_TYPE_ALIAS); |
| 741 { | 751 { |
| 742 Location locationA = new Location(elementA, 1, 2); | 752 Location locationA = new Location(elementA, 1, 2); |
| 743 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); | 753 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); |
| 744 } | 754 } |
| 745 { | 755 { |
| 746 Location locationB = new Location(elementB, 10, 20); | 756 Location locationB = new Location(elementB, 10, 20); |
| 747 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); | 757 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); |
| 748 } | 758 } |
| 749 // search matches | 759 // search matches |
| 750 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 760 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 751 // verify | 761 // verify |
| 752 assertMatches( | 762 assertMatches( |
| 753 matches, | 763 matches, |
| 754 new ExpectedMatch(elementA, MatchKind.FUNCTION_TYPE_REFERENCE, 1, 2), | 764 new ExpectedMatch(elementA, MatchKind.FUNCTION_TYPE_REFERENCE, 1, 2), |
| 755 new ExpectedMatch(elementB, MatchKind.FUNCTION_TYPE_REFERENCE, 10, 20)); | 765 new ExpectedMatch(elementB, MatchKind.FUNCTION_TYPE_REFERENCE, 10, 20)); |
| 756 } | 766 } |
| 757 | 767 |
| 758 public void test_searchReferences_TypeParameterElement() throws Exception { | 768 public void test_searchReferences_TypeParameterElement() throws Exception { |
| 759 TypeParameterElement referencedElement = mock2( | 769 TypeParameterElement referencedElement = mockElement( |
| 760 TypeParameterElement.class, | 770 TypeParameterElement.class, |
| 761 ElementKind.TYPE_PARAMETER); | 771 ElementKind.TYPE_PARAMETER); |
| 762 { | 772 { |
| 763 Location locationA = new Location(elementA, 1, 2); | 773 Location locationA = new Location(elementA, 1, 2); |
| 764 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); | 774 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationA); |
| 765 } | 775 } |
| 766 { | 776 { |
| 767 Location locationB = new Location(elementB, 10, 20); | 777 Location locationB = new Location(elementB, 10, 20); |
| 768 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); | 778 indexStore.recordRelationship(referencedElement, IndexConstants.IS_REFEREN
CED_BY, locationB); |
| 769 } | 779 } |
| 770 // search matches | 780 // search matches |
| 771 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 781 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 772 // verify | 782 // verify |
| 773 assertMatches( | 783 assertMatches( |
| 774 matches, | 784 matches, |
| 775 new ExpectedMatch(elementA, MatchKind.TYPE_PARAMETER_REFERENCE, 1, 2), | 785 new ExpectedMatch(elementA, MatchKind.TYPE_PARAMETER_REFERENCE, 1, 2), |
| 776 new ExpectedMatch(elementB, MatchKind.TYPE_PARAMETER_REFERENCE, 10, 20))
; | 786 new ExpectedMatch(elementB, MatchKind.TYPE_PARAMETER_REFERENCE, 10, 20))
; |
| 777 } | 787 } |
| 778 | 788 |
| 779 public void test_searchReferences_VariableElement() throws Exception { | 789 public void test_searchReferences_VariableElement() throws Exception { |
| 780 LocalVariableElement referencedElement = mock2( | 790 LocalVariableElement referencedElement = mockElement( |
| 781 LocalVariableElement.class, | 791 LocalVariableElement.class, |
| 782 ElementKind.LOCAL_VARIABLE); | 792 ElementKind.LOCAL_VARIABLE); |
| 783 { | 793 { |
| 784 Location location = new Location(elementA, 1, 10); | 794 Location location = new Location(elementA, 1, 10); |
| 785 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_BY
, location); | 795 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_BY
, location); |
| 786 } | 796 } |
| 787 { | 797 { |
| 788 Location location = new Location(elementB, 2, 20); | 798 Location location = new Location(elementB, 2, 20); |
| 789 indexStore.recordRelationship(referencedElement, IndexConstants.IS_WRITTEN
_BY, location); | 799 indexStore.recordRelationship(referencedElement, IndexConstants.IS_WRITTEN
_BY, location); |
| 790 } | 800 } |
| 791 { | 801 { |
| 792 Location location = new Location(elementC, 3, 30); | 802 Location location = new Location(elementC, 3, 30); |
| 793 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_WR
ITTEN_BY, location); | 803 indexStore.recordRelationship(referencedElement, IndexConstants.IS_READ_WR
ITTEN_BY, location); |
| 794 } | 804 } |
| 795 // search matches | 805 // search matches |
| 796 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); | 806 List<SearchMatch> matches = searchReferencesSync(Element.class, referencedEl
ement); |
| 797 // verify | 807 // verify |
| 798 assertMatches( | 808 assertMatches( |
| 799 matches, | 809 matches, |
| 800 new ExpectedMatch(elementA, MatchKind.VARIABLE_READ, 1, 10), | 810 new ExpectedMatch(elementA, MatchKind.VARIABLE_READ, 1, 10), |
| 801 new ExpectedMatch(elementB, MatchKind.VARIABLE_WRITE, 2, 20), | 811 new ExpectedMatch(elementB, MatchKind.VARIABLE_WRITE, 2, 20), |
| 802 new ExpectedMatch(elementC, MatchKind.VARIABLE_READ_WRITE, 3, 30)); | 812 new ExpectedMatch(elementC, MatchKind.VARIABLE_READ_WRITE, 3, 30)); |
| 803 } | 813 } |
| 804 | 814 |
| 805 public void test_searchSubtypes() throws Exception { | 815 public void test_searchSubtypes() throws Exception { |
| 806 final ClassElement referencedElement = mock2(ClassElement.class, ElementKind
.CLASS); | 816 final ClassElement referencedElement = mockElement(ClassElement.class, Eleme
ntKind.CLASS); |
| 807 { | 817 { |
| 808 Location locationA = new Location(elementA, 10, 1); | 818 Location locationA = new Location(elementA, 10, 1); |
| 809 indexStore.recordRelationship(referencedElement, IndexConstants.IS_EXTENDE
D_BY, locationA); | 819 indexStore.recordRelationship(referencedElement, IndexConstants.IS_EXTENDE
D_BY, locationA); |
| 810 } | 820 } |
| 811 { | 821 { |
| 812 Location locationB = new Location(elementB, 20, 2); | 822 Location locationB = new Location(elementB, 20, 2); |
| 813 indexStore.recordRelationship(referencedElement, IndexConstants.IS_MIXED_I
N_BY, locationB); | 823 indexStore.recordRelationship(referencedElement, IndexConstants.IS_MIXED_I
N_BY, locationB); |
| 814 } | 824 } |
| 815 { | 825 { |
| 816 Location locationC = new Location(elementC, 30, 3); | 826 Location locationC = new Location(elementC, 30, 3); |
| 817 indexStore.recordRelationship(referencedElement, IndexConstants.IS_IMPLEME
NTED_BY, locationC); | 827 indexStore.recordRelationship(referencedElement, IndexConstants.IS_IMPLEME
NTED_BY, locationC); |
| 818 } | 828 } |
| 819 // search matches | 829 // search matches |
| 820 List<SearchMatch> matches = runSearch(new SearchRunner<List<SearchMatch>>()
{ | 830 List<SearchMatch> matches = runSearch(new SearchRunner<List<SearchMatch>>()
{ |
| 821 @Override | 831 @Override |
| 822 public List<SearchMatch> run(OperationQueue queue, OperationProcessor proc
essor, Index index, | 832 public List<SearchMatch> run(OperationQueue queue, OperationProcessor proc
essor, Index index, |
| 823 SearchEngine engine) throws Exception { | 833 SearchEngine engine) throws Exception { |
| 824 return engine.searchSubtypes(referencedElement, scope, filter); | 834 return engine.searchSubtypes(referencedElement, scope, filter); |
| 825 } | 835 } |
| 826 }); | 836 }); |
| 827 // verify | 837 // verify |
| 828 assertMatches( | 838 assertMatches( |
| 829 matches, | 839 matches, |
| 830 new ExpectedMatch(elementA, MatchKind.EXTENDS_REFERENCE, 10, 1), | 840 new ExpectedMatch(elementA, MatchKind.EXTENDS_REFERENCE, 10, 1), |
| 831 new ExpectedMatch(elementB, MatchKind.WITH_REFERENCE, 20, 2), | 841 new ExpectedMatch(elementB, MatchKind.WITH_REFERENCE, 20, 2), |
| 832 new ExpectedMatch(elementC, MatchKind.IMPLEMENTS_REFERENCE, 30, 3)); | 842 new ExpectedMatch(elementC, MatchKind.IMPLEMENTS_REFERENCE, 30, 3)); |
| 833 } | 843 } |
| 834 | 844 |
| 835 public void test_searchTypeDeclarations_async() throws Exception { | 845 public void test_searchTypeDeclarations_async() throws Exception { |
| 836 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 846 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 837 { | 847 { |
| 838 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); | 848 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); |
| 839 Location locationA = new Location(elementA, 1, 2); | 849 Location locationA = new Location(elementA, 1, 2); |
| 840 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS, locat
ionA); | 850 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS, locat
ionA); |
| 841 } | 851 } |
| 842 scope = new LibrarySearchScope(library); | 852 scope = new LibrarySearchScope(library); |
| 843 // search matches | 853 // search matches |
| 844 List<SearchMatch> matches = searchTypeDeclarationsAsync(); | 854 List<SearchMatch> matches = searchTypeDeclarationsAsync(); |
| 845 // verify | 855 // verify |
| 846 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_DECLARATI
ON, 1, 2)); | 856 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_DECLARATI
ON, 1, 2)); |
| 847 } | 857 } |
| 848 | 858 |
| 849 public void test_searchTypeDeclarations_class() throws Exception { | 859 public void test_searchTypeDeclarations_class() throws Exception { |
| 850 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 860 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 851 { | 861 { |
| 852 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); | 862 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); |
| 853 Location locationA = new Location(elementA, 1, 2); | 863 Location locationA = new Location(elementA, 1, 2); |
| 854 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS, locat
ionA); | 864 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS, locat
ionA); |
| 855 } | 865 } |
| 856 scope = new LibrarySearchScope(library); | 866 scope = new LibrarySearchScope(library); |
| 857 // search matches | 867 // search matches |
| 858 List<SearchMatch> matches = searchTypeDeclarationsSync(); | 868 List<SearchMatch> matches = searchTypeDeclarationsSync(); |
| 859 // verify | 869 // verify |
| 860 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_DECLARATI
ON, 1, 2)); | 870 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_DECLARATI
ON, 1, 2)); |
| 861 } | 871 } |
| 862 | 872 |
| 863 public void test_searchTypeDeclarations_classAlias() throws Exception { | 873 public void test_searchTypeDeclarations_classAlias() throws Exception { |
| 864 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 874 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 865 { | 875 { |
| 866 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); | 876 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); |
| 867 Location locationA = new Location(elementA, 1, 2); | 877 Location locationA = new Location(elementA, 1, 2); |
| 868 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS_ALIAS,
locationA); | 878 indexStore.recordRelationship(library, IndexConstants.DEFINES_CLASS_ALIAS,
locationA); |
| 869 } | 879 } |
| 870 scope = new LibrarySearchScope(library); | 880 scope = new LibrarySearchScope(library); |
| 871 // search matches | 881 // search matches |
| 872 List<SearchMatch> matches = searchTypeDeclarationsSync(); | 882 List<SearchMatch> matches = searchTypeDeclarationsSync(); |
| 873 // verify | 883 // verify |
| 874 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_ALIAS_DEC
LARATION, 1, 2)); | 884 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.CLASS_ALIAS_DEC
LARATION, 1, 2)); |
| 875 } | 885 } |
| 876 | 886 |
| 877 public void test_searchTypeDeclarations_functionType() throws Exception { | 887 public void test_searchTypeDeclarations_functionType() throws Exception { |
| 878 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 888 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 879 { | 889 { |
| 880 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); | 890 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); |
| 881 Location locationA = new Location(elementA, 1, 2); | 891 Location locationA = new Location(elementA, 1, 2); |
| 882 indexStore.recordRelationship(library, IndexConstants.DEFINES_FUNCTION_TYP
E, locationA); | 892 indexStore.recordRelationship(library, IndexConstants.DEFINES_FUNCTION_TYP
E, locationA); |
| 883 } | 893 } |
| 884 scope = new LibrarySearchScope(library); | 894 scope = new LibrarySearchScope(library); |
| 885 // search matches | 895 // search matches |
| 886 List<SearchMatch> matches = searchTypeDeclarationsSync(); | 896 List<SearchMatch> matches = searchTypeDeclarationsSync(); |
| 887 // verify | 897 // verify |
| 888 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_TYPE_D
ECLARATION, 1, 2)); | 898 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.FUNCTION_TYPE_D
ECLARATION, 1, 2)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 910 String.class, | 920 String.class, |
| 911 "test"); | 921 "test"); |
| 912 // verify | 922 // verify |
| 913 assertMatches( | 923 assertMatches( |
| 914 matches, | 924 matches, |
| 915 new ExpectedMatch(elementA, MatchKind.NAME_REFERENCE_RESOLVED, 1, 2), | 925 new ExpectedMatch(elementA, MatchKind.NAME_REFERENCE_RESOLVED, 1, 2), |
| 916 new ExpectedMatch(elementB, MatchKind.NAME_REFERENCE_UNRESOLVED, 10, 20)
); | 926 new ExpectedMatch(elementB, MatchKind.NAME_REFERENCE_UNRESOLVED, 10, 20)
); |
| 917 } | 927 } |
| 918 | 928 |
| 919 public void test_searchVariableDeclarations() throws Exception { | 929 public void test_searchVariableDeclarations() throws Exception { |
| 920 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 930 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 921 defineVariablesAB(library); | 931 defineVariablesAB(library); |
| 922 scope = new LibrarySearchScope(library); | 932 scope = new LibrarySearchScope(library); |
| 923 // search matches | 933 // search matches |
| 924 List<SearchMatch> matches = searchVariableDeclarationsSync(); | 934 List<SearchMatch> matches = searchVariableDeclarationsSync(); |
| 925 // verify | 935 // verify |
| 926 assertMatches( | 936 assertMatches( |
| 927 matches, | 937 matches, |
| 928 new ExpectedMatch(elementA, MatchKind.VARIABLE_DECLARATION, 1, 2), | 938 new ExpectedMatch(elementA, MatchKind.VARIABLE_DECLARATION, 1, 2), |
| 929 new ExpectedMatch(elementB, MatchKind.VARIABLE_DECLARATION, 10, 20)); | 939 new ExpectedMatch(elementB, MatchKind.VARIABLE_DECLARATION, 10, 20)); |
| 930 } | 940 } |
| 931 | 941 |
| 932 public void test_searchVariableDeclarations_async() throws Exception { | 942 public void test_searchVariableDeclarations_async() throws Exception { |
| 933 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 943 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 934 defineVariablesAB(library); | 944 defineVariablesAB(library); |
| 935 scope = new LibrarySearchScope(library); | 945 scope = new LibrarySearchScope(library); |
| 936 // search matches | 946 // search matches |
| 937 List<SearchMatch> matches = searchVariableDeclarationsAsync(); | 947 List<SearchMatch> matches = searchVariableDeclarationsAsync(); |
| 938 // verify | 948 // verify |
| 939 assertMatches( | 949 assertMatches( |
| 940 matches, | 950 matches, |
| 941 new ExpectedMatch(elementA, MatchKind.VARIABLE_DECLARATION, 1, 2), | 951 new ExpectedMatch(elementA, MatchKind.VARIABLE_DECLARATION, 1, 2), |
| 942 new ExpectedMatch(elementB, MatchKind.VARIABLE_DECLARATION, 10, 20)); | 952 new ExpectedMatch(elementB, MatchKind.VARIABLE_DECLARATION, 10, 20)); |
| 943 } | 953 } |
| 944 | 954 |
| 945 public void test_searchVariableDeclarations_usePattern() throws Exception { | 955 public void test_searchVariableDeclarations_usePattern() throws Exception { |
| 946 LibraryElement library = mock2(LibraryElement.class, ElementKind.LIBRARY); | 956 LibraryElement library = mockElement(LibraryElement.class, ElementKind.LIBRA
RY); |
| 947 defineVariablesAB(library); | 957 defineVariablesAB(library); |
| 948 scope = new LibrarySearchScope(library); | 958 scope = new LibrarySearchScope(library); |
| 949 // search "A" | 959 // search "A" |
| 950 { | 960 { |
| 951 pattern = SearchPatternFactory.createExactPattern("A", true); | 961 pattern = SearchPatternFactory.createExactPattern("A", true); |
| 952 List<SearchMatch> matches = searchVariableDeclarationsSync(); | 962 List<SearchMatch> matches = searchVariableDeclarationsSync(); |
| 953 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.VARIABLE_DECL
ARATION, 1, 2)); | 963 assertMatches(matches, new ExpectedMatch(elementA, MatchKind.VARIABLE_DECL
ARATION, 1, 2)); |
| 954 } | 964 } |
| 955 // search "B" | 965 // search "B" |
| 956 { | 966 { |
| 957 pattern = SearchPatternFactory.createExactPattern("B", true); | 967 pattern = SearchPatternFactory.createExactPattern("B", true); |
| 958 List<SearchMatch> matches = searchVariableDeclarationsSync(); | 968 List<SearchMatch> matches = searchVariableDeclarationsSync(); |
| 959 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.VARIABLE_DECL
ARATION, 10, 20)); | 969 assertMatches(matches, new ExpectedMatch(elementB, MatchKind.VARIABLE_DECL
ARATION, 10, 20)); |
| 960 } | 970 } |
| 961 } | 971 } |
| 962 | 972 |
| 963 @Override | 973 @Override |
| 964 protected void setUp() throws Exception { | 974 protected void setUp() throws Exception { |
| 965 super.setUp(); | 975 super.setUp(); |
| 966 when(elementA.getDisplayName()).thenReturn("A"); | 976 when(elementA.getDisplayName()).thenReturn("A"); |
| 967 when(elementB.getDisplayName()).thenReturn("B"); | 977 when(elementB.getDisplayName()).thenReturn("B"); |
| 968 when(elementC.getDisplayName()).thenReturn("C"); | 978 when(elementC.getDisplayName()).thenReturn("C"); |
| 969 when(elementD.getDisplayName()).thenReturn("D"); | 979 when(elementD.getDisplayName()).thenReturn("D"); |
| 970 when(elementE.getDisplayName()).thenReturn("E"); | 980 when(elementE.getDisplayName()).thenReturn("E"); |
| 981 when(elementA.getSource()).thenReturn(source); |
| 982 when(elementB.getSource()).thenReturn(source); |
| 983 when(elementC.getSource()).thenReturn(source); |
| 984 when(elementD.getSource()).thenReturn(source); |
| 985 when(elementE.getSource()).thenReturn(source); |
| 971 when(elementA.getContext()).thenReturn(CONTEXT); | 986 when(elementA.getContext()).thenReturn(CONTEXT); |
| 972 when(elementB.getContext()).thenReturn(CONTEXT); | 987 when(elementB.getContext()).thenReturn(CONTEXT); |
| 973 when(elementC.getContext()).thenReturn(CONTEXT); | 988 when(elementC.getContext()).thenReturn(CONTEXT); |
| 974 when(elementD.getContext()).thenReturn(CONTEXT); | 989 when(elementD.getContext()).thenReturn(CONTEXT); |
| 975 when(elementE.getContext()).thenReturn(CONTEXT); | 990 when(elementE.getContext()).thenReturn(CONTEXT); |
| 976 } | 991 } |
| 977 | 992 |
| 978 private void defineFunctionsAB(LibraryElement library) { | 993 private void defineFunctionsAB(LibraryElement library) { |
| 979 { | 994 { |
| 980 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); | 995 when(elementA.getAncestor(LibraryElement.class)).thenReturn(library); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 994 Location locationA = new Location(elementA, 1, 2); | 1009 Location locationA = new Location(elementA, 1, 2); |
| 995 indexStore.recordRelationship(library, IndexConstants.DEFINES_VARIABLE, lo
cationA); | 1010 indexStore.recordRelationship(library, IndexConstants.DEFINES_VARIABLE, lo
cationA); |
| 996 } | 1011 } |
| 997 { | 1012 { |
| 998 when(elementB.getAncestor(LibraryElement.class)).thenReturn(library); | 1013 when(elementB.getAncestor(LibraryElement.class)).thenReturn(library); |
| 999 Location locationB = new Location(elementB, 10, 20); | 1014 Location locationB = new Location(elementB, 10, 20); |
| 1000 indexStore.recordRelationship(library, IndexConstants.DEFINES_VARIABLE, lo
cationB); | 1015 indexStore.recordRelationship(library, IndexConstants.DEFINES_VARIABLE, lo
cationB); |
| 1001 } | 1016 } |
| 1002 } | 1017 } |
| 1003 | 1018 |
| 1019 private <T extends Element> T mockElement(Class<T> clazz, ElementKind kind) { |
| 1020 T element = mock(clazz); |
| 1021 when(element.getContext()).thenReturn(CONTEXT); |
| 1022 when(element.getSource()).thenReturn(source); |
| 1023 when(element.getKind()).thenReturn(kind); |
| 1024 return element; |
| 1025 } |
| 1026 |
| 1004 private <T> T runSearch(SearchRunner<T> runner) throws Exception { | 1027 private <T> T runSearch(SearchRunner<T> runner) throws Exception { |
| 1005 final OperationQueue queue = new OperationQueue(); | 1028 final OperationQueue queue = new OperationQueue(); |
| 1006 final OperationProcessor processor = new OperationProcessor(queue); | 1029 final OperationProcessor processor = new OperationProcessor(queue); |
| 1007 final Index index = new IndexImpl(indexStore, queue, processor); | 1030 final Index index = new IndexImpl(indexStore, queue, processor); |
| 1008 final SearchEngine engine = SearchEngineFactory.createSearchEngine(index); | 1031 final SearchEngine engine = SearchEngineFactory.createSearchEngine(index); |
| 1009 try { | 1032 try { |
| 1010 new Thread() { | 1033 new Thread() { |
| 1011 @Override | 1034 @Override |
| 1012 public void run() { | 1035 public void run() { |
| 1013 processor.run(); | 1036 processor.run(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 } | 1127 } |
| 1105 | 1128 |
| 1106 private List<SearchMatch> searchVariableDeclarationsAsync() throws Exception { | 1129 private List<SearchMatch> searchVariableDeclarationsAsync() throws Exception { |
| 1107 return searchDeclarationsAsync("searchVariableDeclarations"); | 1130 return searchDeclarationsAsync("searchVariableDeclarations"); |
| 1108 } | 1131 } |
| 1109 | 1132 |
| 1110 private List<SearchMatch> searchVariableDeclarationsSync() throws Exception { | 1133 private List<SearchMatch> searchVariableDeclarationsSync() throws Exception { |
| 1111 return searchDeclarationsSync("searchVariableDeclarations"); | 1134 return searchDeclarationsSync("searchVariableDeclarations"); |
| 1112 } | 1135 } |
| 1113 } | 1136 } |
| OLD | NEW |