|
19 | 19 | import org.eclipse.core.runtime.CoreException; |
20 | 20 | import org.eclipse.core.runtime.IPath; |
21 | 21 | import org.eclipse.jdt.core.ICompilationUnit; |
| 22 | +import org.eclipse.jdt.core.IJavaElement; |
22 | 23 | import org.eclipse.jdt.core.IJavaProject; |
23 | 24 | import org.eclipse.jdt.core.JavaModelException; |
24 | 25 |
|
@@ -262,4 +263,46 @@ public class X {} |
262 | 263 | removeClasspathEntry(this.completion25Project, jarTwoPath); |
263 | 264 | } |
264 | 265 | } |
| 266 | +public void testGH4796_1() throws JavaModelException { |
| 267 | + this.workingCopies = new ICompilationUnit[1]; |
| 268 | + this.workingCopies[0] = getWorkingCopy( |
| 269 | + "/Completion25/src/X.java", |
| 270 | + """ |
| 271 | + static final String CODE = "001"; |
| 272 | + void main() { |
| 273 | + System.out.println("This is a simple code snippet with code: " + CODE); |
| 274 | + Str |
| 275 | + } |
| 276 | + """); |
| 277 | + |
| 278 | + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); |
| 279 | + requestor.allowAllRequiredProposals(); |
| 280 | + String str = this.workingCopies[0].getSource(); |
| 281 | + String completeBehind = "Str"; |
| 282 | + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); |
| 283 | + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); |
| 284 | + assertResults( |
| 285 | + "String[TYPE_REF]{java.lang.String, java.lang, Ljava.lang.String;, null, null, 51}\n" |
| 286 | + + "StringConcatFactory[TYPE_REF]{java.lang.invoke.StringConcatFactory, java.lang.invoke, Ljava.lang.invoke.StringConcatFactory;, null, null, 51}\n" |
| 287 | + + "StringTemplate[TYPE_REF]{java.lang.StringTemplate, java.lang, Ljava.lang.StringTemplate;, null, null, 51}", |
| 288 | + requestor.getResults()); |
| 289 | +} |
| 290 | +public void testGH4796_2() throws JavaModelException { |
| 291 | + String str = |
| 292 | + """ |
| 293 | + static final String CODE = "001"; |
| 294 | + void main() { |
| 295 | + System.out.println("This is a simple code snippet with code: " + CODE); |
| 296 | + } |
| 297 | + """; |
| 298 | + this.workingCopies = new ICompilationUnit[1]; |
| 299 | + this.workingCopies[0] = getWorkingCopy("/Completion25/src/X.java", str); |
| 300 | + String selectionStr = "println"; |
| 301 | + |
| 302 | + IJavaElement[] elements = this.workingCopies[0].codeSelect(str.indexOf(selectionStr), selectionStr.length()); |
| 303 | + assertNotNull(elements); |
| 304 | + assertEquals("Incorrect no of selection elements", 1, elements.length); |
| 305 | + assertEquals("Incorect type of selection element", IJavaElement.METHOD, elements[0].getElementType()); |
| 306 | + assertEquals("Incorect type of selection element", "println", elements[0].getElementName()); |
| 307 | +} |
265 | 308 | } |
0 commit comments