use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testTypeMismatchForInterfaceInGeneric.
@Test
public void testTypeMismatchForInterfaceInGeneric() 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 test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<String> c) {\n");
buf.append(" PrimaryContainer<String> 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, 4);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<String> c) {\n");
buf.append(" Container<String> 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 test0.PrimaryContainer;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Container<String> c) {\n");
buf.append(" PrimaryContainer<String> list= (PrimaryContainer<String>) 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<String> getContainer() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
String expected3 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(3);
String preview4 = 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> implements PrimaryContainer<String> {\n");
buf.append(" public Container<A> getContainer() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
String expected4 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4 }, new String[] { expected1, expected2, expected3, expected4 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testTypeMismatchInAssignment.
@Test
public void testTypeMismatchInAssignment() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.Iterator;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" String str;\n");
buf.append(" str= iter.next();\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.util.Iterator;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" String str;\n");
buf.append(" str= (String) iter.next();\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.Iterator;\n");
buf.append("public class E {\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" Object str;\n");
buf.append(" str= iter.next();\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 testMismatchingReturnTypeOnGenericMethod14.
@Test
public void testMismatchingReturnTypeOnGenericMethod14() throws Exception {
Map<String, String> options = fJProject1.getOptions(false);
try {
Map<String, String> options14 = new HashMap<String, String>(options);
JavaModelUtil.setComplianceOptions(options14, JavaCore.VERSION_1_4);
fJProject1.setOptions(options14);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\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 void getAnnotation(Class 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 Annotation getAnnotation(Class 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 });
} finally {
fJProject1.setOptions(options);
}
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class TypeMismatchQuickFixTests method testMismatchingExceptionsOnGeneric.
@Test
public void testMismatchingExceptionsOnGeneric() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface IBase<T> {\n");
buf.append(" T[] getValues();\n");
buf.append("}\n");
pack1.createCompilationUnit("IBase.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.io.IOException;\n");
buf.append("public class E implements IBase<String> {\n");
buf.append(" public String[] getValues() throws IOException {\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("\n");
buf.append("import java.io.IOException;\n");
buf.append("\n");
buf.append("public interface IBase<T> {\n");
buf.append(" T[] getValues() throws IOException;\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.IOException;\n");
buf.append("public class E implements IBase<String> {\n");
buf.append(" public String[] getValues() {\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 testTypeMismatchInAssignment3.
@Test
public void testTypeMismatchInAssignment3() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.Iterator;\n");
buf.append("public enum E {\n");
buf.append(" A, B;\n");
buf.append(" String str, str2;\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" str2= iter.next();\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.util.Iterator;\n");
buf.append("public enum E {\n");
buf.append(" A, B;\n");
buf.append(" String str, str2;\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" str2= (String) iter.next();\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.Iterator;\n");
buf.append("public enum E {\n");
buf.append(" A, B;\n");
buf.append(" String str;\n");
buf.append(" Object str2;\n");
buf.append(" public void foo(Iterator iter) {\n");
buf.append(" str2= iter.next();\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
Aggregations