use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class UnresolvedTypesQuickFixTest method testAmbiguousTypeInInterface.
@Test
@Ignore
public void testAmbiguousTypeInInterface() throws Exception {
createSomeAmbiguity(true, false);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import test2.*;\n");
buf.append("import test3.*;\n");
buf.append("public class E implements A {\n");
buf.append(" B b;\n");
buf.append(" C c;\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 test2.*;\n");
buf.append("import test2.A;\n");
buf.append("import test3.*;\n");
buf.append("public class E implements A {\n");
buf.append(" B b;\n");
buf.append(" C c;\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.*;\n");
buf.append("import test3.*;\n");
buf.append("import test3.A;\n");
buf.append("public class E implements A {\n");
buf.append(" B b;\n");
buf.append(" C c;\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 UnresolvedTypesQuickFixTest method testAmbiguousTypeInArgument.
@Test
@Ignore
public void testAmbiguousTypeInArgument() throws Exception {
createSomeAmbiguity(true, false);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import test2.*;\n");
buf.append("import test3.*;\n");
buf.append("public class E {\n");
buf.append(" B b;\n");
buf.append(" C c;\n");
buf.append(" public void foo(A a) {");
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 test2.*;\n");
buf.append("import test2.A;\n");
buf.append("import test3.*;\n");
buf.append("public class E {\n");
buf.append(" B b;\n");
buf.append(" C c;\n");
buf.append(" public void foo(A a) {");
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.*;\n");
buf.append("import test3.*;\n");
buf.append("import test3.A;\n");
buf.append("public class E {\n");
buf.append(" B b;\n");
buf.append(" C c;\n");
buf.append(" public void foo(A a) {");
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 TypeMismatchQuickFixTests method testMismatchingExceptions2.
@Test
public void testMismatchingExceptions2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.io.IOException;\n");
buf.append("public class Base {\n");
buf.append(" String[] getValues() throws IOException {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("Base.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.io.EOFException;\n");
buf.append("import java.text.ParseException;\n");
buf.append("public class E extends Base {\n");
buf.append(" public String[] getValues() throws EOFException, ParseException {\n");
buf.append(" return null;\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.IOException;\n");
buf.append("import java.text.ParseException;\n");
buf.append("public class Base {\n");
buf.append(" String[] getValues() throws IOException, ParseException {\n");
buf.append(" return null;\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.EOFException;\n");
buf.append("import java.text.ParseException;\n");
buf.append("public class E extends Base {\n");
buf.append(" public String[] getValues() throws EOFException {\n");
buf.append(" return null;\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 TypeMismatchQuickFixTests method testMismatchingReturnTypeOnGenericMethod.
@Test
public void testMismatchingReturnTypeOnGenericMethod() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.annotation.Annotation;\n");
buf.append("import java.lang.reflect.AccessibleObject;\n");
buf.append("public class E {\n");
buf.append(" void m() {\n");
buf.append(" new AccessibleObject() {\n");
buf.append(" public <T extends Annotation> void getAnnotation(Class<T> annotationClass) {\n");
buf.append(" }\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 preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.annotation.Annotation;\n");
buf.append("import java.lang.reflect.AccessibleObject;\n");
buf.append("public class E {\n");
buf.append(" void m() {\n");
buf.append(" new AccessibleObject() {\n");
buf.append(" public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testTypeMismatchForInterfaceInGeneric2.
@Test
public void testTypeMismatchForInterfaceInGeneric2() throws Exception {
IPackageFragment pack0 = fSourceFolder.createPackageFragment("test0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test0;\n");
buf.append("public interface PrimaryContainer<A> {\n");
buf.append("}\n");
pack0.createCompilationUnit("PrimaryContainer.java", buf.toString(), false, null);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class Container<A> {\n");
buf.append(" public Container<A> getContainer() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("Container.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.List;\n");
buf.append("import test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<List<?>> c) {\n");
buf.append(" PrimaryContainer<?> list= c.getContainer();\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 java.util.List;\n");
buf.append("import test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<List<?>> c) {\n");
buf.append(" Container<List<?>> list= c.getContainer();\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.util.List;\n");
buf.append("import test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<List<?>> c) {\n");
buf.append(" PrimaryContainer<?> list= (PrimaryContainer<?>) c.getContainer();\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 test1;\n");
buf.append("\n");
buf.append("import test0.PrimaryContainer;\n");
buf.append("\n");
buf.append("public class Container<A> {\n");
buf.append(" public PrimaryContainer<?> getContainer() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
String expected3 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 });
}
Aggregations