Skip to content

Commit

Permalink
Handles the TypePattern DOM API modifications in the JDT.UI
Browse files Browse the repository at this point in the history
Fixes #1994
  • Loading branch information
noopur2507 committed Feb 10, 2025
1 parent bb20580 commit cb33fee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2024 Fabrice TIERCELIN and others.
* Copyright (c) 2021, 2025 Fabrice TIERCELIN and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -33,8 +33,8 @@
import org.eclipse.jdt.core.dom.InfixExpression;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.PatternInstanceofExpression;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypePattern;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer;

Expand Down Expand Up @@ -106,8 +106,8 @@ private class PatternNameVisitor extends ASTVisitor {
public boolean visit(PatternInstanceofExpression node) {
Pattern p= node.getPattern();
if (p instanceof TypePattern typePattern) {
SingleVariableDeclaration patternVariable= typePattern.getPatternVariable();
patternNames.add(patternVariable.getName().getFullyQualifiedName());
VariableDeclaration patternVariable= node.getAST().apiLevel() < AST.JLS22 ? typePattern.getPatternVariable() : typePattern.getPatternVariable2();
patternNames.add(patternVariable.getName().getFullyQualifiedName());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2024 Fabrice TIERCELIN and others.
* Copyright (c) 2021, 2025 Fabrice TIERCELIN and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -39,6 +39,7 @@
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.TypePattern;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
Expand Down Expand Up @@ -220,7 +221,7 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
}
if ((ast.apiLevel() == AST.JLS20 && ast.isPreviewEnabled()) || ast.apiLevel() > AST.JLS20) {
TypePattern newTypePattern= ast.newTypePattern();
newTypePattern.setPatternVariable(newSVDecl);
newTypePattern.setPatternVariable((VariableDeclaration) newSVDecl);
newInstanceof.setPattern(newTypePattern);
} else {
newInstanceof.setRightOperand(newSVDecl);

Check warning on line 227 in org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PatternMatchingForInstanceofFixCore.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The method setRightOperand(SingleVariableDeclaration) from the type PatternInstanceofExpression is deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.PatternInstanceofExpression;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypePattern;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

Expand Down Expand Up @@ -96,17 +96,17 @@ public boolean visit(VariableDeclarationStatement node) {

@Override
public boolean visit(PatternInstanceofExpression node) {
SingleVariableDeclaration svd= node.getRightOperand();
VariableDeclaration vd= node.getRightOperand();

Check warning on line 99 in org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchAnalyzer.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The method getRightOperand() from the type PatternInstanceofExpression is deprecated
AST ast= node.getAST();
if (ast.apiLevel() == AST.JLS20 && ast.isPreviewEnabled() || ast.apiLevel() > AST.JLS20) {
Pattern p= node.getPattern();
if (p instanceof TypePattern typePattern) {
svd= typePattern.getPatternVariable();
vd= ast.apiLevel() < AST.JLS22 ? typePattern.getPatternVariable() : typePattern.getPatternVariable2();
} else {
return false;
}
}
SimpleName name= svd.getName();
SimpleName name= vd.getName();
IBinding binding= name.resolveBinding();
if (binding instanceof IVariableBinding) {
variableBindings.put(name, (IVariableBinding) binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import org.eclipse.jdt.core.dom.InfixExpression;
import org.eclipse.jdt.core.dom.Pattern;
import org.eclipse.jdt.core.dom.PatternInstanceofExpression;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.TypePattern;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;

import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
Expand Down Expand Up @@ -161,7 +161,7 @@ private class PatternNameVisitor extends ASTVisitor {
public boolean visit(PatternInstanceofExpression node) {
Pattern p= node.getPattern();
if (p instanceof TypePattern typePattern) {
SingleVariableDeclaration patternVariable= typePattern.getPatternVariable();
final VariableDeclaration patternVariable= node.getAST().apiLevel() < AST.JLS22 ? typePattern.getPatternVariable() : typePattern.getPatternVariable2();
patternNames.add(patternVariable.getName().getFullyQualifiedName());
}
return true;
Expand Down

0 comments on commit cb33fee

Please sign in to comment.