Skip to content

Conversation

martinaldrin
Copy link

Fixes #4713.

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 4, 2025

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

@martinaldrin
Copy link
Author

martinaldrin commented Jun 4, 2025

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

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 4, 2025

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.

@martinaldrin
Copy link
Author

Sorry for not checking the test carefully. I have pushed a new patch set which removes all the redundant and useless test hopefully.

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 5, 2025

Please squash your commit and add unit tests on switch pattern.

@martinaldrin
Copy link
Author

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.
I try everything by regenerate classes, rebuild and some time it is working and sometimes not.
Do I do something wrong during build of the project?

[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-jupiter' encountered a critical issue during test discovery:
[ERROR]
[ERROR] (1) [ERROR] ClassSelector [className = 'com.github.javaparser.remove.NodeRemovalTest', classLoader = null] resolution failed
[ERROR] Source: ClassSource [className = 'com.github.javaparser.remove.NodeRemovalTest', filePosition = null]
[ERROR] at com.github.javaparser.remove.NodeRemovalTest.(SourceFile:0)
[ERROR] Cause: java.lang.NoClassDefFoundError: Node
[ERROR] at java.lang.Class.getDeclaredMethods0(Native Method)
[ERROR] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[ERROR] at java.lang.Class.getDeclaredMethods(Class.java:1975)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:1792)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.findAllMethodsInHierarchy(ReflectionUtils.java:1732)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.getSuperclassMethods(ReflectionUtils.java:1945)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.findAllMethodsInHierarchy(ReflectionUtils.java:1735)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.streamMethods(ReflectionUtils.java:1717)
[ERROR] at org.junit.platform.commons.util.ReflectionUtils.findMethods(ReflectionUtils.java:1702)
[ERROR] at org.junit.platform.commons.util.AnnotationUtils.findAnnotatedMethods(AnnotationUtils.java:499)
[ERROR] at org.junit.platform.commons.support.AnnotationSupport.findAnnotatedMethods(AnnotationSupport.java:581)
[ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findMethodsAndCheckVoidReturnType(LifecycleMethodUtils.java:134)
[ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findMethodsAndCheckStatic(LifecycleMethodUtils.java:118)
[ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findBeforeAllMethods(LifecycleMethodUtils.java:53)

@martinaldrin
Copy link
Author

I have updated my PR, but I will need to double check the syntax of some of the test that I have added.
So the PR is not yet ready

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 5, 2025

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. I try everything by regenerate classes, rebuild and some time it is working and sometimes not. Do I do something wrong during build of the project?

[ERROR] There was an error in the forked process [ERROR] TestEngine with ID 'junit-jupiter' encountered a critical issue during test discovery: [ERROR] [ERROR] (1) [ERROR] ClassSelector [className = 'com.github.javaparser.remove.NodeRemovalTest', classLoader = null] resolution failed [ERROR] Source: ClassSource [className = 'com.github.javaparser.remove.NodeRemovalTest', filePosition = null] [ERROR] at com.github.javaparser.remove.NodeRemovalTest.(SourceFile:0) [ERROR] Cause: java.lang.NoClassDefFoundError: Node [ERROR] at java.lang.Class.getDeclaredMethods0(Native Method) [ERROR] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) [ERROR] at java.lang.Class.getDeclaredMethods(Class.java:1975) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:1792) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.findAllMethodsInHierarchy(ReflectionUtils.java:1732) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.getSuperclassMethods(ReflectionUtils.java:1945) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.findAllMethodsInHierarchy(ReflectionUtils.java:1735) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.streamMethods(ReflectionUtils.java:1717) [ERROR] at org.junit.platform.commons.util.ReflectionUtils.findMethods(ReflectionUtils.java:1702) [ERROR] at org.junit.platform.commons.util.AnnotationUtils.findAnnotatedMethods(AnnotationUtils.java:499) [ERROR] at org.junit.platform.commons.support.AnnotationSupport.findAnnotatedMethods(AnnotationSupport.java:581) [ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findMethodsAndCheckVoidReturnType(LifecycleMethodUtils.java:134) [ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findMethodsAndCheckStatic(LifecycleMethodUtils.java:118) [ERROR] at org.junit.jupiter.engine.descriptor.LifecycleMethodUtils.findBeforeAllMethods(LifecycleMethodUtils.java:53)

mvn clean install is all you need to build the project.

}

@Test
void validSwitchPatternWithUnnamedPattern() {
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

}

@Test
void invalidUnnamedVariableReferenceInSwitchPattern() {
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

}

@Test
void validSwitchWithRecordPatternAndUnnamedFields() {
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}

@Test
void validSwitchWithNestedRecordPatternAndUnnamedFields() {
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

}

@Test
void validSwitchWithComplexGuardAndUnnamedPatterns() {
Copy link
Collaborator

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.

Copy link
Author

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() {
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 5, 2025

Globally, there are still far too many unnecessary or poorly named unit tests.

@martinaldrin
Copy link
Author

There are a few more complicated switch pattern that will be unsupported by this commit.
Tests are added but disabled, I don't know how to add support for them, as I understand it requires some updates of java.jj

@jlerbsc
Copy link
Collaborator

jlerbsc commented Jun 9, 2025

Please squash your commits.

@martinaldrin
Copy link
Author

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());
}

Copy link
Collaborator

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 @@
/*
Copy link
Collaborator

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.

Copy link
Author

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.")
Copy link
Collaborator

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?

Copy link
Author

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) {
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

@johannescoetzee
Copy link
Contributor

There are a few core things missing from this PR that are required for record patterns. Most likely, for a case like o instanceof Foo(_, _) a new UnnamedPatternExpr node (could be called something else) will have to be added to represent the _ occurrences. Support for this node type would then have to be added to the grammar, symbol solver, and printers. This is similar to what I had to do when adding record pattern support initially, so I'd be happy to add support for this as well

@jlerbsc
Copy link
Collaborator

jlerbsc commented Aug 13, 2025

There are a few core things missing from this PR that are required for record patterns. Most likely, for a case like o instanceof Foo(_, _) a new UnnamedPatternExpr node (could be called something else) will have to be added to represent the _ occurrences. Support for this node type would then have to be added to the grammar, symbol solver, and printers. This is similar to what I had to do when adding record pattern support initially, so I'd be happy to add support for this as well

@johannescoetzee Can you try this proposal again from the beginning by ensuring that UnamedPatternExpr is required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anonymous Variables and Patterns
3 participants