use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class AssistQuickFixTest18 method testAssignParamToField2.
@Test
public void testAssignParamToField2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface I {\n");
buf.append(" static void bar(int x) {\n");
buf.append(" System.out.println(x);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("I.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("x");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 0);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class AssistQuickFixTest18 method testAssignParamToField1.
@Test
public void testAssignParamToField1() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface I {\n");
buf.append(" default void foo(int x) {\n");
buf.append(" System.out.println(x);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("I.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("x");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 0);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToLambda15.
@Test
public void testConvertToLambda15() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("@FunctionalInterface\n");
buf.append("interface FI {\n");
buf.append(" int foo(int x, int y, int z);\n");
buf.append("}\n");
buf.append("\n");
buf.append("class C {\n");
buf.append(" int i;\n");
buf.append(" private void test(int x, int y, int z) {\n");
buf.append(" FI fi = new FI() {\n");
buf.append(" @Override\n");
buf.append(" public int foo(int a, int b, int z) {\n");
buf.append(" int x= 0, y=0; \n");
buf.append(" return x + y + z;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.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("@FunctionalInterface\n");
buf.append("interface FI {\n");
buf.append(" int foo(int x, int y, int z);\n");
buf.append("}\n");
buf.append("\n");
buf.append("class C {\n");
buf.append(" int i;\n");
buf.append(" private void test(int x, int y, int z) {\n");
buf.append(" FI fi = (a, b, z1) -> {\n");
buf.append(" int x1= 0, y1=0; \n");
buf.append(" return x1 + y1 + z1;\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class AssistQuickFixTest18 method testChangeLambdaBodyToExpression7.
@Test
public void testChangeLambdaBodyToExpression7() 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 fi2c = x -> {\n");
buf.append(" return;\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);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_change_lambda_body_to_expression);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class AssistQuickFixTest18 method testBug433754.
@Test
public void testBug433754() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("class E {\n");
buf.append(" private void foo() {\n");
buf.append(" for (String str : new String[1]) {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("str");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("class E {\n");
buf.append(" private void foo() {\n");
buf.append(" String[] strings = new String[1];\n");
buf.append(" for (int i = 0; i < strings.length; i++) {\n");
buf.append(" String str = strings[i];\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Aggregations