use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToLambda16.
@Test
public void testConvertToLambda16() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface FI {\n");
buf.append(" void foo();\n");
buf.append("}\n");
buf.append("\n");
buf.append("class C1 {\n");
buf.append(" void fun1() {\n");
buf.append(" int c = 0; // [1]\n");
buf.append(" FI test = new FI() {\n");
buf.append(" @Override\n");
buf.append(" public void foo() {\n");
buf.append(" for (int c = 0; c < 10;) { /* [2] */ }\n");
buf.append(" for (int c = 0; c < 20;) { /* [3] */ }\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C1.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("FI()");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface FI {\n");
buf.append(" void foo();\n");
buf.append("}\n");
buf.append("\n");
buf.append("class C1 {\n");
buf.append(" void fun1() {\n");
buf.append(" int c = 0; // [1]\n");
buf.append(" FI test = () -> {\n");
buf.append(" for (int c1 = 0; c1 < 10;) { /* [2] */ }\n");
buf.append(" for (int c2 = 0; c2 < 20;) { /* [3] */ }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest18 method testChangeLambdaBodyToExpression5.
@Test
public void testChangeLambdaBodyToExpression5() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI2 fi2= x -> {\n");
buf.append(" --x;\n");
buf.append(" };\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI2 {\n");
buf.append(" void foo(int x);\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("->");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI2 fi2= x -> --x;\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI2 {\n");
buf.append(" void foo(int x);\n");
buf.append("}\n");
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToLambda10.
@Test
public void testConvertToLambda10() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface I {\n");
buf.append(" int foo(String s);\n");
buf.append("}\n");
buf.append("\n");
buf.append("interface J {\n");
buf.append(" Integer foo(String s);\n");
buf.append("}\n");
buf.append("\n");
buf.append("public class X {\n");
buf.append(" static void goo(I i) { }\n");
buf.append("\n");
buf.append(" static void goo(J j) { }\n");
buf.append("\n");
buf.append(" public static void main(String[] args) {\n");
buf.append(" goo(new I() {\n");
buf.append(" @Override\n");
buf.append(" public int foo(String s) {\n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append(" });\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("X.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("I()");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface I {\n");
buf.append(" int foo(String s);\n");
buf.append("}\n");
buf.append("\n");
buf.append("interface J {\n");
buf.append(" Integer foo(String s);\n");
buf.append("}\n");
buf.append("\n");
buf.append("public class X {\n");
buf.append(" static void goo(I i) { }\n");
buf.append("\n");
buf.append(" static void goo(J j) { }\n");
buf.append("\n");
buf.append(" public static void main(String[] args) {\n");
buf.append(" goo((I) s -> 0);\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest18 method testChangeLambdaBodyToBlock1.
@Test
public void testChangeLambdaBodyToBlock1() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI1 fi1a= x -> -1;\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI1 {\n");
buf.append(" int foo(int x);\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("->");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI1 fi1a= x -> {\n");
buf.append(" return -1;\n");
buf.append(" };\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI1 {\n");
buf.append(" int foo(int x);\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest18 method testChangeLambdaBodyToExpression3.
@Test
public void testChangeLambdaBodyToExpression3() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI2 fi2= x -> { m1(); };\n");
buf.append(" int m1(){ return 0; }\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI2 {\n");
buf.append(" void foo(int x);\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("->");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class E {\n");
buf.append(" FI2 fi2= x -> m1();\n");
buf.append(" int m1(){ return 0; }\n");
buf.append("}\n");
buf.append("\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI2 {\n");
buf.append(" void foo(int x);\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Aggregations