diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java index 3c4e8c7893b..b0302e67a2e 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java @@ -52,6 +52,8 @@ public static Test suite() { suite.addTest(new ASTMatcherTest(methods[i].getName(), JLS3_INTERNAL)); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391898 suite.addTest(new ASTMatcherTest(methods[i].getName(), getJLS8())); + suite.addTest(new ASTMatcherTest(methods[i].getName(), AST.JLS17)); + suite.addTest(new ASTMatcherTest(methods[i].getName(), AST.JLS21)); } } return suite; @@ -273,7 +275,16 @@ public String getName() { case JLS3_INTERNAL: name = "JLS3 - " + name; break; - } + case AST.JLS8: + name = "JLS8 - " + name; + break; + case AST.JLS17: + name = "JLS17 - " + name; + break; + case AST.JLS21: + name = "JLS21 - " + name; + break; + } return name; } @@ -586,6 +597,12 @@ public boolean match(TypeMethodReference node, Object other) { public boolean match(IntersectionType node, Object other) { return standardBody(node, other, this.superMatch ? super.match(node, other) : false); } + public boolean match(TypePattern node, Object other) { + return standardBody(node, other, this.superMatch ? super.match(node, other) : false); + } + public boolean match(PatternInstanceofExpression node, Object other) { + return standardBody(node, other, this.superMatch ? super.match(node, other) : false); + } } /** @@ -1137,6 +1154,25 @@ public void testParenthesizedExpression() { ParenthesizedExpression x1 = this.ast.newParenthesizedExpression(); basicMatch(x1); } + public void testPatternInstanceofExpression() { + if (this.ast.apiLevel() < AST.JLS17) { + return; + } + PatternInstanceofExpression x1 = this.ast.newPatternInstanceofExpression(); + x1.setLeftOperand(this.N1); + SingleVariableDeclaration svd = this.ast.newSingleVariableDeclaration(); + svd.setType(this.T1); + svd.setName(this.N2); + + if (this.ast.apiLevel() <= AST.JLS20) { + x1.setRightOperand(svd); + } else { + TypePattern tp = this.ast.newTypePattern(); + tp.setPatternVariable(svd); + x1.setPattern(tp); + } + basicMatch(x1); + } public void testPostfixExpression() { PostfixExpression x1 = this.ast.newPostfixExpression(); x1.setOperand(this.E1); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java index f98b17668d3..109127c4d42 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTMatcher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1976,15 +1976,19 @@ public boolean match(ParenthesizedExpression node, Object other) { * different node type or is null * @since 3.26 */ - @SuppressWarnings("deprecation") public boolean match(PatternInstanceofExpression node, Object other) { if (!(other instanceof PatternInstanceofExpression)) { return false; } PatternInstanceofExpression o = (PatternInstanceofExpression) other; - return - safeSubtreeMatch(node.getLeftOperand(), o.getLeftOperand()) - && safeSubtreeMatch(node.getRightOperand(), o.getRightOperand()); + AST ast= node.getAST(); + if (ast.apiLevel() <= 20) { + return + safeSubtreeMatch(node.getLeftOperand(), o.getLeftOperand()) + && safeSubtreeMatch(node.getRightOperand(), o.getRightOperand()); + } + return safeSubtreeMatch(node.getLeftOperand(), o.getLeftOperand()) + && safeSubtreeMatch(node.getPattern(), o.getPattern()); } /**