diff options
author | Sarika Sinha | 2019-07-25 15:03:55 +0000 |
---|---|---|
committer | Sarika Sinha | 2019-08-06 16:44:30 +0000 |
commit | 008ef1f94c166e1cb14f1cb24614e365aac0586e (patch) | |
tree | 3d1f5d4f734cbdcd6ffad61acfa7d8660a5f8dae | |
parent | 5977f37338666f32ba45692fa8cd2eafbcd1382f (diff) | |
download | eclipse.jdt.core-008ef1f94c166e1cb14f1cb24614e365aac0586e.tar.gz eclipse.jdt.core-008ef1f94c166e1cb14f1cb24614e365aac0586e.tar.xz eclipse.jdt.core-008ef1f94c166e1cb14f1cb24614e365aac0586e.zip |
Bug 549106 - [dom] Impact of preview enabled flag on DOM AST
Change-Id: If7e6642f3e771cb7182f2e7544f0ae3434f85e21
11 files changed, 151 insertions, 36 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 83eac08688..ae8f5e505d 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 @@ -107,7 +107,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { @Override protected void setUp() throws Exception { super.setUp(); - if (this.apiLevel >= AST.JLS12 ) { + 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); } @@ -3650,7 +3650,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { // change case statement SwitchCase caseStatement= (SwitchCase) statements.get(3); Expression newCaseExpression= ast.newNumberLiteral("10"); - if (this.apiLevel < AST.JLS12) { + if (this.apiLevel != AST.JLS12) { rewrite.replace(caseStatement.getExpression(), newCaseExpression, null); } else { List expressions = caseStatement.expressions(); 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 a6109a67eb..48e9181580 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 @@ -57,7 +57,7 @@ public class ASTRewritingSwitchExpressionsTest extends ASTRewritingTest { @Override protected void setUp() throws Exception { super.setUp(); - if (this.apiLevel >= AST.JLS12 ) { + 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); this.project1.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_12); 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 3d431e15cf..2c38bc8db8 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 @@ -1287,7 +1287,7 @@ class ASTConverter { public BreakStatement convert(org.eclipse.jdt.internal.compiler.ast.BreakStatement statement) { BreakStatement breakStatement = new BreakStatement(this.ast); - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (this.ast.apiLevel == AST.JLS12_INTERNAL && this.ast.isPreviewEnabled()) { breakStatement.setImplicit(statement.isImplicit); if (statement.isImplicit) { breakStatement.setSourceRange(statement.sourceEnd -1, 0); @@ -1304,7 +1304,7 @@ class ASTConverter { retrieveIdentifierAndSetPositions(statement.sourceStart, statement.sourceEnd, name); breakStatement.setLabel(name); } - else if (statement.expression != null && this.ast.apiLevel >= AST.JLS12_INTERNAL) { + else if (statement.expression != null && this.ast.apiLevel == AST.JLS12_INTERNAL && this.ast.isPreviewEnabled()) { final Expression expression= convert(statement.expression); breakStatement.setExpression(expression); int sourceEnd = statement.sourceEnd; @@ -1319,7 +1319,7 @@ class ASTConverter { public SwitchCase convert(org.eclipse.jdt.internal.compiler.ast.CaseStatement statement) { SwitchCase switchCase = new SwitchCase(this.ast); - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (this.ast.apiLevel == AST.JLS12_INTERNAL && this.ast.isPreviewEnabled()) { org.eclipse.jdt.internal.compiler.ast.Expression[] expressions = statement.constantExpressions; if (expressions == null || expressions.length == 0) { switchCase.expressions().clear(); @@ -1336,7 +1336,7 @@ class ASTConverter { internalSetExpression(switchCase, convert(constantExpression)); } } - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (this.ast.apiLevel == AST.JLS12_INTERNAL && this.ast.isPreviewEnabled()) { switchCase.setSwitchLabeledRule(statement.isExpr); } switchCase.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1); @@ -2880,7 +2880,7 @@ class ASTConverter { } public Expression convert(org.eclipse.jdt.internal.compiler.ast.SwitchExpression expression) { - if (this.ast.apiLevel < AST.JLS12_INTERNAL) { + if (this.ast.apiLevel < AST.JLS12_INTERNAL || !this.ast.isPreviewEnabled()) { return createFakeNullLiteral(expression); } SwitchExpression switchExpression = new SwitchExpression(this.ast); 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 e50af76c07..2bfe6beac5 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 @@ -484,7 +484,7 @@ public class ASTMatcher { return false; } BreakStatement o = (BreakStatement) other; - return ( node.getAST().apiLevel >= AST.JLS12_INTERNAL && node.getExpression() != null + return ( node.getAST().apiLevel == AST.JLS12_INTERNAL && node.getAST().isPreviewEnabled() && node.getExpression() != null ? safeSubtreeMatch(node.getExpression(), o.getExpression()) && node.isImplicit() == o.isImplicit() : safeSubtreeMatch(node.getLabel(), o.getLabel())); } @@ -2269,7 +2269,7 @@ public class ASTMatcher { return false; } SwitchCase o = (SwitchCase) other; - return ( node.getAST().apiLevel >= AST.JLS12_INTERNAL + return ( node.getAST().apiLevel == AST.JLS12_INTERNAL && node.getAST().isPreviewEnabled() ? safeSubtreeListMatch(node.expressions(), o.expressions()) : compareDeprecatedSwitchExpression(node, o)); } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java index 40dbea9573..f9193e2ddc 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java @@ -1920,7 +1920,7 @@ public abstract class ASTNode { * @since 3.0 */ public final List structuralPropertiesForType() { - return internalStructuralPropertiesForType(this.ast.apiLevel); + return internalStructuralPropertiesForType(this.ast.apiLevel, this.ast.isPreviewEnabled()); } /** @@ -1940,6 +1940,27 @@ public abstract class ASTNode { */ abstract List internalStructuralPropertiesForType(int apiLevel); + + /** + * Returns a list of property descriptors for this node type. + * Clients must not modify the result. This abstract method + * must be implemented in each concrete AST node type. + * <p> + * N.B. This method is package-private, so that the implementations + * of this method in each of the concrete AST node types do not + * clutter up the API doc. + * </p> + * + * @param apiLevel the API level; one of the <code>AST.JLS*</code> constants + * @param previewEnabled the previewEnabled flag + * @return a list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}) + * @since 3.19 + */ + List internalStructuralPropertiesForType(int apiLevel, boolean previewEnabled) { + return internalStructuralPropertiesForType(apiLevel); + } + /** * Internal helper method that starts the building a list of * property descriptors for the given node type. @@ -2094,6 +2115,23 @@ public abstract class ASTNode { throw new UnsupportedOperationException("Operation only supported in ASTs with level JLS12 and above"); //$NON-NLS-1$ } } + + /** + * Checks that this AST operation is not used when + * building ASTs without previewEnabled flag. + * <p> + * Use this method to prevent access to new properties that have been added with preview feature + * </p> + * + * @exception UnsupportedOperationException if this operation is used with previewEnabled flag as false + * @since 3.19 + */ + final void unsupportedWithoutPreviewError() { + if (!this.ast.isPreviewEnabled()) { + throw new UnsupportedOperationException("Operation only supported in ASTs with previewEnabled flag as true"); //$NON-NLS-1$ + } + } + /** * Checks that this AST operation is only used when * building JLS2 level ASTs. @@ -3099,4 +3137,11 @@ public abstract class ASTNode { * @return the size of this node in bytes */ abstract int memSize(); + + boolean isPreviewEnabled() { + if (this.ast.apiLevel == AST.JLS12_INTERNAL && this.ast.isPreviewEnabled()) { + return true; + } + return false; + } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java index 1c8312e3f0..46afdc1cb9 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/BreakStatement.java @@ -92,7 +92,14 @@ public class BreakStatement extends Statement { * @since 3.0 */ public static List propertyDescriptors(int apiLevel) { - if (apiLevel >= AST.JLS12_INTERNAL) { + return PROPERTY_DESCRIPTORS; + } + + /** + * @since 3.19 BETA_JAVA13 + */ + public static List propertyDescriptors(int apiLevel, boolean previewEnabled) { + if (apiLevel == AST.JLS12_INTERNAL && previewEnabled) { return PROPERTY_DESCRIPTORS_12; } return PROPERTY_DESCRIPTORS; @@ -125,6 +132,11 @@ public class BreakStatement extends Statement { final List internalStructuralPropertiesForType(int apiLevel) { return propertyDescriptors(apiLevel); } + + @Override + final List internalStructuralPropertiesForType(int apiLevel, boolean isPreviewEnabled) { + return propertyDescriptors(apiLevel, isPreviewEnabled); + } @Override final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { @@ -159,7 +171,7 @@ public class BreakStatement extends Statement { result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setLabel((SimpleName) ASTNode.copySubtree(target, getLabel())); - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { result.setExpression((Expression) ASTNode.copySubtree(target, getExpression())); } return result; @@ -175,7 +187,7 @@ public class BreakStatement extends Statement { void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { acceptChild(visitor, getExpression()); } acceptChild(visitor, getLabel()); @@ -217,11 +229,13 @@ public class BreakStatement extends Statement { * * @return the expression, or <code>null</code> if there is none * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public Expression getExpression() { // optionalExpression can be null unsupportedBelow12(); + unsupportedWithoutPreviewError(); return this.optionalExpression; } @@ -236,10 +250,12 @@ public class BreakStatement extends Statement { * <li>the node already has a parent</li> * </ul> * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public void setExpression(Expression expression) { unsupportedBelow12(); + unsupportedWithoutPreviewError(); ASTNode oldChild = this.optionalExpression; preReplaceChild(oldChild, expression, EXPRESSION_PROPERTY); this.optionalExpression = expression; @@ -252,10 +268,12 @@ public class BreakStatement extends Statement { * * @return isImplicit <code>true</code> or <code>false</code> * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public boolean isImplicit() { unsupportedBelow12(); + unsupportedWithoutPreviewError(); return this.isImplicit; } @@ -266,10 +284,12 @@ public class BreakStatement extends Statement { * @param isImplicit <code>true</code> or <code>false</code> * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ void setImplicit(boolean isImplicit) { unsupportedBelow12(); + unsupportedWithoutPreviewError(); this.isImplicit = isImplicit; } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java index 94404ed180..55c31294f4 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchCase.java @@ -96,7 +96,23 @@ public class SwitchCase extends Statement { * @since 3.0 */ public static List propertyDescriptors(int apiLevel) { - if (apiLevel >= AST.JLS12_INTERNAL) { + return propertyDescriptors(apiLevel, false); + } + + /** + * Returns a list of structural property descriptors for this node type. + * Clients must not modify the result. + * + * @param apiLevel the API level; one of the + * <code>AST.JLS*</code> constants + * @param previewEnabled the previewEnabled flag + * @return a list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}) + * @noreference This method is not intended to be referenced by clients. + * @since 3.19 + */ + public static List propertyDescriptors(int apiLevel, boolean previewEnabled) { + if (apiLevel == AST.JLS12_INTERNAL && previewEnabled) { return PROPERTY_DESCRIPTORS_12; } return PROPERTY_DESCRIPTORS; @@ -134,7 +150,7 @@ public class SwitchCase extends Statement { */ SwitchCase(AST ast) { super(ast); - if (ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { this.expressions = new ASTNode.NodeList(EXPRESSIONS2_PROPERTY ); } } @@ -143,6 +159,11 @@ public class SwitchCase extends Statement { final List internalStructuralPropertiesForType(int apiLevel) { return propertyDescriptors(apiLevel); } + + @Override + final List internalStructuralPropertiesForType(int apiLevel, boolean isPreviewEnabled) { + return propertyDescriptors(apiLevel, isPreviewEnabled); + } @Override final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) { @@ -192,7 +213,7 @@ public class SwitchCase extends Statement { SwitchCase result = new SwitchCase(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { result.expressions().addAll( ASTNode.copySubtrees(target, expressions())); } else { @@ -212,7 +233,7 @@ public class SwitchCase extends Statement { void accept0(ASTVisitor visitor) { boolean visitChildren = visitor.visit(this); if (visitChildren) { - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { acceptChildren(visitor, this.expressions); } else { acceptChild(visitor, getExpression()); @@ -246,15 +267,18 @@ public class SwitchCase extends Statement { /** * Returns the list of expressions of this switch case, or * <code>empty</code> if there is none (the "default:" case). + * With previewEnabled flag as false it will have only one element. * * @return the list of expression nodes * (element type: {@link Expression}) * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public List expressions() { if (this.expressions == null) { unsupportedBelow12(); + unsupportedWithoutPreviewError(); } return this.expressions; } @@ -287,10 +311,12 @@ public class SwitchCase extends Statement { * @param switchLabeledRule <code>true</code> or <code>false</code> * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public void setSwitchLabeledRule(boolean switchLabeledRule) { unsupportedBelow12(); + unsupportedWithoutPreviewError(); preValueChange(SWITCH_LABELED_RULE_PROPERTY); this.switchLabeledRule = switchLabeledRule; postValueChange(SWITCH_LABELED_RULE_PROPERTY); @@ -302,10 +328,12 @@ public class SwitchCase extends Statement { * * @return switchLabeledRule <code>true</code> or <code>false</code> * @exception UnsupportedOperationException if this operation is used below JLS12 + * @exception UnsupportedOperationException if this expression is used with previewEnabled flag as false * @since 3.18 */ public boolean isSwitchLabeledRule() { unsupportedBelow12(); + unsupportedWithoutPreviewError(); return this.switchLabeledRule; } @@ -320,7 +348,7 @@ public class SwitchCase extends Statement { * <code>false</code> if this is a non-default switch case */ public boolean isDefault() { - if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { + if (isPreviewEnabled()) { return expressions().isEmpty(); } return getExpression() == null; @@ -337,4 +365,6 @@ public class SwitchCase extends Statement { memSize() + (this.optionalExpression == null ? 0 : this.optionalExpression.treeSize()); } + + } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java index 135796d209..de55fbf8a5 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SwitchExpression.java @@ -76,7 +76,25 @@ public class SwitchExpression extends Expression { * @since 3.16 */ public static List propertyDescriptors(int apiLevel) { - return PROPERTY_DESCRIPTORS_12_0; + return propertyDescriptors(apiLevel, false); + } + + /** + * Returns a list of structural property descriptors for this node type. + * Clients must not modify the result. + * + * @param apiLevel the API level; one of the + * <code>AST.JLS*</code> constants + * @param previewEnabled previewEnabled flag + * @return a list of property descriptors (element type: + * {@link StructuralPropertyDescriptor}) + * @since 3.19 + */ + public static List propertyDescriptors(int apiLevel, boolean previewEnabled) { + if (previewEnabled) { + return PROPERTY_DESCRIPTORS_12_0; + } + return null; } /** @@ -107,12 +125,18 @@ public class SwitchExpression extends Expression { SwitchExpression(AST ast) { super(ast); unsupportedBelow12(); + unsupportedWithoutPreviewError(); } @Override final List internalStructuralPropertiesForType(int apiLevel) { return propertyDescriptors(apiLevel); } + + @Override + final List internalStructuralPropertiesForType(int apiLevel, boolean previewEnabled) { + return propertyDescriptors(apiLevel, previewEnabled); + } @Override final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { 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..42099a2d81 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,16 @@ 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())) { - this.buffer.append("break"); //$NON-NLS-1$ - } + 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 +1504,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..04f7245a58 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..f3b3101320 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,19 +362,17 @@ 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())) { - this.result.append("break"); //$NON-NLS-1$ - } + this.result.append("break"); //$NON-NLS-1$ ASTNode label= getChildNode(node, BreakStatement.LABEL_PROPERTY); if (label != null) { 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 +981,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$ @@ -994,7 +992,7 @@ public class ASTRewriteFlattener extends ASTVisitor { t.accept(this); this.result.append(it.hasNext() ? ", " : ""); //$NON-NLS-1$ //$NON-NLS-2$ } - this.result.append(getBooleanAttribute(node, SwitchCase.SWITCH_LABELED_RULE_PROPERTY) ? " ->" : ":");//$NON-NLS-1$ //$NON-NLS-2$ + this.result.append(getBooleanAttribute(node, SwitchCase.SWITCH_LABELED_RULE_PROPERTY) ? " ->" : ":");//$NON-NLS-1$ //$NON-NLS-2$ } } else { ASTNode expression= getChildNode(node, INTERNAL_SWITCH_EXPRESSION_PROPERTY); |