OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, 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 |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.internal.index; | 14 package com.google.dart.engine.internal.index; |
15 | 15 |
16 import com.google.common.base.Objects; | 16 import com.google.common.base.Objects; |
17 import com.google.common.collect.ImmutableSet; | 17 import com.google.common.collect.ImmutableSet; |
18 import com.google.common.collect.Lists; | 18 import com.google.common.collect.Lists; |
19 import com.google.dart.engine.EngineTestCase; | 19 import com.google.dart.engine.EngineTestCase; |
20 import com.google.dart.engine.context.AnalysisContext; | 20 import com.google.dart.engine.context.AnalysisContext; |
21 import com.google.dart.engine.element.CompilationUnitElement; | 21 import com.google.dart.engine.element.CompilationUnitElement; |
22 import com.google.dart.engine.element.Element; | 22 import com.google.dart.engine.element.Element; |
23 import com.google.dart.engine.element.ElementLocation; | 23 import com.google.dart.engine.element.ElementLocation; |
24 import com.google.dart.engine.index.Location; | 24 import com.google.dart.engine.index.Location; |
25 import com.google.dart.engine.index.Relationship; | 25 import com.google.dart.engine.index.Relationship; |
26 import com.google.dart.engine.internal.context.InstrumentedAnalysisContextImpl; | 26 import com.google.dart.engine.internal.context.InstrumentedAnalysisContextImpl; |
27 import com.google.dart.engine.internal.element.ElementLocationImpl; | 27 import com.google.dart.engine.internal.element.ElementLocationImpl; |
| 28 import com.google.dart.engine.internal.element.member.Member; |
| 29 import com.google.dart.engine.source.DirectoryBasedSourceContainer; |
28 import com.google.dart.engine.source.Source; | 30 import com.google.dart.engine.source.Source; |
29 import com.google.dart.engine.source.SourceContainer; | 31 import com.google.dart.engine.source.SourceContainer; |
30 | 32 |
31 import org.mockito.invocation.InvocationOnMock; | 33 import org.mockito.invocation.InvocationOnMock; |
32 import org.mockito.stubbing.Answer; | 34 import org.mockito.stubbing.Answer; |
33 | 35 |
34 import static org.fest.assertions.Assertions.assertThat; | 36 import static org.fest.assertions.Assertions.assertThat; |
35 import static org.mockito.Matchers.any; | 37 import static org.mockito.Matchers.any; |
36 import static org.mockito.Matchers.eq; | 38 import static org.mockito.Matchers.eq; |
37 import static org.mockito.Mockito.mock; | 39 import static org.mockito.Mockito.mock; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 214 } |
213 | 215 |
214 public void test_recordRelationship() throws Exception { | 216 public void test_recordRelationship() throws Exception { |
215 // no relationships initially | 217 // no relationships initially |
216 assertEquals(0, store.internalGetLocationCount()); | 218 assertEquals(0, store.internalGetLocationCount()); |
217 // record relationship | 219 // record relationship |
218 store.recordRelationship(elementA, relationship, location); | 220 store.recordRelationship(elementA, relationship, location); |
219 assertEquals(1, store.internalGetLocationCount()); | 221 assertEquals(1, store.internalGetLocationCount()); |
220 } | 222 } |
221 | 223 |
| 224 public void test_recordRelationship_member() throws Exception { |
| 225 Member member = mock(Member.class); |
| 226 when(member.getBaseElement()).thenReturn(elementA); |
| 227 // no relationships initially |
| 228 assertEquals(0, store.internalGetLocationCount()); |
| 229 // record relationship |
| 230 store.recordRelationship(member, relationship, location); |
| 231 // no location for "member" |
| 232 { |
| 233 Location[] locations = store.getRelationships(member, relationship); |
| 234 assertLocations(locations); |
| 235 } |
| 236 // has location for "elementA" |
| 237 { |
| 238 Location[] locations = store.getRelationships(elementA, relationship); |
| 239 assertLocations(locations, location); |
| 240 } |
| 241 } |
| 242 |
222 public void test_recordRelationship_noElement() throws Exception { | 243 public void test_recordRelationship_noElement() throws Exception { |
223 store.recordRelationship(null, relationship, location); | 244 store.recordRelationship(null, relationship, location); |
224 assertEquals(0, store.internalGetLocationCount()); | 245 assertEquals(0, store.internalGetLocationCount()); |
225 } | 246 } |
226 | 247 |
| 248 public void test_recordRelationship_noElementContext() throws Exception { |
| 249 when(elementA.getContext()).thenReturn(null); |
| 250 store.recordRelationship(elementA, relationship, location); |
| 251 assertEquals(0, store.internalGetLocationCount()); |
| 252 } |
| 253 |
| 254 public void test_recordRelationship_noElementSource() throws Exception { |
| 255 when(elementA.getSource()).thenReturn(null); |
| 256 store.recordRelationship(elementA, relationship, location); |
| 257 assertEquals(0, store.internalGetLocationCount()); |
| 258 } |
| 259 |
227 public void test_recordRelationship_noLocation() throws Exception { | 260 public void test_recordRelationship_noLocation() throws Exception { |
228 store.recordRelationship(elementA, relationship, null); | 261 store.recordRelationship(elementA, relationship, null); |
229 assertEquals(0, store.internalGetLocationCount()); | 262 assertEquals(0, store.internalGetLocationCount()); |
230 } | 263 } |
231 | 264 |
232 public void test_recordRelationship_noLocationElement() throws Exception { | 265 public void test_recordRelationship_noLocationContext() throws Exception { |
233 Element elementWithoutEnclosing = mock(Element.class); | 266 when(location.getElement().getContext()).thenReturn(null); |
234 Location location = new Location(elementWithoutEnclosing, 0, 0); | 267 store.recordRelationship(elementA, relationship, location); |
| 268 assertEquals(0, store.internalGetLocationCount()); |
| 269 } |
| 270 |
| 271 public void test_recordRelationship_noLocationSource() throws Exception { |
| 272 when(location.getElement().getSource()).thenReturn(null); |
235 store.recordRelationship(elementA, relationship, location); | 273 store.recordRelationship(elementA, relationship, location); |
236 assertEquals(0, store.internalGetLocationCount()); | 274 assertEquals(0, store.internalGetLocationCount()); |
237 } | 275 } |
238 | 276 |
239 public void test_removeContext_instrumented() throws Exception { | 277 public void test_removeContext_instrumented() throws Exception { |
240 InstrumentedAnalysisContextImpl instrumentedContext = mock(InstrumentedAnaly
sisContextImpl.class); | 278 InstrumentedAnalysisContextImpl instrumentedContext = mock(InstrumentedAnaly
sisContextImpl.class); |
241 when(instrumentedContext.getBasis()).thenReturn(contextA); | 279 when(instrumentedContext.getBasis()).thenReturn(contextA); |
242 // configure B | 280 // configure B |
243 when(elementB.getContext()).thenReturn(contextA); | 281 when(elementB.getContext()).thenReturn(contextA); |
244 Location locationB = mockLocation(elementB); | 282 Location locationB = mockLocation(elementB); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 store.removeSource(contextC, sourceB); | 452 store.removeSource(contextC, sourceB); |
415 assertEquals(0, store.internalGetLocationCount()); | 453 assertEquals(0, store.internalGetLocationCount()); |
416 assertEquals(0, store.internalGetLocationCount(contextB)); | 454 assertEquals(0, store.internalGetLocationCount(contextB)); |
417 assertEquals(0, store.internalGetLocationCount(contextC)); | 455 assertEquals(0, store.internalGetLocationCount(contextC)); |
418 { | 456 { |
419 Location[] locations = store.getRelationships(elementA, relationship); | 457 Location[] locations = store.getRelationships(elementA, relationship); |
420 assertThat(locations).isEmpty(); | 458 assertThat(locations).isEmpty(); |
421 } | 459 } |
422 } | 460 } |
423 | 461 |
| 462 public void test_removeSources_nullContext() throws Exception { |
| 463 // record |
| 464 { |
| 465 store.recordRelationship(IndexConstants.UNIVERSE, relationship, location); |
| 466 assertEquals(1, store.internalGetLocationCount()); |
| 467 } |
| 468 // remove "null" context, should never happen - ignored |
| 469 SourceContainer sourceContainer = new DirectoryBasedSourceContainer("/path/"
); |
| 470 store.removeSources(null, sourceContainer); |
| 471 assertEquals(1, store.internalGetLocationCount()); |
| 472 } |
| 473 |
424 public void test_removeSources_withDeclaration() throws Exception { | 474 public void test_removeSources_withDeclaration() throws Exception { |
425 Location locationB = mockLocation(elementB); | 475 Location locationB = mockLocation(elementB); |
426 Location locationC = mockLocation(elementC); | 476 Location locationC = mockLocation(elementC); |
427 // record: A, [B -> A], [C -> A] and [B -> C] | 477 // record: A, [B -> A], [C -> A] and [B -> C] |
428 { | 478 { |
429 store.recordRelationship(elementA, relationship, locationB); | 479 store.recordRelationship(elementA, relationship, locationB); |
430 store.recordRelationship(elementA, relationship, locationC); | 480 store.recordRelationship(elementA, relationship, locationC); |
431 store.recordRelationship(elementC, relationship, locationB); | 481 store.recordRelationship(elementC, relationship, locationB); |
432 assertEquals(3, store.internalGetLocationCount()); | 482 assertEquals(3, store.internalGetLocationCount()); |
433 Location[] locations = store.getRelationships(elementA, relationship); | 483 Location[] locations = store.getRelationships(elementA, relationship); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 when(elementA.getSource()).thenReturn(sourceA); | 623 when(elementA.getSource()).thenReturn(sourceA); |
574 when(elementB.getSource()).thenReturn(sourceB); | 624 when(elementB.getSource()).thenReturn(sourceB); |
575 when(elementC.getSource()).thenReturn(sourceC); | 625 when(elementC.getSource()).thenReturn(sourceC); |
576 when(elementD.getSource()).thenReturn(sourceD); | 626 when(elementD.getSource()).thenReturn(sourceD); |
577 when(unitElementA.getSource()).thenReturn(sourceA); | 627 when(unitElementA.getSource()).thenReturn(sourceA); |
578 when(unitElementB.getSource()).thenReturn(sourceB); | 628 when(unitElementB.getSource()).thenReturn(sourceB); |
579 when(unitElementC.getSource()).thenReturn(sourceC); | 629 when(unitElementC.getSource()).thenReturn(sourceC); |
580 when(unitElementD.getSource()).thenReturn(sourceD); | 630 when(unitElementD.getSource()).thenReturn(sourceD); |
581 } | 631 } |
582 } | 632 } |
OLD | NEW |