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 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 T element = mock(clazz); | 193 T element = mock(clazz); |
194 when(element.getLocation()).thenReturn(location); | 194 when(element.getLocation()).thenReturn(location); |
195 when(element.getNameOffset()).thenReturn(offset); | 195 when(element.getNameOffset()).thenReturn(offset); |
196 when(element.getDisplayName()).thenReturn(name); | 196 when(element.getDisplayName()).thenReturn(name); |
197 return element; | 197 return element; |
198 } | 198 } |
199 | 199 |
200 private IndexStore store = mock(IndexStore.class); | 200 private IndexStore store = mock(IndexStore.class); |
201 private IndexContributor index = new IndexContributor(store); | 201 private IndexContributor index = new IndexContributor(store); |
202 | 202 |
203 /** | |
204 * TODO(scheglov) enable this test after analyzer fix | |
205 * <p> | |
206 * https://code.google.com/p/dart/issues/detail?id=10521 | |
207 */ | |
208 public void fail_isReferencedBy_ImportElement_withPrefix() throws Exception { | |
209 setFileContent( | |
210 "Lib.dart", | |
211 makeSource( | |
212 "// filler filler filler filler filler filler filler filler filler f
iller", | |
213 "library lib;", | |
214 "var myVar;")); | |
215 parseTestUnit( | |
216 "// filler filler filler filler filler filler filler filler filler fille
r", | |
217 "import 'Lib.dart' as pref;", | |
218 "main() {", | |
219 " pref.myVar = 1;", | |
220 "}", | |
221 ""); | |
222 // set elements | |
223 Element mainElement = findElement("main("); | |
224 ImportElement importElement = (ImportElement) findNode( | |
225 "import 'Lib.dart", | |
226 ImportDirective.class).getElement(); | |
227 // index | |
228 index.visitCompilationUnit(testUnit); | |
229 // verify | |
230 // TODO(scheglov) we have problem - PrefixElement recorded for "pref" and we
don't know | |
231 // which ImportElement it is. | |
232 // List<RecordedRelation> relations = captureRecordedRelations(); | |
233 // assertRecordedRelation( | |
234 // relations, | |
235 // importElement, | |
236 // IndexConstants.IS_REFERENCED_BY, | |
237 // new ExpectedLocation(mainElement, findOffset("pref.myVar"), "pref")); | |
238 } | |
239 | |
240 public void test_createElementLocation() throws Exception { | 203 public void test_createElementLocation() throws Exception { |
241 ElementLocation elementLocation = mock(ElementLocation.class); | 204 ElementLocation elementLocation = mock(ElementLocation.class); |
242 Element element = mockElement(Element.class, elementLocation, 42, "myName"); | 205 Element element = mockElement(Element.class, elementLocation, 42, "myName"); |
243 Location location = IndexContributor.createElementLocation(element); | 206 Location location = IndexContributor.createElementLocation(element); |
244 assertLocation(location, element, 42, "myName", null); | 207 assertLocation(location, element, 42, "myName", null); |
245 } | 208 } |
246 | 209 |
247 public void test_createElementLocation_null() throws Exception { | 210 public void test_createElementLocation_null() throws Exception { |
248 assertSame(null, IndexContributor.createElementLocation(null)); | 211 assertSame(null, IndexContributor.createElementLocation(null)); |
249 } | 212 } |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 index.visitCompilationUnit(testUnit); | 864 index.visitCompilationUnit(testUnit); |
902 // verify | 865 // verify |
903 List<RecordedRelation> relations = captureRecordedRelations(); | 866 List<RecordedRelation> relations = captureRecordedRelations(); |
904 assertRecordedRelation( | 867 assertRecordedRelation( |
905 relations, | 868 relations, |
906 importElement, | 869 importElement, |
907 IndexConstants.IS_REFERENCED_BY, | 870 IndexConstants.IS_REFERENCED_BY, |
908 new ExpectedLocation(mainElement, findOffset("myVar = 1"), "")); | 871 new ExpectedLocation(mainElement, findOffset("myVar = 1"), "")); |
909 } | 872 } |
910 | 873 |
| 874 /** |
| 875 * TODO(scheglov) enable this test after analyzer fix |
| 876 * <p> |
| 877 * https://code.google.com/p/dart/issues/detail?id=10521 |
| 878 */ |
| 879 public void test_isReferencedBy_ImportElement_withPrefix() throws Exception { |
| 880 setFileContent( |
| 881 "Lib.dart", |
| 882 makeSource( |
| 883 "// filler filler filler filler filler filler filler filler filler f
iller", |
| 884 "library lib;", |
| 885 "var myVar;")); |
| 886 parseTestUnit( |
| 887 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 888 "import 'Lib.dart' as pref;", |
| 889 "main() {", |
| 890 " pref.myVar = 1;", |
| 891 "}", |
| 892 ""); |
| 893 // set elements |
| 894 Element mainElement = findElement("main("); |
| 895 ImportElement importElement = (ImportElement) findNode( |
| 896 "import 'Lib.dart", |
| 897 ImportDirective.class).getElement(); |
| 898 // index |
| 899 index.visitCompilationUnit(testUnit); |
| 900 // verify |
| 901 // TODO(scheglov) we have problem - PrefixElement recorded for "pref" and we
don't know |
| 902 // which ImportElement it is. |
| 903 // List<RecordedRelation> relations = captureRecordedRelations(); |
| 904 // assertRecordedRelation( |
| 905 // relations, |
| 906 // importElement, |
| 907 // IndexConstants.IS_REFERENCED_BY, |
| 908 // new ExpectedLocation(mainElement, findOffset("pref.myVar"), "pref")); |
| 909 } |
| 910 |
911 public void test_isReferencedBy_LabelElement() throws Exception { | 911 public void test_isReferencedBy_LabelElement() throws Exception { |
912 parseTestUnit( | 912 parseTestUnit( |
913 "// filler filler filler filler filler filler filler filler filler fille
r", | 913 "// filler filler filler filler filler filler filler filler filler fille
r", |
914 "main() {", | 914 "main() {", |
915 " L: while(true) {", | 915 " L: while(true) {", |
916 " break L;", | 916 " break L;", |
917 " }", | 917 " }", |
918 "}", | 918 "}", |
919 ""); | 919 ""); |
920 // set elements | 920 // set elements |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 int count = argElement.getAllValues().size(); | 1500 int count = argElement.getAllValues().size(); |
1501 for (int i = 0; i < count; i++) { | 1501 for (int i = 0; i < count; i++) { |
1502 relations.add(new RecordedRelation( | 1502 relations.add(new RecordedRelation( |
1503 argElement.getAllValues().get(i), | 1503 argElement.getAllValues().get(i), |
1504 argRel.getAllValues().get(i), | 1504 argRel.getAllValues().get(i), |
1505 argLocation.getAllValues().get(i))); | 1505 argLocation.getAllValues().get(i))); |
1506 } | 1506 } |
1507 return relations; | 1507 return relations; |
1508 } | 1508 } |
1509 } | 1509 } |
OLD | NEW |