use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class ReorgQuickFixTest method testTodoTasks4.
@Test
public void testTodoTasks4() 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 void foo() {\n");
buf.append(" /**\n");
buf.append(" TODO: XXX\n");
buf.append(" */\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "TODO: XXX";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER);
ArrayList proposals = collectCorrections(context, problem);
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 {\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class ReorgQuickFixTest method testTodoTasks2.
@Test
public void testTodoTasks2() 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 void foo() {\n");
buf.append(" // Some other text TODO: XXX\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "TODO: XXX";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER);
ArrayList proposals = collectCorrections(context, problem);
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 {\n");
buf.append(" public void foo() {\n");
buf.append(" // Some other text \n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class ReorgQuickFixTest method testTodoTasks7.
@Test
public void testTodoTasks7() 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 void foo() {\n");
buf.append(" /* TODO: XXX*/;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "TODO: XXX";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER);
ArrayList proposals = collectCorrections(context, problem);
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 {\n");
buf.append(" public void foo() {\n");
buf.append(" ;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest method testSplitDeclaration3.
@Test
public void testSplitDeclaration3() 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 void foo() {\n");
buf.append(" final int i[] = null;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "i[]";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" final int i[];\n");
buf.append(" i = null;\n");
buf.append(" }\n");
buf.append("}\n");
String ex1 = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private int is[];\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" is = null;\n");
buf.append(" }\n");
buf.append("}\n");
String ex2 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest method testGenerateForImportsAndFormat1.
@Test
public void testGenerateForImportsAndFormat1() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append(" class Iterator {}\n");
buf.append(" void foo() {\n");
buf.append(" B.get( /*important: empty*/ );\n");
buf.append(" }\n");
buf.append("}\n");
StringBuffer buf2 = new StringBuffer();
buf2.append("package test1;\n");
buf2.append("import java.util.ArrayList;\n");
buf2.append("import java.util.Date;\n");
buf2.append("import java.util.Set;\n");
buf2.append("public class B {\n");
buf2.append(" static ArrayList<Date> get() {\n");
buf2.append(" return new ArrayList<Date>();\n");
buf2.append(" }\n");
buf2.append(" static Set raw(int i) {\n");
buf2.append(" return java.util.Collections.emptySet();\n");
buf2.append(" }\n");
buf2.append("}");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
pack1.createCompilationUnit("B.java", buf2.toString(), false, null);
Map saveOptions = fJProject1.getOptions(false);
Map newOptions = new HashMap();
JavaCore.setComplianceOptions(org.eclipse.jdt.core.JavaCore.VERSION_1_5, newOptions);
newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true");
try {
fJProject1.setOptions(newOptions);
String selection = "B.get( /*important: empty*/ );";
AssistContext context = getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 5);
assertCorrectLabels(proposals);
String[] expected = new String[3];
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("import java.util.Date;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" class Iterator {}\n");
buf.append(" void foo() {\n");
buf.append(" for (Date date : B.get( /*important: empty*/ )) {\n");
buf.append(" \n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("import java.util.Date;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" class Iterator {}\n");
buf.append(" void foo() {\n");
buf.append(" for (java.util.Iterator<Date> iterator = B.get( /*important: empty*/ ).iterator(); iterator\n");
buf.append(" .hasNext();) {\n");
buf.append(" Date date = iterator.next();\n");
buf.append(" \n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
expected[1] = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("import java.util.Date;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" class Iterator {}\n");
buf.append(" void foo() {\n");
buf.append(" for (int i = 0; i < B.get( /*important: empty*/ ).size(); i++) {\n");
buf.append(" Date date = B.get( /*important: empty*/ ).get(i);\n");
buf.append(" \n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
expected[2] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
} finally {
fJProject1.setOptions(saveOptions);
}
}
Aggregations