use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidMemberClassModifiers.
@Test
public void testInvalidMemberClassModifiers() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface E {\n");
buf.append(" private class Inner {\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 interface E {\n");
buf.append(" class Inner {\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 testOverridesMoreVisibleMethodInGeneric.
@Test
public void testOverridesMoreVisibleMethodInGeneric() throws Exception {
IPackageFragment pack2 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class C<T> {\n");
buf.append(" public <M> T foo(M m) {\n");
buf.append(" }\n");
buf.append("}\n");
pack2.createCompilationUnit("C.java", buf.toString(), false, null);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import test2.C;\n");
buf.append("public class E extends C<String> {\n");
buf.append(" protected <M> String foo(M m) {\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 test2;\n");
buf.append("public class C<T> {\n");
buf.append(" protected <M> T foo(M m) {\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 test2.C;\n");
buf.append("public class E extends C<String> {\n");
buf.append(" public <M> String foo(M m) {\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 testInvalidInterfaceModifiers.
@Test
public void testInvalidInterfaceModifiers() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public static interface E {\n");
buf.append(" public void 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, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface E {\n");
buf.append(" public void foo();\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 testInvisibleConstructorRequestedInOtherType.
@Test
public void testInvisibleConstructorRequestedInOtherType() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class C {\n");
buf.append(" private C() {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("C.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" C c= new 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);
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 C {\n");
buf.append(" C() {\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 testSuppressBug169446.
@Test
public void testSuppressBug169446() throws Exception {
IPackageFragment other = fSourceFolder.createPackageFragment("other", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package other; \n");
buf.append("\n");
buf.append("public @interface SuppressWarnings {\n");
buf.append(" String value();\n");
buf.append("}\n");
other.createCompilationUnit("SuppressWarnings.java", buf.toString(), false, null);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("a.b", false, null);
buf = new StringBuffer();
buf.append("package a.b;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" @Deprecated()\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("E.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package a.b;\n");
buf.append("\n");
buf.append("import other.SuppressWarnings;\n");
buf.append("\n");
buf.append("public class Test {\n");
buf.append(" @SuppressWarnings(\"BC\")\n");
buf.append(" public void foo() {\n");
buf.append(" new E().foo();\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Test.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 a.b;\n");
buf.append("\n");
buf.append("import other.SuppressWarnings;\n");
buf.append("\n");
buf.append("public class Test {\n");
buf.append(" @java.lang.SuppressWarnings(\"deprecation\")\n");
buf.append(" @SuppressWarnings(\"BC\")\n");
buf.append(" public void foo() {\n");
buf.append(" new E().foo();\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
Aggregations