-
Notifications
You must be signed in to change notification settings - Fork 409
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
"Cannot mix pattern with other case labels" Java 21 + preview feature #3043
Comments
I use latest jdtls snapshot (at time of writing jdt-language-server-1.33.0-202402030358), Many "movable parts" where things can go wrong... 😅 |
Ah,
I'll see if I can figure out how to launch that compiler on my Edit, ecj.jshif (! Files.exists(Path.of("ecj.jar"))) {
Files.write(Path.of("ecj.jar"), URI.create(
"https://repo1.maven.org/maven2/org/eclipse/jdt/ecj/3.36.0/ecj-3.36.0.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path ecj.jar
Files.writeString(Path.of("Main.java"), """
class Main {
sealed interface OneTwoThree {}
record One() implements OneTwoThree {}
record Two() implements OneTwoThree {}
record Three() implements OneTwoThree {}
public static void main(String[] args) {
OneTwoThree value = new Three();
String message = switch(value) {
case One one -> "One!";
case Two _,
Three _ -> "Two or Three!";
};
System.out.println(message);
}
}
""");
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
import org.eclipse.jdt.core.compiler.CompilationProgress;
class MyCompilationProgress extends CompilationProgress {
public void begin(int remainingWork) {}
public void done() {}
public boolean isCanceled() { return false; }
public void setTaskName(String name) { System.out.println("Task: " + name); }
public void worked(int workIncrement, int remainingWork) {}
}
var out = new StringWriter();
var err = new StringWriter();
String command = "--enable-preview -source 21 Main.java";
//command = "-help"
boolean success = BatchCompiler.compile(
command,
new PrintWriter(out),
new PrintWriter(err),
new MyCompilationProgress()
);
System.out.println(String.join("\n",
success ? "Success!" : "Nope",
out.toString(),
err.toString()));
/exit
|
That's a question for @datho7561, since he implemented unnamed variables support in JDT |
I split the "unnamed variables and patterns" feature into two separate PRs, one for the base feature and one for supporting lists of patterns in case statements. The second part hasn't been reviewed or merged yet:
They are hesitant about reviewing my PR upstream since they want to rewrite a lot of the code that my PR touches before merging my PR. I guess we should consider merging my PR into our fork @rgrunber . My main concern is that this means maintaining our fork gets harder once they start making the changes to the code that conflict with my PR. |
Today I tried with jdt-language-server-1.34.0-202403261717 , |
@tors42 I too use the same versions of all these software, except my JDTLS version is 1.35.0, but still I can't get JDK 21 support. I get error messages like "String cannot be resolved to a type", etc. Any specific configuration to be done? |
src/main/java/pkg/Main.java
pom.xml
jdtls reports "Cannot mix pattern with other case labels" error,
while
java
happily runs:The text was updated successfully, but these errors were encountered: