use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest17 method testRemoveRedundantTypeArguments3.
@Test
public void testRemoveRedundantTypeArguments3() 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("import java.util.Map;\n");
buf.append("public class E {\n");
buf.append(" void foo() {\n");
buf.append(" List<Map<String, String>> a = new ArrayList<Map<String, 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, 3);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.List;\n");
buf.append("import java.util.Map;\n");
buf.append("public class E {\n");
buf.append(" void foo() {\n");
buf.append(" List<Map<String, String>> a = new ArrayList<>();;\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest17 method testUnneededCatchBlockTryWithResources.
@Test
public void testUnneededCatchBlockTryWithResources() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.io.FileReader;\n");
buf.append("class MyException extends Exception {\n");
buf.append(" static final long serialVersionUID = 1L;\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void foo() throws Exception {\n");
buf.append(" try (FileReader reader1 = new FileReader(\"file\")) {\n");
buf.append(" int ch;\n");
buf.append(" while ((ch = reader1.read()) != -1) {\n");
buf.append(" System.out.println(ch);\n");
buf.append(" }\n");
buf.append(" } catch (MyException e) {\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("import java.io.FileReader;\n");
buf.append("class MyException extends Exception {\n");
buf.append(" static final long serialVersionUID = 1L;\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void foo() throws Exception {\n");
buf.append(" try (FileReader reader1 = new FileReader(\"file\")) {\n");
buf.append(" int ch;\n");
buf.append(" while ((ch = reader1.read()) != -1) {\n");
buf.append(" System.out.println(ch);\n");
buf.append(" }\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("import java.io.FileReader;\n");
buf.append("class MyException extends Exception {\n");
buf.append(" static final long serialVersionUID = 1L;\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void foo() throws Exception {\n");
buf.append(" try (FileReader reader1 = new FileReader(\"file\")) {\n");
buf.append(" int ch;\n");
buf.append(" while ((ch = reader1.read()) != -1) {\n");
buf.append(" System.out.println(ch);\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 });
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testSuppressWarningsForFieldVariables.
@Test
public void testSuppressWarningsForFieldVariables() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
JavaCore.setOptions(options);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1; \n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" List<String> myList = new ArrayList();\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot, 1);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 3);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package test1; \n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" @SuppressWarnings(\"unchecked\")\n");
buf.append(" List<String> myList = new ArrayList();\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 ModifierCorrectionsQuickFixTest method testMethodRequiresBody2.
@Test
public void testMethodRequiresBody2() 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(" public int foo();\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 0;\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(" public abstract int foo();\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidVisabilityOverrideMethod.
/**
* Quick Fix proposes wrong visibility for overriding/overridden method.
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=216898#c1
*
* @throws Exception if anything goes wrong
* @since 3.9
*/
@Test
public void testInvalidVisabilityOverrideMethod() throws Exception {
// No simple solution to this problemID IProblem.AbstractMethodCannotBeOverridden
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
IPackageFragment pack2 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public abstract class Abs {\n");
buf.append(" abstract String getName();\n");
buf.append("}\n");
pack1.createCompilationUnit("Abs.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class AbsImpl extends test1.Abs {\n");
buf.append(" String getName() {\n");
buf.append(" return \"name\";\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("AbsImpl.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot, 2);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 0);
}
Aggregations