Skip to content

Commit 06f69ad

Browse files
authored
No code completion in JEP 512: Compact Source Files with static variables eclipse-jdt#4796 (eclipse-jdt#4818)
1 parent 2875481 commit 06f69ad

File tree

2 files changed

+45
-0
lines changed
  • org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model
  • org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl

2 files changed

+45
-0
lines changed

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests25.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.core.runtime.CoreException;
2020
import org.eclipse.core.runtime.IPath;
2121
import org.eclipse.jdt.core.ICompilationUnit;
22+
import org.eclipse.jdt.core.IJavaElement;
2223
import org.eclipse.jdt.core.IJavaProject;
2324
import org.eclipse.jdt.core.JavaModelException;
2425

@@ -262,4 +263,46 @@ public class X {}
262263
removeClasspathEntry(this.completion25Project, jarTwoPath);
263264
}
264265
}
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+
}
265308
}

org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/Engine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ private ASTNode parseBlockStatements(
346346
int length = methods.length;
347347
for (int i = 0; i < length; i++) {
348348
AbstractMethodDeclaration method = methods[i];
349+
if (type.isImplicitType() && method.isClinit())
350+
continue;
349351
if (method.bodyStart > position + 1)
350352
continue;
351353

0 commit comments

Comments
 (0)