Closed ZenLiuCN closed 2 months ago
It looks like yield
not supported yet?
Can you try setting the compliance level on the environment to a Version supporting that? Maybe 17 or 20 or whatever your code needs.
code without yield
is fine.
package spoon.bug;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeKind.*;
public interface Sample {
Object N = null;
static Object lookup(TypeMirror type) {
final Object v;
switch (type.getKind()) {
case BOOLEAN ->v= N;
case BYTE ->v= N;
case SHORT ->v= N;
case INT ->v= N;
case LONG ->v= N;
case CHAR ->v= N;
case FLOAT ->v= N;
case DOUBLE ->v= N;
case ARRAY -> {
var ct = ((ArrayType) type).getComponentType();
switch (ct.getKind()) {
case BOOLEAN ->v=N;
case BYTE ->v= N;
case SHORT ->v= N;
case INT ->v= N;
case LONG ->v= N;
case CHAR ->v= N;
case FLOAT ->v= N;
case DOUBLE ->v= N;
case ARRAY, DECLARED ->v= N;
default -> throw new IllegalStateException("");
};
}
case DECLARED -> {
var dt = (DeclaredType) type;
v= switch (dt.getTypeArguments().size()) {
//simple
case 0 -> switch (dt.asElement().getSimpleName().toString()) {
case "Boolean" -> N;
case "Integer" -> N;
case "String" -> N;
case "Buffer" -> N;
case "Number" -> N;
case "BigDecimal" -> N;
case "Long" -> N;
case "Float" -> N;
case "Double" -> N;
case "Instant" -> N;
case "Duration" -> N;
case "JsonArray" -> N;
case "JsonObject" -> N;
default -> {
throw new IllegalStateException("");
}
};
case 1 -> {
throw new IllegalStateException("");
}
case 2 -> {
throw new IllegalStateException("");
}
default -> {
throw new IllegalStateException("");
}
};
}
default -> throw new IllegalStateException("");
};
return v;
}
}
The default compliance level is 8 (I think), so yield will not be accepted. If you change the level to something supporting it and it still breaks, then spoon has a bug. Otherwise this is just spoon trying to use Java 8 rules to parse Java 13+ code, which can break. If that is your problem, the error message isn't quite the most helpful though.
Can you try setting the compliance level on the environment to a Version supporting that? Maybe 17 or 20 or whatever your code needs.
added l.getEnvironment().setComplianceLevel(17);
, it's ok. so it not bug.
My bad to assume that language levels are defualt to the JDK levels.
Thanks very much.
To default has not been useful for years now, but changing that is a bit hard to do now in a backwards compatible way. The best default is probably not to have one and require that...
To default has not been useful for years now, but changing that is a bit hard to do now in a backwards compatible way. The best default is probably not to have one and require that...
I like this idea. Hidden nothing may reduce many mistakes.
Describe the bug
Use spoon to compile the source cause
java.lang.RuntimeException: Inconsistent Stack static Object lookup(TypeMirror type)
. It may something wrong with spoon to parse nesting enumration expression switch statement.debugging located in
spoon.support.compiler.jdt.ContextBuilder
It seems that maybe the parse stage not resolve the right node. (same code is compiled with just jdk).
Source code you are trying to analyze/transform
Source code for your Spoon processing
Actual output
Expected output
No response
Spoon Version
10.4.1
JVM Version
17.0.10
What operating system are you using?
windows 10