-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for Java 22 (JEP 456). #4771
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
base: master
Are you sure you want to change the base?
Conversation
Thank you for this PR. That seems correct even if I don't know what the impact will be on the LPP and the symbol resolver. Perhaps you could add tests on the LPP. Can you enhance the tests with switch pattern tests? You can take inspiration from https://www.baeldung.com/java-unnamed-patterns-variables |
Thanks for quick feedback. All code in this commit is ai generated. I hope that is ok. First time I use the Cursor IDE, I wanted to see if I’m able to add support for new Java support and it worked pretty well. Also the additional unit tests are generated and I used the web link as reference for adding them. So I think we should have pretty well test coverage now |
There are far too many redundant tests, and others that are useless. What I was asking for was just to add tests on switch patterns. You can completely undo the last commit. Please check what the AI produces. |
Sorry for not checking the test carefully. I have pushed a new patch set which removes all the redundant and useless test hopefully. |
Please squash your commit and add unit tests on switch pattern. |
I get an annoying fault from time to time that generated classes are missing during "mvn clean install" I don't know if I do something wrong, it is files that I have never touched. [ERROR] There was an error in the forked process |
I have updated my PR, but I will need to double check the syntax of some of the test that I have added. |
mvn clean install is all you need to build the project. |
} | ||
|
||
@Test | ||
void validSwitchPatternWithUnnamedPattern() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a switch pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed
} | ||
|
||
@Test | ||
void invalidUnnamedVariableReferenceInSwitchPattern() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no switch pattern here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
} | ||
|
||
@Test | ||
void validSwitchWithRecordPatternAndUnnamedFields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
} | ||
|
||
@Test | ||
void validSwitchWithNestedRecordPatternAndUnnamedFields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test is useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
} | ||
|
||
@Test | ||
void validSwitchWithComplexGuardAndUnnamedPatterns() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -100,4 +101,163 @@ public void nestedSwitchRecordPatternShouldResolve() { | |||
NameExpr name = Navigator.findNameExpression(cu, "s").get(); | |||
assertEquals("java.lang.String", name.resolve().getType().describe()); | |||
} | |||
|
|||
@Test | |||
public void switchPatternUnnamedPatternShouldNotResolveInWrongScope() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
Globally, there are still far too many unnecessary or poorly named unit tests. |
There are a few more complicated switch pattern that will be unsupported by this commit. |
Please squash your commits. |
the commits are already squashed, I did a rebase -i and a forced push. so there is only one commit now. |
@@ -100,4 +101,146 @@ public void nestedSwitchRecordPatternShouldResolve() { | |||
NameExpr name = Navigator.findNameExpression(cu, "s").get(); | |||
assertEquals("java.lang.String", name.resolve().getType().describe()); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the only useful tests are those that try to resolve an unnamed variable or a method call for which the parameter is an unnamed variable (although I don't know if this is allowed by the specification).
@@ -0,0 +1,344 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it seems to me that the tests should only validate support for unnamed variables and that the more precise tests should be carried out in the test classes which are more specific to the case. For example, for switch patterns, the more detailed tests need to be implemented in the SwitchExprTest class. This is typically what was done when the record pattern was implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, Move all Switch test
} | ||
|
||
@Test | ||
@Disabled("Parser grammar doesn't support mixed named/unnamed fields in record patterns (JEP 456). Requires JavaCC grammar updates.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What errors are produced by disabled tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.opentest4j.AssertionFailedError: [Encountered unexpected token: "color"
at line 1, column 35.
Was expecting one of:
"!="
"%"
"%="
"&"
"&&"
"&="
"("
")"
"*"
"*="
"+"
"+="
","
"-"
"-="
"->"
"/"
"/="
"::"
"<"
"<<="
"<="
"="
"=="
">"
">="
">>="
">>>="
"?"
"^"
"^="
"instanceof"
"|"
"|="
"||"
Problem stacktrace :
com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14486)
com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:14331)
com.github.javaparser.GeneratedJavaParser.Arguments(GeneratedJavaParser.java:5454)
com.github.javaparser.GeneratedJavaParser.PrimaryPrefix(GeneratedJavaParser.java:5154)
com.github.javaparser.GeneratedJavaParser.PrimaryExpression(GeneratedJavaParser.java:4843)
com.github.javaparser.GeneratedJavaParser.PostfixExpression(GeneratedJavaParser.java:4704)
com.github.javaparser.GeneratedJavaParser.UnaryExpressionNotPlusMinus(GeneratedJavaParser.java:4674)
com.github.javaparser.GeneratedJavaParser.UnaryExpression(GeneratedJavaParser.java:4544)
com.github.javaparser.GeneratedJavaParser.MultiplicativeExpression(GeneratedJavaParser.java:4404)
com.github.javaparser.GeneratedJavaParser.AdditiveExpression(GeneratedJavaParser.java:4356)
com.github.javaparser.GeneratedJavaParser.ShiftExpression(GeneratedJavaParser.java:4311)
com.github.javaparser.GeneratedJavaParser.RelationalExpression(GeneratedJavaParser.java:4251)
com.github.javaparser.GeneratedJavaParser.InstanceOfExpression(GeneratedJavaParser.java:4167)
com.github.javaparser.GeneratedJavaParser.EqualityExpression(GeneratedJavaParser.java:3990)
com.github.javaparser.GeneratedJavaParser.AndExpression(GeneratedJavaParser.java:3945)
com.github.javaparser.GeneratedJavaParser.ExclusiveOrExpression(GeneratedJavaParser.java:3905)
com.github.javaparser.GeneratedJavaParser.InclusiveOrExpression(GeneratedJavaParser.java:3865)
com.github.javaparser.GeneratedJavaParser.ConditionalAndExpression(GeneratedJavaParser.java:3825)
com.github.javaparser.GeneratedJavaParser.ConditionalOrExpression(GeneratedJavaParser.java:3780)
com.github.javaparser.GeneratedJavaParser.ConditionalExpression(GeneratedJavaParser.java:3748)
com.github.javaparser.GeneratedJavaParser.SwitchEntry(GeneratedJavaParser.java:6553)
com.github.javaparser.GeneratedJavaParser.SwitchExpression(GeneratedJavaParser.java:6436)
com.github.javaparser.GeneratedJavaParser.UnaryExpressionNotPlusMinus(GeneratedJavaParser.java:4678)
com.github.javaparser.GeneratedJavaParser.UnaryExpression(GeneratedJavaParser.java:4544)
com.github.javaparser.GeneratedJavaParser.MultiplicativeExpression(GeneratedJavaParser.java:4404)
com.github.javaparser.GeneratedJavaParser.AdditiveExpression(GeneratedJavaParser.java:4356)
com.github.javaparser.GeneratedJavaParser.ShiftExpression(GeneratedJavaParser.java:4311)
com.github.javaparser.GeneratedJavaParser.RelationalExpression(GeneratedJavaParser.java:4251)
com.github.javaparser.GeneratedJavaParser.InstanceOfExpression(GeneratedJavaParser.java:4167)
com.github.javaparser.GeneratedJavaParser.EqualityExpression(GeneratedJavaParser.java:3990)
com.github.javaparser.GeneratedJavaParser.AndExpression(GeneratedJavaParser.java:3945)
com.github.javaparser.GeneratedJavaParser.ExclusiveOrExpression(GeneratedJavaParser.java:3905)
com.github.javaparser.GeneratedJavaParser.InclusiveOrExpression(GeneratedJavaParser.java:3865)
com.github.javaparser.GeneratedJavaParser.ConditionalAndExpression(GeneratedJavaParser.java:3825)
com.github.javaparser.GeneratedJavaParser.ConditionalOrExpression(GeneratedJavaParser.java:3780)
com.github.javaparser.GeneratedJavaParser.ConditionalExpression(GeneratedJavaParser.java:3748)
com.github.javaparser.GeneratedJavaParser.Expression(GeneratedJavaParser.java:3558)
com.github.javaparser.GeneratedJavaParser.ExpressionParseStart(GeneratedJavaParser.java:8692)
com.github.javaparser.JavaParser.parse(JavaParser.java:125)
com.github.javaparser.JavaParser.parseExpression(JavaParser.java:342)
com.github.javaparser.utils.TestParser.parseExpression(TestParser.java:64)
com.github.javaparser.ast.expr.SwitchExprTest.testSwitchWithRecordPatternAndUnnamedFields(SwitchExprTest.java:504)
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
java.base/java.lang.reflect.Method.invoke(Method.java:580)
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:787)
org.junit.platform.commons.support.ReflectionSupport.invokeMethod(ReflectionSupport.java:479)
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:161)
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:152)
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:91)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:112)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:94)
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:93)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:87)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$4(TestMethodTestDescriptor.java:221)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:217)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:159)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:70)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:157)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:147)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:145)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:144)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:101)
java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:161)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:147)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:145)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:144)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:101)
java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:161)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:147)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:145)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:144)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:101)
org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.executeEngine(EngineExecutionOrchestrator.java:230)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.failOrExecuteEngine(EngineExecutionOrchestrator.java:204)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:172)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:101)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:64)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:150)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:63)
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:109)
org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:91)
org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
org.junit.platform.launcher.core.InterceptingLauncher.lambda$execute$1(InterceptingLauncher.java:39)
org.junit.platform.launcher.core.ClasspathAlignmentCheckingLauncherInterceptor.intercept(ClasspathAlignmentCheckingLauncherInterceptor.java:25)
org.junit.platform.launcher.core.InterceptingLauncher.execute(InterceptingLauncher.java:38)
org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:66)
com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)]
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:138)
at com.github.javaparser.utils.TestParser.unpack(TestParser.java:50)
at com.github.javaparser.utils.TestParser.parseExpression(TestParser.java:64)
at com.github.javaparser.ast.expr.SwitchExprTest.testSwitchWithRecordPatternAndUnnamedFields(SwitchExprTest.java:504)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
*/ | ||
final VisitorValidator unnamedReferenceValidator = new VisitorValidator() { | ||
@Override | ||
public void visit(NameExpr n, ProblemReporter reporter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment I don't know if this is the best solution for validating the syntax.
} | ||
|
||
@Override | ||
public void visit(SimpleName n, ProblemReporter reporter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment I don't know if this is the best solution for validating the syntax.
Fixes #4713.