Bug 565447 - [15] ASTConverter showing pattern variable for
InstanceOfExpression as final non-sealed
Change-Id: Ib72d64948d137154677c5bb6c16d0305f604ab6d
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
index 99fab78..c374727 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter_15Test.java
@@ -760,7 +760,7 @@
assertEquals("wrong line number", 9, compilationUnit.getLineNumber(node.getStartPosition()));
}
- public void _testPatternInstanceOfExpression001() throws JavaModelException {
+ public void testPatternInstanceOfExpression001() throws JavaModelException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
@@ -795,14 +795,14 @@
checkSourceRange(expression, "o instanceof String s", contents);
assertEquals("Not an instanceof expression", ASTNode.INSTANCEOF_EXPRESSION, expression.getNodeType());
InstanceofExpression instanceofExpression = (InstanceofExpression) expression;
- SingleVariableDeclaration var = instanceofExpression.getPatternVariable();
- checkSourceRange(var, "String s", contents);
+ SimpleName var = instanceofExpression.getPatternVariable();
+ checkSourceRange(var, "s", contents);
}finally {
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
}
}
- public void _testPatternInstanceOfExpression002() throws JavaModelException {
+ public void testPatternInstanceOfExpression002() throws JavaModelException {
if (!isJRE15) {
System.err.println("Test "+getName()+" requires a JRE 15");
return;
@@ -838,7 +838,7 @@
checkSourceRange(expression, "o instanceof String", contents);
assertEquals("Not an instanceof expression", ASTNode.INSTANCEOF_EXPRESSION, expression.getNodeType());
InstanceofExpression instanceofExpression = (InstanceofExpression) expression;
- SingleVariableDeclaration var = instanceofExpression.getPatternVariable();
+ SimpleName var = instanceofExpression.getPatternVariable();
assertNull(var);
}finally {
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, old);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
index ce33099..d9ed1b5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingInstanceOfPatternExpressionTest.java
@@ -26,7 +26,6 @@
import org.eclipse.jdt.core.dom.InstanceofExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleType;
-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
@@ -90,10 +89,7 @@
instanceOfExpression.setLeftOperand(ast.newSimpleName("o"));//$NON-NLS-1$
SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("String"));//$NON-NLS-1$
instanceOfExpression.setRightOperand(simpleType);
- SingleVariableDeclaration patternVariable = ast.newSingleVariableDeclaration();
- patternVariable.setName(ast.newSimpleName("s"));
- patternVariable.setType(ast.newSimpleType(ast.newSimpleName("String")));//$NON-NLS-1$
- instanceOfExpression.setPatternVariable(patternVariable);
+ instanceOfExpression.setPatternVariable(ast.newSimpleName("s"));
ifStatement.setExpression(instanceOfExpression);
ifStatement.setThenStatement(ast.newEmptyStatement());
rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY).insertLast(ifStatement, null);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index 430be8a..76adab1 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -2225,7 +2225,8 @@
int startPosition = leftExpression.getStartPosition();
int sourceEnd = convertType.getStartPosition() + convertType.getLength() - 1;
if (DOMASTUtil.isInstanceofExpressionPatternSupported(this.ast) && expression.elementVariable != null) {
- instanceOfExpression.setPatternVariable(convertToSingleVariableDeclaration(expression.elementVariable));
+ SingleVariableDeclaration patternVariable = convertToSingleVariableDeclaration(expression.elementVariable);
+ instanceOfExpression.setPatternVariable(((SimpleName)patternVariable.getName().clone(this.ast)));
sourceEnd= expression.elementVariable.sourceEnd;
}
instanceOfExpression.setSourceRange(startPosition, sourceEnd - startPosition + 1);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/InstanceofExpression.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/InstanceofExpression.java
index 12ea6c7..9bd4ef8 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/InstanceofExpression.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/InstanceofExpression.java
@@ -47,12 +47,13 @@
new ChildPropertyDescriptor(InstanceofExpression.class, "rightOperand", Type.class, MANDATORY, CYCLE_RISK); //$NON-NLS-1$
/**
- * The "patternVariable" structural property of this node type (child type: {@link SingleVariableDeclaration}) (added in JLS14 API).
+ * The "patternVariable" structural property of this node type (child type: {@link SimpleName}) (added in JLS14 API).
+ * This contains the name of the instance variable.
* @noreference This property is not intended to be referenced by clients as it is a part of Java preview feature.
* @since 3.22
*/
public static final ChildPropertyDescriptor PATTERN_VARIABLE_PROPERTY =
- new ChildPropertyDescriptor(InstanceofExpression.class, "patternVariable", SingleVariableDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
+ new ChildPropertyDescriptor(InstanceofExpression.class, "patternVariable", SimpleName.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
@@ -129,7 +130,7 @@
/**
* The patternVariable declaration.
*/
- private SingleVariableDeclaration patternVariable = null;
+ private SimpleName patternVariable = null;
/**
* Creates a new AST node for an instanceof expression owned by the given
@@ -174,7 +175,7 @@
if (get) {
return getPatternVariable();
} else {
- setPatternVariable((SingleVariableDeclaration) child);
+ setPatternVariable((SimpleName) child);
return null;
}
}
@@ -194,9 +195,9 @@
result.setLeftOperand((Expression) getLeftOperand().clone(target));
result.setRightOperand((Type) getRightOperand().clone(target));
if (DOMASTUtil.isInstanceofExpressionPatternSupported(target)) {
- SingleVariableDeclaration pv = getPatternVariable();
+ SimpleName pv = getPatternVariable();
if (pv != null) {
- result.setPatternVariable((SingleVariableDeclaration) pv.clone(target));
+ result.setPatternVariable((SimpleName) pv.clone(target));
}
}
return result;
@@ -311,7 +312,7 @@
* @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature.
* @nooverride This method is not intended to be re-implemented or extended by clients as it is a part of Java preview feature.
*/
- public SingleVariableDeclaration getPatternVariable() {
+ public SimpleName getPatternVariable() {
supportedOnlyIn15();
unsupportedWithoutPreviewError();
return this.patternVariable;
@@ -327,7 +328,7 @@
* @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature.
* @nooverride This method is not intended to be re-implemented or extended by clients as it is a part of Java preview feature.
*/
- public void setPatternVariable(SingleVariableDeclaration referencePatternVariable) {
+ public void setPatternVariable(SimpleName referencePatternVariable) {
supportedOnlyIn15();
unsupportedWithoutPreviewError();
if (referencePatternVariable == null) {