use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testSetFinalVariable4.
@Test
public void testSetFinalVariable4() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.List;\n");
buf.append("public class E {\n");
buf.append(" final List<String> a= null, x= a, y= a;\n");
buf.append(" public void foo() {\n");
buf.append(" x= new ArrayList<String>();\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("import java.util.ArrayList;\n");
buf.append("import java.util.List;\n");
buf.append("public class E {\n");
buf.append(" final List<String> a= null;\n");
buf.append(" List<String> x= a;\n");
buf.append(" final List<String> y= a;\n");
buf.append(" public void foo() {\n");
buf.append(" x= new ArrayList<String>();\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidVariableModifiers.
@Test
public void testInvalidVariableModifiers() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private void foo() {\n");
buf.append(" native int x;\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(" private void foo() {\n");
buf.append(" int x;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnnessecaryNLSTag6.
@Test
public void testUnnessecaryNLSTag6() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
JavaCore.setOptions(options);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" foo(); //$NON-NLS-1$ / more\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, 2);
String[] expected = new String[2];
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" foo(); // / more\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("public class E {\n");
buf.append(" @SuppressWarnings(\"nls\")\n");
buf.append(" public void foo() {\n");
buf.append(" foo(); //$NON-NLS-1$ / more\n");
buf.append(" }\n");
buf.append("}\n");
expected[1] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnnecessaryElse5.
@Test
public void testUnnecessaryElse5() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNNECESSARY_ELSE, JavaCore.ERROR);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("p", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package p;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" boolean foo(int i) {\n");
buf.append(" switch (i) {\n");
buf.append(" case 42:\n");
buf.append(" if (foo(i+1))\n");
buf.append(" return true;\n");
buf.append(" else\n");
buf.append(" i = i + 3;\n");
buf.append(" }\n");
buf.append(" return false;\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, 1);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package p;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" boolean foo(int i) {\n");
buf.append(" switch (i) {\n");
buf.append(" case 42:\n");
buf.append(" if (foo(i+1))\n");
buf.append(" return true;\n");
buf.append(" i = i + 3;\n");
buf.append(" }\n");
buf.append(" return false;\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testRemoveDeadCodeConditional3.
@Test
public void testRemoveDeadCodeConditional3() 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(" Object o = true ? new Integer(1) : new Double(0.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, 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);\n");
buf.append(" }\n");
buf.append("}\n");
String[] expected = new String[] { buf.toString() };
assertExpectedExistInProposals(proposals, expected);
}
Aggregations