Skip to content

Improving Java code completion support for sealed types in switches.#7966

Merged
lahodaj merged 1 commit intoapache:masterfrom
lahodaj:switch-sealed-code-completion
Dec 2, 2024
Merged

Improving Java code completion support for sealed types in switches.#7966
lahodaj merged 1 commit intoapache:masterfrom
lahodaj:switch-sealed-code-completion

Conversation

@lahodaj
Copy link
Copy Markdown
Contributor

@lahodaj lahodaj commented Nov 14, 2024

Consider code like:

package sealed.test;

public class SealedTest {
    private int test(I i) {
        return switch (i) {
            case /*invoke code completion here*/
        };
    }

    public sealed interface I {}
    public final class A implements I {}
    public final class B implements I {}
    public class E extends Exception {}
    public enum AI implements I {A, B, C;}
}

The (Java) code completion returns all types at the specified place, instead of just subtypes of i. This patch is trying to solve that, by using the selector's type as a base type, and hence only proposing the correct subclasses/interfaces.

The patch is sadly a bit biggish, partly as it seems I need to add smartType flag to createStaticMemberItem. The code is also tricky around qualified enum constants (which are permitted since JDK 21).

There may be further improvements possible, but I hope this PR leads to a not completely unreasonable state.

@lahodaj lahodaj added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension labels Nov 14, 2024
@lahodaj lahodaj added this to the NB25 milestone Nov 14, 2024
@lahodaj lahodaj requested a review from dbalek November 14, 2024 16:27
@lahodaj lahodaj force-pushed the switch-sealed-code-completion branch from effe121 to c4a0e1b Compare November 29, 2024 14:21
@lahodaj lahodaj force-pushed the switch-sealed-code-completion branch from c4a0e1b to bbdc51e Compare December 2, 2024 07:12
@lahodaj lahodaj merged commit 6b34b88 into apache:master Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants