Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lahodaj
Copy link
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 [ci] enable VSCode Extension tests 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
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 [ci] enable VSCode Extension tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants