Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2021-03-01 13:17:03 +0000
committerSarika Sinha2021-03-02 04:50:28 +0000
commitdb365100ebf21e1b83389994ac4895d4524e3d88 (patch)
tree1d3160b87bce0a31639dc1f998500ae8ce464ab6
parentbbcaa456f1a25ca66e2d163e1b9ea11fde10e0e2 (diff)
downloadeclipse.jdt.core-db365100ebf21e1b83389994ac4895d4524e3d88.tar.gz
eclipse.jdt.core-db365100ebf21e1b83389994ac4895d4524e3d88.tar.xz
eclipse.jdt.core-db365100ebf21e1b83389994ac4895d4524e3d88.zip
Bug 571586 - [16] AST Rewrite support
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java19
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java64
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java36
3 files changed, 89 insertions, 30 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
index 073668141b..72121d2f02 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingRecordDeclarationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2020 IBM Corporation and others.
+* Copyright (c) 2020, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,6 +7,9 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+* This is an implementation of an early-draft specification developed under the Java
+* Community Process (JCP) and is made available for testing and evaluation purposes
+* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -17,7 +20,6 @@ import java.util.List;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
@@ -49,7 +51,7 @@ import junit.framework.Test;
public class ASTRewritingRecordDeclarationTest extends ASTRewritingTest {
public ASTRewritingRecordDeclarationTest(String name) {
- super(name, 15);
+ super(name, 16);
}
public ASTRewritingRecordDeclarationTest(String name, int apiLevel) {
@@ -63,18 +65,13 @@ public class ASTRewritingRecordDeclarationTest extends ASTRewritingTest {
@Override
protected void setUp() throws Exception {
super.setUp();
- if (this.apiLevel == AST.JLS15 ) {
- this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_16);
- this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16);
- this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16);
- this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
- }
+ setUpProjectAbove16();
}
@SuppressWarnings("deprecation")
private boolean checkAPILevel() {
- if (this.apiLevel != 16) {
- System.err.println("Test "+getName()+" requires a JRE 15");
+ if (this.apiLevel < 16) {
+ System.err.println("Test "+getName()+" requires a JRE 16");
return true;
}
return false;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
index cf76e8e886..e370704eaa 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019, 2020 IBM Corporation and others.
+ * Copyright (c) 2019, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,6 +7,9 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -17,7 +20,6 @@ import java.util.List;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Block;
@@ -56,23 +58,27 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
return createSuite(ASTRewritingSwitchExpressionsTest.class);
}
- @SuppressWarnings("deprecation")
@Override
protected void setUp() throws Exception {
super.setUp();
- if (this.apiLevel == AST_INTERNAL_JLS15 ) {
- this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_15);
- this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_15);
- this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_15);
- } else if (this.apiLevel == AST_INTERNAL_JLS14 ) {
- this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
- this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
- this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
+ super.setUpProjectAbove14();
+
+ }
+
+ @SuppressWarnings("deprecation")
+ private boolean checkAPILevel() {
+ if (this.apiLevel < 14) {
+ System.err.println("Test "+getName()+" requires a JRE 14");
+ return true;
}
+ return false;
}
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -176,6 +182,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
}
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_02_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -235,9 +244,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_03_since_12() throws Exception {
- /*
- * if (this.apiLevel == AST_INTERNAL_JLS15) { return; }
- */
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -326,6 +335,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
@SuppressWarnings("rawtypes")
public void testSwitchStatement_Bug543720_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -407,9 +419,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
}
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_04_since_12() throws Exception {
- /*
- * if (this.apiLevel == AST_INTERNAL_JLS15) { return; }
- */
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s = "package test1;\n"+
"public class X {\n"+
@@ -483,6 +495,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
// replacing colon by ->
@SuppressWarnings("rawtypes")
public void testSwitchStatement_Bug543720_05_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -561,6 +576,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
// replacing colon by ->
@SuppressWarnings("rawtypes")
public void testSwitchStatement_Bug543720_06_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -638,6 +656,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
// replacing colon by ->
@SuppressWarnings("rawtypes")
public void testSwitchExpression_Bug543720_07_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -717,6 +738,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
// replacing colon by ->
@SuppressWarnings("rawtypes")
public void testSwitchExpression_Bug543720_08_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
String s =
"package test1;\n"+
@@ -794,6 +818,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
}
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_05_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuilder builder= new StringBuilder();
builder.append("package test1;\n");
@@ -863,6 +890,9 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_Bug567975_since_12() throws Exception {
+ if (checkAPILevel()) {
+ return;
+ }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=567975
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuilder builder= new StringBuilder();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
index f5ab1abd1b..c1bfa01375 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,6 +7,9 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
@@ -87,9 +90,12 @@ public class ASTRewritingTest extends AbstractJavaModelTests {
/** @deprecated using deprecated code */
private final static int JLS14_INTERNAL = AST.JLS14;
+ /** @deprecated using deprecated code */
private final static int JLS15_INTERNAL = AST.JLS15;
- private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS14_INTERNAL, JLS15_INTERNAL};
+ private final static int JLS16_INTERNAL = AST.JLS16;
+
+ private final static int[] JLS_LEVELS = { JLS2_INTERNAL, JLS3_INTERNAL, JLS4_INTERNAL, JLS8_INTERNAL, JLS9_INTERNAL, JLS10_INTERNAL, JLS14_INTERNAL, JLS15_INTERNAL, JLS16_INTERNAL};
private static final String ONLY_AST_STRING = "_only";
private static final String SINCE_AST_STRING = "_since";
@@ -222,6 +228,32 @@ public class ASTRewritingTest extends AbstractJavaModelTests {
this.sourceFolder = getPackageFragmentRoot("P", "src");
}
+ protected void setUpProjectAbove14() throws Exception {
+ if (this.apiLevel == AST_INTERNAL_JLS14 ) {
+ this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14);
+ this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14);
+ this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14);
+ }
+ setUpProjectAbove15();
+ }
+
+ protected void setUpProjectAbove15() throws Exception {
+ if (this.apiLevel == AST_INTERNAL_JLS15 ) {
+ this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_15);
+ this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_15);
+ this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_15);
+ }
+ setUpProjectAbove16();
+ }
+
+ protected void setUpProjectAbove16() throws Exception {
+ if (this.apiLevel == AST_INTERNAL_JLS16 ) {
+ this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_16);
+ this.project1.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_16);
+ this.project1.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_16);
+ }
+ }
+
protected IJavaProject createProject(String projectName, String complianceVersion) throws CoreException {
IJavaProject proj = createJavaProject(projectName, new String[] {"src"}, "bin");
proj.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);

Back to the top