diff options
author | Jay Arthanareeswaran | 2019-02-21 12:37:49 +0000 |
---|---|---|
committer | Sarika Sinha | 2019-02-26 20:29:58 +0000 |
commit | 2dfafebe5b2de626769e9d808a8e65372af7e071 (patch) | |
tree | 48722649622c9484d9bea23bbbc6ba4022cd9e6c | |
parent | feb01aa7e990efe551d7871cbf27ba9f2898ad47 (diff) | |
download | eclipse.jdt.core-2dfafebe5b2de626769e9d808a8e65372af7e071.tar.gz eclipse.jdt.core-2dfafebe5b2de626769e9d808a8e65372af7e071.tar.xz eclipse.jdt.core-2dfafebe5b2de626769e9d808a8e65372af7e071.zip |
Bug 542558 - [12][dom ast] DOM AST Support for Switch Expressions
Fix all warnings about deprecated methods/fields
Change-Id: Icb5de73babb8ba0c9f099e31b9e3d4b25ac08e0d
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
16 files changed, 70 insertions, 13 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java index dc6db31f4a..21383f0431 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java @@ -4829,12 +4829,14 @@ public class ASTConverter15JLS4Test extends ConverterTestSetup { statement = (Statement) statements.get(0); assertEquals("Not a switch case statement", ASTNode.SWITCH_CASE, statement.getNodeType()); SwitchCase switchCase = (SwitchCase) statement; + @SuppressWarnings("deprecation") Expression expression = switchCase.getExpression(); assertNull("Got a constant", expression.resolveConstantExpressionValue()); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548 - public void test0152() throws CoreException { + @SuppressWarnings("deprecation") + public void test0152() throws CoreException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = "public class X {\n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java index 32ef339415..546c5a585a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS8Test.java @@ -4759,7 +4759,8 @@ public class ASTConverter15JLS8Test extends ConverterTestSetup { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548 - public void test0151() throws CoreException { + @SuppressWarnings("deprecation") + public void test0151() throws CoreException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = "public enum X {\n" + @@ -4822,7 +4823,8 @@ public class ASTConverter15JLS8Test extends ConverterTestSetup { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548 - public void test0152() throws CoreException { + @SuppressWarnings("deprecation") + public void test0152() throws CoreException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = "public class X {\n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java index 3a42702693..00cd53b3be 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java @@ -4781,7 +4781,8 @@ public class ASTConverter15Test extends ConverterTestSetup { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548 - public void test0151() throws CoreException { + @SuppressWarnings("deprecation") + public void test0151() throws CoreException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = "public enum X {\n" + @@ -4844,7 +4845,8 @@ public class ASTConverter15Test extends ConverterTestSetup { } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548 - public void test0152() throws CoreException { + @SuppressWarnings("deprecation") + public void test0152() throws CoreException { this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); String contents = "public class X {\n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java index addae41c47..f4d1f0ef49 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java @@ -2088,6 +2088,7 @@ public class ASTConverterAST3Test extends ConverterTestSetup { /** * SwitchStatement ==> SwitchStatement */ + @SuppressWarnings("deprecation") public void test0097() throws JavaModelException { ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ char[] source = sourceUnit.getSource().toCharArray(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java index 926d8a34bd..4b77b6e96a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST4Test.java @@ -2088,6 +2088,7 @@ public class ASTConverterAST4Test extends ConverterTestSetup { /** * SwitchStatement ==> SwitchStatement */ + @SuppressWarnings("deprecation") public void test0097() throws JavaModelException { ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ char[] source = sourceUnit.getSource().toCharArray(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java index 9c83e01fce..9e617b11bd 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST8Test.java @@ -2072,6 +2072,7 @@ public class ASTConverterAST8Test extends ConverterTestSetup { /** * SwitchStatement ==> SwitchStatement */ + @SuppressWarnings("deprecation") public void test0097() throws JavaModelException { ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ char[] source = sourceUnit.getSource().toCharArray(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java index acbd8ddf23..dfafd6d6a9 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java @@ -2177,6 +2177,7 @@ public class ASTConverterTest extends ConverterTestSetup { /** * SwitchStatement ==> SwitchStatement */ + @SuppressWarnings("deprecation") public void test0097() throws JavaModelException { ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ char[] source = sourceUnit.getSource().toCharArray(); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java index 04ca9bb6e8..6b421b9407 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java @@ -1206,6 +1206,7 @@ public class ASTMatcherTest extends org.eclipse.jdt.core.tests.junit.extension.T x1.setName(this.N2); basicMatch(x1); } + @SuppressWarnings("deprecation") public void testSwitchCase() { SwitchCase x1 = this.ast.newSwitchCase(); x1.setExpression(this.E1); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java index 0407d10cc6..c5e62c6311 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java @@ -2096,6 +2096,7 @@ public class ASTVisitorTest extends org.eclipse.jdt.core.tests.junit.extension.T String result = this.b.toString(); assertTrue(result.equals("[(eSMR"+this.N1S+this.N2S+"eSMR)]")); //$NON-NLS-1$ //$NON-NLS-2$ } + @SuppressWarnings("deprecation") public void testSwitchCase() { SwitchCase x1 = this.ast.newSwitchCase(); x1.setExpression(this.E1); 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 433b8554ca..fc9b8be5d8 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 @@ -3562,6 +3562,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { } + @SuppressWarnings("deprecation") public void testSwitchStatement() throws Exception { IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); @@ -3691,6 +3692,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { } + @SuppressWarnings("deprecation") public void testSwitchStatement2() throws Exception { String previousValue = null; try { @@ -4050,6 +4052,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { * https://bugs.eclipse.org/bugs/show_bug.cgi?id=246627 * Replace a statement preceded by an unchanged statement) */ + @SuppressWarnings("deprecation") public void testSwitchStatement7() throws Exception { String previousValue = null; try { @@ -4192,6 +4195,7 @@ public class ASTRewritingStatementsTest extends ASTRewritingTest { * https://bugs.eclipse.org/bugs/show_bug.cgi?id=246627 * Remove a statement followed by an inserted statement) */ + @SuppressWarnings("deprecation") public void testSwitchStatement9() throws Exception { String previousValue = null; try { 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 cd1ea2b897..3253a99b97 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 @@ -364,7 +364,15 @@ class ASTConverter { spanningNode.setFlags(spanningNode.getFlags() | ASTNode.MALFORMED); } } - + /** + * Internal access method to SwitchCase#setExpression() for avoiding deprecated warnings + * @param switchCase + * @param exp + * @deprecated + */ + private static void internalSetExpression(SwitchCase switchCase, Expression exp) { + switchCase.setExpression(exp); + } /** * Internal access method to SingleVariableDeclaration#setExtraDimensions() for avoiding deprecated warnings * @@ -1311,9 +1319,9 @@ class ASTConverter { } else { org.eclipse.jdt.internal.compiler.ast.Expression constantExpression = statement.constantExpression; if (constantExpression == null) { - switchCase.setExpression(null); + internalSetExpression(switchCase, null); } else { - switchCase.setExpression(convert(constantExpression)); + internalSetExpression(switchCase, convert(constantExpression)); } } if (this.ast.apiLevel >= AST.JLS12_INTERNAL) { 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 55e2ed3680..defcaa152f 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 @@ -2275,10 +2275,20 @@ public class ASTMatcher { SwitchCase o = (SwitchCase) other; return ( node.getAST().apiLevel >= AST.JLS12_INTERNAL ? safeSubtreeListMatch(node.getExpressions(), o.getExpressions()) - : safeSubtreeMatch(node.getExpression(), o.getExpression())); + : compareDeprecatedSwitchExpression(node, o)); } /** + * Return whether the deprecated comment strings of the given java doc are equals. + * <p> + * Note the only purpose of this method is to hide deprecated warnings. + * @deprecated mark deprecated to hide deprecated usage + */ + private boolean compareDeprecatedSwitchExpression(SwitchCase first, SwitchCase second) { + return safeSubtreeMatch(first.getExpression(), second.getExpression()); + } + + /** * Returns whether the given node and the other object match. * <p> * The default implementation provided by this class tests whether the 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 12af14c5e6..bbc8630985 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 @@ -1532,13 +1532,19 @@ public class NaiveASTFlattener extends ASTVisitor { this.buffer.append("default :\n");//$NON-NLS-1$ } else { this.buffer.append("case ");//$NON-NLS-1$ - node.getExpression().accept(this); + getSwitchExpression(node).accept(this); this.buffer.append(":\n");//$NON-NLS-1$ } } this.indent++; //decremented in visit(SwitchStatement) return false; } + /** + * @deprecated + */ + private Expression getSwitchExpression(SwitchCase node) { + return node.getExpression(); + } private void visitSwitchNode(ASTNode node) { this.buffer.append("switch (");//$NON-NLS-1$ 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 74dd7b3741..b32d738129 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 @@ -117,6 +117,9 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { /** @deprecated using deprecated code */ private static final ChildListPropertyDescriptor INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY = TryStatement.RESOURCES_PROPERTY; + + /** @deprecated using deprecated code */ + private static final ChildPropertyDescriptor INTERNAL_SWITCH_EXPRESSION_PROPERTY = SwitchCase.EXPRESSION_PROPERTY; /** @deprecated using deprecated code */ private static final int JLS2_INTERNAL = AST.JLS2; @@ -3409,7 +3412,7 @@ public final class ASTRewriteAnalyzer extends ASTVisitor { } // dont allow switching from case to default or back. New statements should be created. - rewriteRequiredNode(node, SwitchCase.EXPRESSION_PROPERTY); + rewriteRequiredNode(node, INTERNAL_SWITCH_EXPRESSION_PROPERTY); return false; } 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 ee92237352..117b09530b 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 @@ -76,6 +76,9 @@ public class ASTRewriteFlattener extends ASTVisitor { private static final ChildListPropertyDescriptor INTERNAL_TRY_STATEMENT_RESOURCES_PROPERTY = TryStatement.RESOURCES_PROPERTY; /** @deprecated using deprecated code */ + private static final ChildPropertyDescriptor INTERNAL_SWITCH_EXPRESSION_PROPERTY = SwitchCase.EXPRESSION_PROPERTY; + + /** @deprecated using deprecated code */ private static final int JLS2_INTERNAL = AST.JLS2; /** @deprecated using deprecated code */ @@ -959,7 +962,7 @@ public class ASTRewriteFlattener extends ASTVisitor { @Override public boolean visit(SwitchCase node) { - ASTNode expression= getChildNode(node, SwitchCase.EXPRESSION_PROPERTY); + ASTNode expression= getChildNode(node, INTERNAL_SWITCH_EXPRESSION_PROPERTY); if (expression == null) { this.result.append("default"); //$NON-NLS-1$ } else { diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java index f194800322..ba40de8431 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java @@ -386,11 +386,22 @@ public class SpacePreparator extends ASTVisitor { handleToken(node, TokenNameCOLON, this.options.insert_space_before_colon_in_default, false); } else { handleToken(node, TokenNamecase, false, true); - handleToken(node.getExpression(), TokenNameCOLON, this.options.insert_space_before_colon_in_case, false); + handleToken(getSwitchExpression(node), TokenNameCOLON, this.options.insert_space_before_colon_in_case, false); } return true; } + /** + * + * @param node + * @return expression + * @deprecated + */ + private Expression getSwitchExpression(SwitchCase node) { + return node.getExpression(); + } + + @Override public boolean visit(DoStatement node) { handleTokenBefore(node.getExpression(), TokenNameLPAREN, |