Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2019-07-04 02:09:33 -0400
committerSarika Sinha2019-07-05 03:58:24 -0400
commit357185ef691b346646bc98aa38ba4950222dbc6a (patch)
treeae300420b208c84a4f38d77185c6541395c6d07f
parenta73c2353d7810c3b248c523da998d659181ac7d8 (diff)
downloadeclipse.jdt.core-357185ef691b346646bc98aa38ba4950222dbc6a.tar.gz
eclipse.jdt.core-357185ef691b346646bc98aa38ba4950222dbc6a.tar.xz
eclipse.jdt.core-357185ef691b346646bc98aa38ba4950222dbc6a.zip
Bug 548956 - Rewrite should work based on previewEnabled flag of AST
Change-Id: Ida5b2721cf35b20b286e6198d3a0d03c0426711b Signed-off-by: Sarika Sinha <sarika.sinha@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java9
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingSwitchExpressionsTest.java10
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java8
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java6
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java8
5 files changed, 30 insertions, 11 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
index bd6a6e6a0f..acfcedc4cc 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
@@ -104,6 +104,15 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest {
return createSuite(ASTRewritingStatementsTest.class);
}
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (this.apiLevel >= AST.JLS12 ) {
+ this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ this.project1.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ }
+ }
+
/** @deprecated using deprecated code */
private void internalSetExtraDimensions(VariableDeclarationFragment node, int dimensions) {
if (this.apiLevel < AST.JLS8) {
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 f10badf274..e604f7453e 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
@@ -17,6 +17,7 @@ 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;
@@ -53,6 +54,15 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest {
return createSuite(ASTRewritingSwitchExpressionsTest.class);
}
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (this.apiLevel >= AST.JLS12 ) {
+ this.project1.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ this.project1.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
+ }
+ }
+
@SuppressWarnings("rawtypes")
public void testSwitchExpressions_since_12() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
index 028519f632..998c0675a5 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
@@ -460,18 +460,18 @@ public class NaiveASTFlattener extends ASTVisitor {
@Override
public boolean visit(BreakStatement node) {
- if (node.getAST().apiLevel() >= JLS12 && node.isImplicit() && node.getExpression() == null) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled() && node.isImplicit() && node.getExpression() == null) {
return false;
}
printIndent();
- if (node.getAST().apiLevel() < JLS12 || (node.getAST().apiLevel() >= JLS12 && !node.isImplicit())) {
+ if (node.getAST().apiLevel() < JLS12 || (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled() && !node.isImplicit())) {
this.buffer.append("break"); //$NON-NLS-1$
}
if (node.getLabel() != null) {
this.buffer.append(" ");//$NON-NLS-1$
node.getLabel().accept(this);
}
- if (node.getAST().apiLevel() >= JLS12) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled()) {
if (node.getExpression() != null) {
this.buffer.append(" ");//$NON-NLS-1$
node.getExpression().accept(this);
@@ -1506,7 +1506,7 @@ public class NaiveASTFlattener extends ASTVisitor {
@Override
public boolean visit(SwitchCase node) {
- if (node.getAST().apiLevel() >= JLS12) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled()) {
if (node.isDefault()) {
this.buffer.append("default");//$NON-NLS-1$
this.buffer.append(node.isSwitchLabeledRule() ? " ->" : ":");//$NON-NLS-1$ //$NON-NLS-2$
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index 9dd5439f1d..424f7d8285 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -2576,7 +2576,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
try {
int offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNamebreak, node.getStartPosition());
rewriteNode(node, BreakStatement.LABEL_PROPERTY, offset, ASTRewriteFormatter.SPACE); // space between break and label
- if (node.getAST().apiLevel() >= JLS12_INTERNAL) {
+ if (node.getAST().apiLevel() >= JLS12_INTERNAL && node.getAST().isPreviewEnabled()) {
rewriteNode(node, BreakStatement.EXPRESSION_PROPERTY, offset, ASTRewriteFormatter.SPACE); // space between break and label
}
} catch (CoreException e) {
@@ -3519,7 +3519,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
}
// dont allow switching from case to default or back. New statements should be created.
- if (node.getAST().apiLevel() >= JLS12_INTERNAL) {
+ if (node.getAST().apiLevel() >= JLS12_INTERNAL && node.getAST().isPreviewEnabled()) {
int pos = node.expressions().size() == 0 ? node.getStartPosition() :
rewriteNodeList(node, SwitchCase.EXPRESSIONS2_PROPERTY, node.getStartPosition(), Util.EMPTY_STRING, ", "); //$NON-NLS-1$
if (isChanged(node, SwitchCase.SWITCH_LABELED_RULE_PROPERTY)) {
@@ -3743,7 +3743,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor {
insertIndent++;
}
ParagraphListRewriter listRewriter;
- if (node.getAST().apiLevel() >= JLS12_INTERNAL) {
+ if (node.getAST().apiLevel() >= JLS12_INTERNAL && node.getAST().isPreviewEnabled()) {
listRewriter= new SwitchListLabeledRuleRewriter(insertIndent);
} else {
listRewriter= new SwitchListRewriter(insertIndent);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
index e8590da9a2..952fceec4a 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
@@ -362,11 +362,11 @@ public class ASTRewriteFlattener extends ASTVisitor {
@Override
public boolean visit(BreakStatement node) {
- if (node.getAST().apiLevel() >= JLS12 && node.isImplicit() && node.getExpression() == null) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled() && node.isImplicit() && node.getExpression() == null) {
return false;
}
- if (node.getAST().apiLevel() < JLS12 || (node.getAST().apiLevel() >= JLS12 && !node.isImplicit())) {
+ if (node.getAST().apiLevel() < JLS12 || (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled() && !node.isImplicit())) {
this.result.append("break"); //$NON-NLS-1$
}
ASTNode label= getChildNode(node, BreakStatement.LABEL_PROPERTY);
@@ -374,7 +374,7 @@ public class ASTRewriteFlattener extends ASTVisitor {
this.result.append(' ');
label.accept(this);
}
- if (node.getAST().apiLevel() >= JLS12) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled()) {
ASTNode expression = getChildNode(node, BreakStatement.EXPRESSION_PROPERTY);
if (expression != null ) {
this.result.append(' ');
@@ -983,7 +983,7 @@ public class ASTRewriteFlattener extends ASTVisitor {
@Override
public boolean visit(SwitchCase node) {
- if (node.getAST().apiLevel() >= JLS12) {
+ if (node.getAST().apiLevel() >= JLS12 && node.getAST().isPreviewEnabled()) {
if (node.isDefault()) {
this.result.append("default");//$NON-NLS-1$
this.result.append(getBooleanAttribute(node, SwitchCase.SWITCH_LABELED_RULE_PROPERTY) ? " ->" : ":");//$NON-NLS-1$ //$NON-NLS-2$

Back to the top