1 /*******************************************************************************
2 * Copyright (c) 2017, 2019 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.jdt.core.tests.model;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jdt.core.CompletionProposal;
18 import org.eclipse.jdt.core.ICompilationUnit;
19
20 import junit.framework.Test;
21
22 public class CompletionTests3 extends AbstractJavaModelCompletionTests {
23
CompletionTests3(String name)24 public CompletionTests3(String name) {
25 super(name);
26 }
27 @Override
setUpSuite()28 public void setUpSuite() throws Exception {
29 super.setUpSuite();
30 }
31 @Override
tearDownSuite()32 public void tearDownSuite() throws Exception {
33 super.tearDownSuite();
34 }
35 static {
36 // TESTS_NAMES = new String[] { "testBug504095" };
37 }
suite()38 public static Test suite() {
39 return buildModelTestSuite(CompletionTests3.class);
40 }
41 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=338398
testBug338398a()42 public void testBug338398a() throws CoreException {
43 try {
44 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
45 this.workingCopies = new ICompilationUnit[2];
46 this.workingCopies[0] = getWorkingCopy(
47 "/P/src/a/A.java",
48 "package a;\n" +
49 "import static b.B.assertNotNull;\n"+
50 "public class A {\n" +
51 " public void foo() {\n" +
52 " assertno\n" +
53 " }" +
54 "}\n");
55
56 this.workingCopies[1] = getWorkingCopy(
57 "/P/src/b/B.java",
58 "package b;\n"+
59 "public class B {\n" +
60 " static public void assertNotNull(Object object) {\n" +
61 " // nothing to do here \n" +
62 " }\n" +
63 "}\n");
64
65 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
66 String str = this.workingCopies[0].getSource();
67 String completeBehind = "assertno";
68 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
69 this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
70 assertResults(
71 "assertNotNull[METHOD_REF]{assertNotNull(), Lb.B;, (Ljava.lang.Object;)V, assertNotNull, (object), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
72 requestor.getResults());
73 } finally {
74 deleteProject("P");
75 }
76 }
_testBug338398b()77 public void _testBug338398b() throws CoreException {
78 try {
79 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
80 this.workingCopies = new ICompilationUnit[2];
81 this.workingCopies[0] = getWorkingCopy(
82 "/P/src/a/A_CLASS.java",
83 "package a;\n" +
84 "public class A_CLASS {\n" +
85 " public A_CLASS() {}\n" +
86 " /**" +
87 " * A_CLASS#a_cl" +
88 " */\n" +
89 "}\n");
90
91 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
92 String str = this.workingCopies[0].getSource();
93 String completeBehind = "A_CLASS#a_cl";
94 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
95 this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
96 assertResults(
97 "A_CLASS[JAVADOC_METHOD_REF]{{@link A_CLASS#A_CLASS()}, La.A_CLASS;, ()V, A_CLASS, null, 45}",
98 requestor.getResults());
99 } finally {
100 deleteProject("P");
101 }
102 }
_testBug338398c()103 public void _testBug338398c() throws CoreException {
104 try {
105 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
106 this.workingCopies = new ICompilationUnit[2];
107 this.workingCopies[0] = getWorkingCopy(
108 "/P/src/a/A_CLASS.java",
109 "package a;\n" +
110 "public class A_CLASS {\n" +
111 " /**" +
112 " * @param my_s" +
113 " */\n" +
114 " public A_CLASS(String MY_STring) {}\n" +
115 "}\n");
116
117 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
118 String str = this.workingCopies[0].getSource();
119 String completeBehind = "@param my_s";
120 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
121 this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
122 assertResults(
123 "MY_STring[JAVADOC_PARAM_REF]{MY_STring, null, null, MY_STring, null, 18}",
124 requestor.getResults());
125 } finally {
126 deleteProject("P");
127 }
128 }
testBug504095()129 public void testBug504095() throws CoreException {
130 try {
131 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
132 this.workingCopies = new ICompilationUnit[2];
133 this.workingCopies[0] = getWorkingCopy(
134 "/P/src/a/Bug504095.java",
135 "package a;\n" +
136 "import java.lang.reflect.Field;\n" +
137 "public class Bug504095 {\n" +
138 " static @interface Parameter {}\n" +
139 " void method(Class<?> clazz) {\n" +
140 " for (Field member : clazz.getDeclaredFields()) {\n" +
141 " Parameter parameter = memb\n" +
142 " }\n" +
143 " }\n" +
144 "}\n");
145
146 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
147 String str = this.workingCopies[0].getSource();
148 String completeBehind = "memb";
149 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
150 this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
151 assertResults(
152 "member[LOCAL_VARIABLE_REF]{member, null, LField;, member, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
153 requestor.getResults());
154 } finally {
155 deleteProject("P");
156 }
157 }
testBug425035a()158 public void testBug425035a() throws CoreException {
159 try {
160 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
161 this.workingCopies = new ICompilationUnit[3];
162 this.workingCopies[0] = getWorkingCopy(
163 "/P/src/a/Values.java",
164 "package a;\n" +
165 "public enum Values {\n" +
166 " SOME_VALUE, OTHER_VALUE\n" +
167 "}\n");
168 this.workingCopies[1] = getWorkingCopy(
169 "/P/src/a/Annotation.java",
170 "package a;\n" +
171 "public @interface Annotation {\n" +
172 " Values[] value();\n" +
173 "}\n");
174 this.workingCopies[2] = getWorkingCopy(
175 "/P/src/b/Test.java",
176 "import a.Annotation;\n" +
177 "package b;\n" +
178 "@Annotation()\n" +
179 "public class Test {\n" +
180 "}\n");
181
182 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
183 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
184 String str = this.workingCopies[2].getSource();
185 String completeBehind = "Annotation(";
186 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
187 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
188 assertResults(
189 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
190 "value[ANNOTATION_ATTRIBUTE_REF]{value = , La.Annotation;, [La.Values;, value, null, 52}\n" +
191 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
192 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
193 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
194 requestor.getResults());
195 } finally {
196 deleteProject("P");
197 }
198 }
testBug425035b()199 public void testBug425035b() throws CoreException {
200 try {
201 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
202 this.workingCopies = new ICompilationUnit[3];
203 this.workingCopies[0] = getWorkingCopy(
204 "/P/src/a/Values.java",
205 "package a;\n" +
206 "public enum Values {\n" +
207 " SOME_VALUE, OTHER_VALUE\n" +
208 "}\n");
209 this.workingCopies[1] = getWorkingCopy(
210 "/P/src/a/Annotation.java",
211 "package a;\n" +
212 "public @interface Annotation {\n" +
213 " Values[] value();\n" +
214 "}\n");
215 this.workingCopies[2] = getWorkingCopy(
216 "/P/src/b/Test.java",
217 "import a.Annotation;\n" +
218 "package b;\n" +
219 "@Annotation({})\n" +
220 "public class Test {\n" +
221 "}\n");
222
223 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
224 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
225 String str = this.workingCopies[2].getSource();
226 String completeBehind = "Annotation({";
227 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
228 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
229 assertResults(
230 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
231 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
232 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
233 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
234 requestor.getResults());
235 } finally {
236 deleteProject("P");
237 }
238 }
testBug425035c()239 public void testBug425035c() throws CoreException {
240 try {
241 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
242 this.workingCopies = new ICompilationUnit[3];
243 this.workingCopies[0] = getWorkingCopy(
244 "/P/src/a/Values.java",
245 "package a;\n" +
246 "public enum Values {\n" +
247 " SOME_VALUE, OTHER_VALUE\n" +
248 "}\n");
249 this.workingCopies[1] = getWorkingCopy(
250 "/P/src/a/Annotation.java",
251 "package a;\n" +
252 "public @interface Annotation {\n" +
253 " Values[] value();\n" +
254 "}\n");
255 this.workingCopies[2] = getWorkingCopy(
256 "/P/src/b/Test.java",
257 "import a.Annotation;\n" +
258 "import a.Values;\n" +
259 "package b;\n" +
260 "@Annotation({Values.SOME_VALUE, })\n" +
261 "public class Test {\n" +
262 "}\n");
263
264 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
265 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
266 String str = this.workingCopies[2].getSource();
267 String completeBehind = "SOME_VALUE,";
268 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
269 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
270 assertResults(
271 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
272 "Values[TYPE_REF]{Values, a, La.Values;, null, null, 102}\n" +
273 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
274 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
275 requestor.getResults());
276 } finally {
277 deleteProject("P");
278 }
279 }
testBug425035d()280 public void testBug425035d() throws CoreException {
281 try {
282 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
283 this.workingCopies = new ICompilationUnit[3];
284 this.workingCopies[0] = getWorkingCopy(
285 "/P/src/a/Values.java",
286 "package a;\n" +
287 "public enum Values {\n" +
288 " SOME_VALUE, OTHER_VALUE\n" +
289 "}\n");
290 this.workingCopies[1] = getWorkingCopy(
291 "/P/src/a/Annotation.java",
292 "package a;\n" +
293 "public @interface Annotation {\n" +
294 " Values[] x();\n" +
295 "}\n");
296 this.workingCopies[2] = getWorkingCopy(
297 "/P/src/b/Test.java",
298 "import a.Annotation;\n" +
299 "package b;\n" +
300 "@Annotation(x=)\n" +
301 "public class Test {\n" +
302 "}\n");
303
304 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
305 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
306 String str = this.workingCopies[2].getSource();
307 String completeBehind = "Annotation(x=";
308 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
309 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
310 assertResults(
311 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
312 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
313 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
314 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
315 requestor.getResults());
316 } finally {
317 deleteProject("P");
318 }
319 }
testBug425035e()320 public void testBug425035e() throws CoreException {
321 try {
322 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
323 this.workingCopies = new ICompilationUnit[3];
324 this.workingCopies[0] = getWorkingCopy(
325 "/P/src/a/Values.java",
326 "package a;\n" +
327 "public enum Values {\n" +
328 " SOME_VALUE, OTHER_VALUE\n" +
329 "}\n");
330 this.workingCopies[1] = getWorkingCopy(
331 "/P/src/a/Annotation.java",
332 "package a;\n" +
333 "public @interface Annotation {\n" +
334 " Values[] x();\n" +
335 "}\n");
336 this.workingCopies[2] = getWorkingCopy(
337 "/P/src/b/Test.java",
338 "import a.Annotation;\n" +
339 "package b;\n" +
340 "@Annotation(x={})\n" +
341 "public class Test {\n" +
342 "}\n");
343
344 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
345 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
346 String str = this.workingCopies[2].getSource();
347 String completeBehind = "Annotation(x={";
348 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
349 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
350 assertResults(
351 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
352 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
353 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
354 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
355 requestor.getResults());
356 } finally {
357 deleteProject("P");
358 }
359 }
testBug425035f()360 public void testBug425035f() throws CoreException {
361 try {
362 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
363 this.workingCopies = new ICompilationUnit[3];
364 this.workingCopies[0] = getWorkingCopy(
365 "/P/src/a/Values.java",
366 "package a;\n" +
367 "public enum Values {\n" +
368 " SOME_VALUE, OTHER_VALUE\n" +
369 "}\n");
370 this.workingCopies[1] = getWorkingCopy(
371 "/P/src/a/Annotation.java",
372 "package a;\n" +
373 "public @interface Annotation {\n" +
374 " Values[] x();\n" +
375 "}\n");
376 this.workingCopies[2] = getWorkingCopy(
377 "/P/src/b/Test.java",
378 "import a.Annotation;\n" +
379 "import a.Values;\n" +
380 "package b;\n" +
381 "@Annotation(x={Values.SOME_VALUE, })\n" +
382 "public class Test {\n" +
383 "}\n");
384
385 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
386 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
387 String str = this.workingCopies[2].getSource();
388 String completeBehind = "SOME_VALUE,";
389 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
390 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
391 assertResults(
392 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
393 "Values[TYPE_REF]{Values, a, La.Values;, null, null, 102}\n" +
394 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
395 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
396 requestor.getResults());
397 } finally {
398 deleteProject("P");
399 }
400 }
testBug425035_method_a()401 public void testBug425035_method_a() throws CoreException {
402 try {
403 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
404 this.workingCopies = new ICompilationUnit[3];
405 this.workingCopies[0] = getWorkingCopy(
406 "/P/src/a/Values.java",
407 "package a;\n" +
408 "public enum Values {\n" +
409 " SOME_VALUE, OTHER_VALUE\n" +
410 "}\n");
411 this.workingCopies[1] = getWorkingCopy(
412 "/P/src/a/Annotation.java",
413 "package a;\n" +
414 "public @interface Annotation {\n" +
415 " Values[] value();\n" +
416 "}\n");
417 this.workingCopies[2] = getWorkingCopy(
418 "/P/src/b/Test.java",
419 "import a.Annotation;\n" +
420 "package b;\n" +
421 "public class Test {\n" +
422 " public static final int i=0;\n" +
423 " @Annotation()\n" +
424 " void f() {}\n" +
425 "}\n");
426
427 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
428 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
429 String str = this.workingCopies[2].getSource();
430 String completeBehind = "Annotation(";
431 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
432 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
433 assertResults(
434 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
435 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
436 "value[ANNOTATION_ATTRIBUTE_REF]{value = , La.Annotation;, [La.Values;, value, null, 52}\n" +
437 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
438 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
439 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
440 requestor.getResults());
441 } finally {
442 deleteProject("P");
443 }
444 }
testBug425035_method_b()445 public void testBug425035_method_b() throws CoreException {
446 try {
447 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
448 this.workingCopies = new ICompilationUnit[3];
449 this.workingCopies[0] = getWorkingCopy(
450 "/P/src/a/Values.java",
451 "package a;\n" +
452 "public enum Values {\n" +
453 " SOME_VALUE, OTHER_VALUE\n" +
454 "}\n");
455 this.workingCopies[1] = getWorkingCopy(
456 "/P/src/a/Annotation.java",
457 "package a;\n" +
458 "public @interface Annotation {\n" +
459 " Values[] value();\n" +
460 "}\n");
461 this.workingCopies[2] = getWorkingCopy(
462 "/P/src/b/Test.java",
463 "import a.Annotation;\n" +
464 "package b;\n" +
465 "public class Test {\n" +
466 " public static final int i=0;\n" +
467 " @Annotation({})\n" +
468 " void f() {}\n" +
469 "}\n");
470
471 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
472 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
473 String str = this.workingCopies[2].getSource();
474 String completeBehind = "Annotation({";
475 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
476 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
477 assertResults(
478 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
479 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
480 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
481 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
482 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
483 requestor.getResults());
484 } finally {
485 deleteProject("P");
486 }
487 }
testBug425035_method_c()488 public void testBug425035_method_c() throws CoreException {
489 try {
490 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
491 this.workingCopies = new ICompilationUnit[3];
492 this.workingCopies[0] = getWorkingCopy(
493 "/P/src/a/Values.java",
494 "package a;\n" +
495 "public enum Values {\n" +
496 " SOME_VALUE, OTHER_VALUE\n" +
497 "}\n");
498 this.workingCopies[1] = getWorkingCopy(
499 "/P/src/a/Annotation.java",
500 "package a;\n" +
501 "public @interface Annotation {\n" +
502 " Values[] value();\n" +
503 "}\n");
504 this.workingCopies[2] = getWorkingCopy(
505 "/P/src/b/Test.java",
506 "import a.Annotation;\n" +
507 "import a.Values;\n" +
508 "package b;\n" +
509 "public class Test {\n" +
510 " public static final int i=0;\n" +
511 " @Annotation({Values.SOME_VALUE, })\n" +
512 " void f() {}\n" +
513 "}\n");
514
515 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
516 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
517 String str = this.workingCopies[2].getSource();
518 String completeBehind = "SOME_VALUE,";
519 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
520 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
521 assertResults(
522 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
523 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
524 "Values[TYPE_REF]{Values, a, La.Values;, null, null, 102}\n" +
525 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
526 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
527 requestor.getResults());
528 } finally {
529 deleteProject("P");
530 }
531 }
testBug425035_method_d()532 public void testBug425035_method_d() throws CoreException {
533 try {
534 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
535 this.workingCopies = new ICompilationUnit[3];
536 this.workingCopies[0] = getWorkingCopy(
537 "/P/src/a/Values.java",
538 "package a;\n" +
539 "public enum Values {\n" +
540 " SOME_VALUE, OTHER_VALUE\n" +
541 "}\n");
542 this.workingCopies[1] = getWorkingCopy(
543 "/P/src/a/Annotation.java",
544 "package a;\n" +
545 "public @interface Annotation {\n" +
546 " Values[] x();\n" +
547 "}\n");
548 this.workingCopies[2] = getWorkingCopy(
549 "/P/src/b/Test.java",
550 "import a.Annotation;\n" +
551 "package b;\n" +
552 "public class Test {\n" +
553 " public static final int i=0;\n" +
554 " @Annotation(x=)\n" +
555 " void f() {}\n" +
556 "}\n");
557
558 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
559 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
560 String str = this.workingCopies[2].getSource();
561 String completeBehind = "Annotation(x=";
562 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
563 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
564 assertResults(
565 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
566 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
567 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
568 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
569 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
570 requestor.getResults());
571 } finally {
572 deleteProject("P");
573 }
574 }
testBug425035_method_e()575 public void testBug425035_method_e() throws CoreException {
576 try {
577 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
578 this.workingCopies = new ICompilationUnit[3];
579 this.workingCopies[0] = getWorkingCopy(
580 "/P/src/a/Values.java",
581 "package a;\n" +
582 "public enum Values {\n" +
583 " SOME_VALUE, OTHER_VALUE\n" +
584 "}\n");
585 this.workingCopies[1] = getWorkingCopy(
586 "/P/src/a/Annotation.java",
587 "package a;\n" +
588 "public @interface Annotation {\n" +
589 " Values[] x();\n" +
590 "}\n");
591 this.workingCopies[2] = getWorkingCopy(
592 "/P/src/b/Test.java",
593 "import a.Annotation;\n" +
594 "package b;\n" +
595 "public class Test {\n" +
596 " public static final int i=0;\n" +
597 " @Annotation(x={})\n" +
598 " void f() {}\n" +
599 "}\n");
600
601 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
602 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
603 String str = this.workingCopies[2].getSource();
604 String completeBehind = "Annotation(x={";
605 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
606 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
607 assertResults(
608 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
609 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
610 "Values[TYPE_REF]{a.Values, a, La.Values;, null, null, 99}\n" +
611 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
612 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
613 requestor.getResults());
614 } finally {
615 deleteProject("P");
616 }
617 }
testBug425035_method_f()618 public void testBug425035_method_f() throws CoreException {
619 try {
620 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
621 this.workingCopies = new ICompilationUnit[3];
622 this.workingCopies[0] = getWorkingCopy(
623 "/P/src/a/Values.java",
624 "package a;\n" +
625 "public enum Values {\n" +
626 " SOME_VALUE, OTHER_VALUE\n" +
627 "}\n");
628 this.workingCopies[1] = getWorkingCopy(
629 "/P/src/a/Annotation.java",
630 "package a;\n" +
631 "public @interface Annotation {\n" +
632 " Values[] x();\n" +
633 "}\n");
634 this.workingCopies[2] = getWorkingCopy(
635 "/P/src/b/Test.java",
636 "import a.Annotation;\n" +
637 "import a.Values;\n" +
638 "package b;\n" +
639 "public class Test {\n" +
640 " public static final int i=0;\n" +
641 " @Annotation(x={Values.SOME_VALUE, })\n" +
642 " void f() {}\n" +
643 "}\n");
644
645 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
646 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
647 String str = this.workingCopies[2].getSource();
648 String completeBehind = "SOME_VALUE,";
649 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
650 this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
651 assertResults(
652 "Test[TYPE_REF]{Test, b, Lb.Test;, null, null, 52}\n" +
653 "i[FIELD_REF]{i, Lb.Test;, I, i, null, 52}\n" +
654 "Values[TYPE_REF]{Values, a, La.Values;, null, null, 102}\n" +
655 "OTHER_VALUE[FIELD_REF]{Values.OTHER_VALUE, La.Values;, La.Values;, OTHER_VALUE, null, 104}\n" +
656 "SOME_VALUE[FIELD_REF]{Values.SOME_VALUE, La.Values;, La.Values;, SOME_VALUE, null, 104}",
657 requestor.getResults());
658 } finally {
659 deleteProject("P");
660 }
661 }
testBug547256()662 public void testBug547256() throws CoreException {
663 try {
664 createJavaProject("P", new String[] {"src"}, new String[]{"JCL17_LIB"}, "bin", "1.7");
665 this.workingCopies = new ICompilationUnit[1];
666 this.workingCopies[0] = getWorkingCopy(
667 "/P/src/jdt/Something.java",
668 "package jdt;\n" +
669 "public class Something {\n" +
670 " public static void main(String[] args) {\n" +
671 " done: for (int i = 0; i < 5; ++i) {\n" +
672 " if (i == 3) {\n" +
673 " break done;\n" +
674 " }\n" +
675 " System.out.println(i);\n" +
676 " }\n" +
677 " arg\n" +
678 " System.out.println(\"done\");\n" +
679 " }\n" +
680 "}\n");
681 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
682 requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true);
683 String str = this.workingCopies[0].getSource();
684 String completeBehind = "arg";
685 int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
686 this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
687 assertResults(
688 "args[LOCAL_VARIABLE_REF]{args, null, [Ljava.lang.String;, args, null, 52}",
689 requestor.getResults());
690
691 } finally {
692 deleteProject("P");
693 }
694 }
695 }
696