1515package org .eclipse .jdt .core .tests .model ;
1616
1717import junit .framework .Test ;
18- import org .eclipse .core .resources .IFile ;
1918import org .eclipse .core .runtime .CoreException ;
20- import org .eclipse .core .runtime .IPath ;
2119import org .eclipse .jdt .core .ICompilationUnit ;
2220import org .eclipse .jdt .core .IJavaProject ;
23- import org .eclipse .jdt .core .JavaCore ;
2421import org .eclipse .jdt .core .JavaModelException ;
2522
2623public class CompletionTests23 extends AbstractJavaModelCompletionTests {
@@ -41,7 +38,6 @@ public CompletionTests23(String name) {
4138@ Override
4239public void setUpSuite () throws Exception {
4340 this .completion23Project = setUpJavaProject ("Completion23" , "23" , false );
44- this .completion23Project .setOption (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .ENABLED );
4541 super .setUpSuite ();
4642}
4743@ Override
@@ -53,269 +49,52 @@ public static Test suite() {
5349 return buildModelTestSuite (CompletionTests23 .class );
5450}
5551
56- public void testKeyword () throws JavaModelException {
57- this .workingCopies = new ICompilationUnit [1 ];
58- this .workingCopies [0 ] = getWorkingCopy (
59- "/Completion23/src/p/X.java" ,
60- """
61- package p;
62- import m
63- public class X {}
64- """ );
52+ // === positive tests for module imports have moved to CompletionTests25 ===
6553
66- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
67- requestor .allowAllRequiredProposals ();
68- String str = this .workingCopies [0 ].getSource ();
69- String completeBehind = "import m" ;
70- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
71- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
72- int relevanceWithoutCase = DEFAULT_RELEVANCE - R_CASE ;
73- assertResults (
74- "Map[TYPE_REF]{java.util.Map;, java.util, Ljava.util.Map;, null, null, " +relevanceWithoutCase +"}\n " +
75- "MethodHandle[TYPE_REF]{java.lang.invoke.MethodHandle;, java.lang.invoke, Ljava.lang.invoke.MethodHandle;, null, null, " +relevanceWithoutCase +"}\n " +
76- "MethodHandles[TYPE_REF]{java.lang.invoke.MethodHandles;, java.lang.invoke, Ljava.lang.invoke.MethodHandles;, null, null, " +relevanceWithoutCase +"}\n " +
77- "MethodType[TYPE_REF]{java.lang.invoke.MethodType;, java.lang.invoke, Ljava.lang.invoke.MethodType;, null, null, " +relevanceWithoutCase +"}\n " +
78- "module[KEYWORD]{module, null, null, module, null, " + DEFAULT_RELEVANCE + "}" ,
79- requestor .getResults ());
80- }
8154public void testKeyword_neg () throws JavaModelException {
8255 // keyword not enabled, other proposals don't match
83- this .completion23Project .setOption (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .DISABLED );
84- try {
85- this .workingCopies = new ICompilationUnit [1 ];
86- this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
87- package p;
88- import mod
89- public class X {}
90- """ );
91- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
92- requestor .allowAllRequiredProposals ();
93- String str = this .workingCopies [0 ].getSource ();
94- String completeBehind = "import mod" ;
95- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
96- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
97- assertResults (
98- "" ,
99- requestor .getResults ());
100- } finally {
101- this .completion23Project .setOption (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .ENABLED );
102- }
103- }
104-
105- public void test001 () throws JavaModelException {
106- // prefixed
107- // only java.base available (from JCL_23_LIB)
10856 this .workingCopies = new ICompilationUnit [1 ];
109- this .workingCopies [0 ] = getWorkingCopy (
110- "/Completion23/src/p/X.java" ,
111- """
57+ this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
11258 package p;
113- import module java.
59+ import mod
11460 public class X {}
11561 """ );
116-
117- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true , false , true );
62+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
11863 requestor .allowAllRequiredProposals ();
11964 String str = this .workingCopies [0 ].getSource ();
120- String completeBehind = "java." ;
121- int nameStart = str .lastIndexOf (completeBehind );
122- int cursorLocation = nameStart + completeBehind .length ();
65+ String completeBehind = "import mod" ;
66+ int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
12367 this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
12468 assertResults (
125- "[MODULE_REF]{java.base, java.base, null, null, null, [" + nameStart + ", " + cursorLocation + "], " + DEFAULT_RELEVANCE + "} " ,
69+ "" ,
12670 requestor .getResults ());
12771}
12872
12973public void test001_neg () throws JavaModelException {
13074 // prefixed
13175 // only java.base available (from JCL_23_LIB)
132- // preview JEP 476 not enabled
76+ // module imports not enabled
13377 // other proposals don't match prefix
134- this .completion23Project .setOption (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .DISABLED );
135- try {
136- this .workingCopies = new ICompilationUnit [1 ];
137- this .workingCopies [0 ] = getWorkingCopy (
138- "/Completion23/src/p/X.java" ,
139- """
140- package p;
141- import module java.b
142- public class X {}
143- """ );
144-
145- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
146- requestor .allowAllRequiredProposals ();
147- String str = this .workingCopies [0 ].getSource ();
148- String completeBehind = "java.b" ;
149- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
150- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
151- assertResults (
152- "" ,
153- requestor .getResults ());
154- } finally {
155- this .completion23Project .setOption (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .ENABLED );
156- }
157- }
158-
159- public void test002 () throws JavaModelException {
160- // no prefix
161- // only java.base available (from JCL_23_LIB)
16278 this .workingCopies = new ICompilationUnit [1 ];
16379 this .workingCopies [0 ] = getWorkingCopy (
16480 "/Completion23/src/p/X.java" ,
16581 """
16682 package p;
167- import module\s
83+ import module java.b
16884 public class X {}
16985 """ );
17086
17187 CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
17288 requestor .allowAllRequiredProposals ();
17389 String str = this .workingCopies [0 ].getSource ();
174- String completeBehind = "module " ;
90+ String completeBehind = "java.b " ;
17591 int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
17692 this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
17793 assertResults (
178- "[MODULE_REF]{java.base, java.base, null, null, null, " + DEFAULT_RELEVANCE + "} " ,
94+ "" ,
17995 requestor .getResults ());
18096}
18197
182- public void test003 () throws JavaModelException {
183- // no prefix
184- // 2 modules available: mod.one & java.base
185- // unnamed module reads them all
186- IPath jarPath = this .completion23Project .getPath ().append ("mod.one.jar" );
187- try {
188- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarPath , null , null ));
189- this .workingCopies = new ICompilationUnit [1 ];
190- this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
191- package p;
192- import module\s
193- public class X {}
194- """ );
195- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
196- requestor .allowAllRequiredProposals ();
197- String str = this .workingCopies [0 ].getSource ();
198- String completeBehind = "module " ;
199- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
200- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
201- assertResults (
202- "[MODULE_REF]{java.base, java.base, null, null, null, " + DEFAULT_RELEVANCE + "}\n " +
203- "[MODULE_REF]{mod.one, mod.one, null, null, null, " + DEFAULT_RELEVANCE + "}" ,
204- requestor .getResults ());
205- } finally {
206- removeClasspathEntry (this .completion23Project , jarPath );
207- }
208- }
209-
210- public void test004 () throws JavaModelException {
211- // with prefix
212- // 3 modules on the module path: mod.two, mod.one & java.base
213- // prefix selects 2 out of 3
214- IPath jarOnePath = this .completion23Project .getPath ().append ("mod.one.jar" );
215- IPath jarTwoPath = this .completion23Project .getPath ().append ("mod.two.jar" );
216- try {
217- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarOnePath , null , null ));
218- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarTwoPath , null , null ));
219- this .workingCopies = new ICompilationUnit [1 ];
220- this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
221- package p;
222- import module mo
223- public class X {}
224- """ );
225- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
226- requestor .allowAllRequiredProposals ();
227- String str = this .workingCopies [0 ].getSource ();
228- String completeBehind = "module mo" ;
229- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
230- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
231- assertResults (
232- "[MODULE_REF]{mod.one, mod.one, null, null, null, " + DEFAULT_RELEVANCE + "}\n " +
233- "[MODULE_REF]{mod.two, mod.two, null, null, null, " + DEFAULT_RELEVANCE + "}" ,
234- requestor .getResults ());
235- } finally {
236- removeClasspathEntry (this .completion23Project , jarOnePath );
237- removeClasspathEntry (this .completion23Project , jarTwoPath );
238- }
239- }
240-
241- public void test005 () throws CoreException {
242- // with prefix
243- // 4 modules available: mod.test (self), mod.two (required), mod.one (transitively required) & java.base (from JCL_23_LIB)
244- // prefix selects 3 out of 4
245- IPath jarOnePath = this .completion23Project .getPath ().append ("mod.one.jar" );
246- IPath jarTwoPath = this .completion23Project .getPath ().append ("mod.two.jar" );
247- IFile moduleFile = null ;
248- try {
249- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarOnePath , null , null ));
250- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarTwoPath , null , null ));
251- moduleFile = createFile ("Completion23/src/module-info.java" ,
252- """
253- module mod.test {
254- requires mod.two; // mod.two requires transitive mod.one
255- }
256- """ );
257- this .workingCopies = new ICompilationUnit [1 ];
258- this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
259- package p;
260- import module mo
261- public class X {}
262- """ );
263- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
264- requestor .allowAllRequiredProposals ();
265- String str = this .workingCopies [0 ].getSource ();
266- String completeBehind = "module mo" ;
267- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
268- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
269- assertResults (
270- "[MODULE_REF]{mod.one, mod.one, null, null, null, " + DEFAULT_RELEVANCE + "}\n " +
271- "[MODULE_REF]{mod.test, mod.test, null, null, null, " + DEFAULT_RELEVANCE + "}\n " +
272- "[MODULE_REF]{mod.two, mod.two, null, null, null, " + DEFAULT_RELEVANCE + "}" ,
273- requestor .getResults ());
274- } finally {
275- removeClasspathEntry (this .completion23Project , jarOnePath );
276- removeClasspathEntry (this .completion23Project , jarTwoPath );
277- if (moduleFile != null )
278- deleteResource (moduleFile );
279- }
280- }
281- public void test006 () throws CoreException {
282- // with prefix
283- // 4 modules present: mod.test(self), mod.one, mod.two & java.base available
284- // + prefix rules out java.base
285- // + mod.two is proposed with lower relevance, because it is not read by the current module
286- IPath jarOnePath = this .completion23Project .getPath ().append ("mod.one.jar" );
287- IPath jarTwoPath = this .completion23Project .getPath ().append ("mod.two.jar" );
288- try {
289- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarOnePath , null , null ));
290- addClasspathEntry (this .completion23Project , newModularLibraryEntry (jarTwoPath , null , null )); // not read my the current module
291- createFile ("Completion23/src/module-info.java" ,
292- """
293- module mod.test {
294- requires mod.one;
295- }
296- """ );
297- this .workingCopies = new ICompilationUnit [1 ];
298- this .workingCopies [0 ] = getWorkingCopy ("/Completion23/src/p/X.java" , """
299- package p;
300- import module mo
301- public class X {}
302- """ );
303- CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2 (true );
304- requestor .allowAllRequiredProposals ();
305- String str = this .workingCopies [0 ].getSource ();
306- String completeBehind = "module mo" ;
307- int cursorLocation = str .lastIndexOf (completeBehind ) + completeBehind .length ();
308- this .workingCopies [0 ].codeComplete (cursorLocation , requestor , this .wcOwner );
309- assertResults (
310- "[MODULE_REF]{mod.two, mod.two, null, null, null, " + (DEFAULT_RELEVANCE - R_NON_RESTRICTED ) + "}\n " + // lower relevance, not read
311- "[MODULE_REF]{mod.one, mod.one, null, null, null, " + DEFAULT_RELEVANCE + "}\n " +
312- "[MODULE_REF]{mod.test, mod.test, null, null, null, " + DEFAULT_RELEVANCE + "}" ,
313- requestor .getResults ());
314- } finally {
315- removeClasspathEntry (this .completion23Project , jarOnePath );
316- removeClasspathEntry (this .completion23Project , jarTwoPath );
317- }
318- }
31998
32099public void testMarkdownTypeLink1 () throws CoreException {
321100 createFolder ("/Completion23/src/javadoc" );
0 commit comments