use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testRemoveDeadCodeIfElse.
@Test
public void testRemoveDeadCodeIfElse() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING);
JavaCore.setOptions(options);
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 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUndefinedConstructorWithEnclosingInGeneric.
@Test
public void testUndefinedConstructorWithEnclosingInGeneric() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class F<S> {\n");
buf.append(" public class SubF <T>{\n");
buf.append(" public SubF(S s, T t) {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("F.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E extends F<String>.SubF<String> {\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, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E extends F<String>.SubF<String> {\n");
buf.append("\n");
buf.append(" public E(F<String> f, String s, String t) {\n");
buf.append(" f.super(s, t);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUncaughtExceptionOnSuper3.
@Test
public void testUncaughtExceptionOnSuper3() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A implements Runnable {\n");
buf.append(" public void run() {\n");
buf.append(" Class.forName(null);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A implements Runnable {\n");
buf.append(" public void run() {\n");
buf.append(" try {\n");
buf.append(" Class.forName(null);\n");
buf.append(" } catch (ClassNotFoundException e) {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testRemoveUnreachableCodeMultiStatementsSwitch.
@Test
public void testRemoveUnreachableCodeMultiStatementsSwitch() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING);
JavaCore.setOptions(options);
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(" foo();\n");
buf.append(" break;\n");
buf.append(" foo();\n");
buf.append(" new Object();\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, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = 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(" foo();\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");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnusedVariable4.
@Test
public void testUnusedVariable4() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR);
hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER, JavaCore.ERROR);
hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE, JavaCore.DISABLED);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" /**\n");
buf.append(" * @param i\n");
buf.append(" */\n");
buf.append(" private void foo(int i) {\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, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" /**\n");
buf.append(" */\n");
buf.append(" private void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations