List of usage examples for org.eclipse.jdt.core JavaCore COMPILER_PB_DEAD_CODE
String COMPILER_PB_DEAD_CODE
To view the source code for org.eclipse.jdt.core JavaCore COMPILER_PB_DEAD_CODE.
Click Source Link
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThen() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/* w ww .ja v a2s. co m*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" if (false) {\n"); buf.append(" System.out.println(\"a\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"b\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" System.out.println(\"b\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" if (false) {\n"); buf.append(" System.out.println(\"a\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"b\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThen2() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/* ww w . java2 s . co m*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) {\n"); buf.append(" if (o == null) {\n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) {\n"); buf.append(" if (o == null) {\n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThen3() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/* www . j av a 2 s . c o m*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (o == null) {\n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" System.out.println(\"bye-bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" System.out.println(\"bye-bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (o == null) {\n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" System.out.println(\"bye-bye\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThen4() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/* www . ja v a 2s .c om*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (true) \n"); buf.append(" if (o == null) \n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (true) {\n"); buf.append(" }\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (true) \n"); buf.append(" if (o == null) \n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThen5() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/*w ww.j av a 2s .c om*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (false) \n"); buf.append(" if (o == null) \n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) {\n"); buf.append(" }\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = new Object();\n"); buf.append(" if (o != null) \n"); buf.append(" if (false) \n"); buf.append(" if (o == null) \n"); buf.append(" System.out.println(\"hello\");\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfThenSwitch() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/* w ww . j a v a 2s . c o m*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" switch (1) {\n"); buf.append(" case 1:\n"); buf.append(" if (false) {\n"); buf.append(" foo();\n"); buf.append(" System.out.println(\"hi\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append(" break;\n"); buf.append(" case 2:\n"); buf.append(" foo();\n"); buf.append(" break;\n"); buf.append(" default:\n"); buf.append(" break;\n"); buf.append(" };\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" switch (1) {\n"); buf.append(" case 1:\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" break;\n"); buf.append(" case 2:\n"); buf.append(" foo();\n"); buf.append(" break;\n"); buf.append(" default:\n"); buf.append(" break;\n"); buf.append(" };\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" switch (1) {\n"); buf.append(" case 1:\n"); buf.append(" if (false) {\n"); buf.append(" foo();\n"); buf.append(" System.out.println(\"hi\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"bye\");\n"); buf.append(" }\n"); buf.append(" break;\n"); buf.append(" case 2:\n"); buf.append(" foo();\n"); buf.append(" break;\n"); buf.append(" default:\n"); buf.append(" break;\n"); buf.append(" };\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeIfElse() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);// ww w .j ava2s .c o m IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" if (Math.random() == -1 || true) {\n"); buf.append(" System.out.println(\"a\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"b\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" System.out.println(\"a\");\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" if (Math.random() == -1 || true) {\n"); buf.append(" System.out.println(\"a\");\n"); buf.append(" } else {\n"); buf.append(" System.out.println(\"b\");\n"); buf.append(" }\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeAfterIf() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);//from w w w . ja va 2s . c o m IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public boolean foo() {\n"); buf.append(" if (true) return false;\n"); buf.append(" return true;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public boolean foo() {\n"); buf.append(" return false;\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public boolean foo() {\n"); buf.append(" if (true) return false;\n"); buf.append(" return true;\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeConditional() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);/*from w w w .jav a 2s .com*/ IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public int foo() {\n"); buf.append(" return true ? 1 : 0;\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0); String preview1 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public int foo() {\n"); buf.append(" return 1;\n"); buf.append(" }\n"); buf.append("}\n"); String expected1 = buf.toString(); proposal = (CUCorrectionProposal) proposals.get(1); String preview2 = getPreviewContent(proposal); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public int foo() {\n"); buf.append(" return true ? 1 : 0;\n"); buf.append(" }\n"); buf.append("}\n"); String expected2 = buf.toString(); assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testRemoveDeadCodeConditional2() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); JavaCore.setOptions(options);//from ww w . ja v a2 s. co m IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = true ? new Integer(1) + 2 : new Double(0.0) + 3;\n"); buf.append(" System.out.println(o);\n"); buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); CompilationUnit astRoot = getASTRoot(cu); ArrayList proposals = collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" Object o = (double) (new Integer(1) + 2);\n"); buf.append(" System.out.println(o);\n"); buf.append(" }\n"); buf.append("}\n"); String[] expected = new String[] { buf.toString() }; assertExpectedExistInProposals(proposals, expected); }