From 3eb741f97331662b5e08ae988a6c124eed607d50 Mon Sep 17 00:00:00 2001 From: Srikanth Sankaran <131454720+srikanth-sankaran@users.noreply.github.com> Date: Fri, 14 Jun 2024 14:03:13 +0530 Subject: [PATCH] [Sealed types] Completion fails within the body of a permitted class (#2568) * Regression test for https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2540 --- .../core/tests/model/CompletionTests17.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java index 769d07af8ca..06e696ae5ee 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests17.java @@ -740,4 +740,28 @@ public sealed interface SealedI p { permits[RESTRICTED_IDENTIFIER]{permits, null, null, permits, null, 49}\ """, requestor.getResults()); } + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2540 + // Completion fails within the body of a permitted class + public void testGH2540() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy("/Completion/src/Storage.java", """ + public sealed class Storage permits SqlStorage { + }\ + """); + this.workingCopies[1] = getWorkingCopy("/Completion/src/SqlStorage.java", """ + public final class SqlStorage extends Storage { + /*here*/Sq + }\ + """); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[1].getSource(); + String completeBehind = "/*here*/Sq"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[1].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults(""" + Sq[POTENTIAL_METHOD_DECLARATION]{Sq, LSqlStorage;, ()V, Sq, null, 39} + SqlStorage[TYPE_REF]{SqlStorage, , LSqlStorage;, null, null, 52}\ + """, requestor.getResults()); + } }