List of usage examples for org.eclipse.jdt.core JavaCore COMPILER_PB_UNUSED_OBJECT_ALLOCATION
String COMPILER_PB_UNUSED_OBJECT_ALLOCATION
To view the source code for org.eclipse.jdt.core JavaCore COMPILER_PB_UNUSED_OBJECT_ALLOCATION.
Click Source Link
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testUnusedObjectAllocation1() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION, JavaCore.WARNING); JavaCore.setOptions(options);//from w ww . 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("\n"); buf.append("public class E {\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" /*a*/new Object()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append(" return null;\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); assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 5); String[] expected = new String[5]; buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" /*a*/return new Object()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); expected[0] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); expected[1] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" /*a*/new Object()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); expected[2] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" /*a*/Object object = new Object()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); expected[3] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" private Object object;\n"); buf.append("\n"); buf.append(" public Object foo() {\n"); buf.append(" if (Boolean.TRUE) {\n"); buf.append(" /*a*/object = new Object()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}\n"); expected[4] = buf.toString(); assertExpectedExistInProposals(proposals, expected); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testUnusedObjectAllocation2() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION, JavaCore.WARNING); JavaCore.setOptions(options);// w w w . j a v a 2 s .c om IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/new Exception()/*b*/;/*c*/\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); assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 6); String[] expected = new String[6]; buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/throw new Exception()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append("}\n"); expected[0] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" }\n"); buf.append("}\n"); expected[1] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" @SuppressWarnings(\"unused\")\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/new Exception()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append("}\n"); expected[2] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/return new Exception()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append("}\n"); expected[3] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/Exception exception = new Exception()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append("}\n"); expected[4] = buf.toString(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" private Exception exception;\n"); buf.append("\n"); buf.append(" public void foo() {\n"); buf.append(" /*a*/exception = new Exception()/*b*/;/*c*/\n"); buf.append(" }\n"); buf.append("}\n"); expected[5] = buf.toString(); assertExpectedExistInProposals(proposals, expected); }
From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java
License:Open Source License
@Test public void testUnusedObjectAllocation3() throws Exception { Hashtable options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION, JavaCore.WARNING); JavaCore.setOptions(options);// w ww . java 2 s.c om IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" private Object name;\n"); buf.append(" public E() {\n"); buf.append(" if (name == null)\n"); buf.append(" new IllegalArgumentException();\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); assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 5); String expected = new String(); buf = new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); buf.append("public class E {\n"); buf.append(" private Object name;\n"); buf.append(" public E() {\n"); buf.append(" if (name == null)\n"); buf.append(" throw new IllegalArgumentException();\n"); buf.append(" }\n"); buf.append("}\n"); expected = buf.toString(); assertExpectedExistInProposals(proposals, new String[] { expected }); }