From 5bfbcd5919fdc19f9c330b8813df15bf1fdadd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 14 Aug 2024 10:17:10 +0300 Subject: [PATCH] Fix ASTConverter_RecordPattern_Test.testCaseDefaultExpressionPattern --- .../eclipse/jdt/core/dom/JavacConverter.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 6e223397524..334586fbf31 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -97,6 +97,8 @@ import com.sun.tools.javac.tree.JCTree.JCParens; import com.sun.tools.javac.tree.JCTree.JCPattern; import com.sun.tools.javac.tree.JCTree.JCPatternCaseLabel; +import com.sun.tools.javac.tree.JCTree.JCConstantCaseLabel; +import com.sun.tools.javac.tree.JCTree.JCDefaultCaseLabel; import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; import com.sun.tools.javac.tree.JCTree.JCProvides; import com.sun.tools.javac.tree.JCTree.JCRecordPattern; @@ -2427,6 +2429,25 @@ private Statement convertSwitchCase(JCCase jcCase) { } else { // Override length to just be `case blah:` + for (JCCaseLabel jcLabel : jcCase.getLabels()) { + switch (jcLabel) { + case JCConstantCaseLabel constantLabel: { + if (constantLabel.expr.toString().equals("null")) { + res.expressions().add(this.ast.newNullLiteral()); + } + break; + } + case JCDefaultCaseLabel defaultCase: { + if (jcCase.getLabels().size() != 1) { + res.expressions().add(this.ast.newCaseDefaultExpression()); + } + break; + } + default: { + break; + } + } + } int start1 = res.getStartPosition(); int colon = this.rawText.indexOf(":", start1); if( colon != -1 ) {