use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnimplementedMethodsInEnumConstant2.
@Test
public void testUnimplementedMethodsInEnumConstant2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("enum TestEnum {\n");
buf.append(" A {\n");
buf.append(" };\n");
buf.append(" public abstract boolean foo();\n");
buf.append(" public abstract void bar();\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("TestEnum.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot, 2);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 1);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("enum TestEnum {\n");
buf.append(" A {\n");
buf.append("\n");
buf.append(" @Override\n");
buf.append(" public boolean foo() {\n");
buf.append(" return false;\n");
buf.append(" }\n");
buf.append("\n");
buf.append(" @Override\n");
buf.append(" public void bar() {\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" public abstract boolean foo();\n");
buf.append(" public abstract void bar();\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 testInheritedAccessOnStaticInGeneric.
@Test
public void testInheritedAccessOnStaticInGeneric() throws Exception {
IPackageFragment pack0 = fSourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class A<T> {\n");
buf.append(" public static void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
pack0.createCompilationUnit("A.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class B<T> extends A<String> {\n");
buf.append("}\n");
pack0.createCompilationUnit("B.java", buf.toString(), false, null);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import pack.B;\n");
buf.append("public class E {\n");
buf.append(" public void foo(B<Number> b) {\n");
buf.append(" b.foo();\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);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import pack.B;\n");
buf.append("public class E {\n");
buf.append(" public void foo(B<Number> b) {\n");
buf.append(" B.foo();\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 pack.A;\n");
buf.append("import pack.B;\n");
buf.append("public class E {\n");
buf.append(" public void foo(B<Number> b) {\n");
buf.append(" A.foo();\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(2);
String preview3 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class A<T> {\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
String expected3 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 });
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUndefinedConstructorWithLineBreaks.
@Test
public void testUndefinedConstructorWithLineBreaks() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "30");
String optionValue = DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT);
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, optionValue);
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, optionValue);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class F {\n");
buf.append(" public F(Runnable runnable, boolean isGreen, boolean isBlue, boolean isRed) {\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 {\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 {\n");
buf.append("\n");
buf.append(" public E(\n");
buf.append(" Runnable runnable,\n");
buf.append(" boolean isGreen,\n");
buf.append(" boolean isBlue,\n");
buf.append(" boolean isRed) {\n");
buf.append(" super(\n");
buf.append(" runnable,\n");
buf.append(" isGreen,\n");
buf.append(" isBlue,\n");
buf.append(" isRed);\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 testUnimplementedMethodsWithSubsignature3.
@Test
public void testUnimplementedMethodsWithSubsignature3() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=272657 , https://bugs.eclipse.org/bugs/show_bug.cgi?id=424509#c6
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("import java.math.BigInteger;\n");
buf.append("\n");
buf.append("interface A { Object m(Class c); }\n");
buf.append("interface B<S extends Number> { Object m(Class<S> c); }\n");
buf.append("interface D<S,T> extends B<BigInteger>, A {}\n");
buf.append("\n");
buf.append("class M implements D<BigInteger,BigInteger> {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 2);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("import java.math.BigInteger;\n");
buf.append("\n");
buf.append("interface A { Object m(Class c); }\n");
buf.append("interface B<S extends Number> { Object m(Class<S> c); }\n");
buf.append("interface D<S,T> extends B<BigInteger>, A {}\n");
buf.append("\n");
buf.append("class M implements D<BigInteger,BigInteger> {\n");
buf.append("\n");
buf.append(" public Object m(Class c) {\n");
buf.append(" return null;\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 testUnimplementedMethods_bug113665.
@Test
public void testUnimplementedMethods_bug113665() throws Exception {
IPackageFragment pack2 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public interface F {\n");
buf.append(" public void c() throws Exception;\n");
buf.append(" public void e();\n");
buf.append("}\n");
pack2.createCompilationUnit("F.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("A.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 test2;\n");
buf.append("public class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("\n");
buf.append(" public void e() {\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 test2;\n");
buf.append("public abstract class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
Aggregations