use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest18 method _testConvertToAnonymousClassCreation7.
@Test
@Ignore
public // Bug 427694: [1.8][compiler] Functional interface not identified correctly
void _testConvertToAnonymousClassCreation7() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface I { Object m(Class c); }\n");
buf.append("interface J<S> { S m(Class<?> c); }\n");
buf.append("interface K<T> { T m(Class<?> c); }\n");
buf.append("interface Functional<S,T> extends I, J<S>, K<T> {}\n");
buf.append("\n");
buf.append("class C {\n");
buf.append(" Functional<?, ?> fun= (c) -> { return null;};\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.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("interface I { Object m(Class c); }\n");
buf.append("interface J<S> { S m(Class<?> c); }\n");
buf.append("interface K<T> { T m(Class<?> c); }\n");
buf.append("interface Functional<S,T> extends I, J<S>, K<T> {}\n");
buf.append("\n");
buf.append("class C {\n");
buf.append(" Functional<?, ?> fun= new Functional<Object, Object>() {\n");
buf.append(" @Override\n");
buf.append(" public Object m(Class c) {\n");
buf.append(" return null;\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.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToLambda12.
@Test
public void testConvertToLambda12() 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 extends Y {\n");
buf.append(" static void goo(I i) { }\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");
buf.append("\n");
buf.append("class Y {\n");
buf.append(" static void goo(J j) { } \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 extends Y {\n");
buf.append(" static void goo(I i) { }\n");
buf.append(" public static void main(String[] args) {\n");
buf.append(" goo((I) s -> 0);\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
buf.append("class Y {\n");
buf.append(" static void goo(J j) { } \n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToLambda7.
@Test
public void testConvertToLambda7() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("abstract class C {\n");
buf.append(" abstract void method();\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void bar(C c) {\n");
buf.append(" }\n");
buf.append(" void foo() {\n");
buf.append(" bar(new C() {\n");
buf.append(" public void method() {\n");
buf.append(" System.out.println();\n");
buf.append(" }\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("C()");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 1);
assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression);
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest18 method testConvertToAnonymousClassCreation3.
@Test
public void testConvertToAnonymousClassCreation3() 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(" void method();\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void bar(I i) {\n");
buf.append(" }\n");
buf.append(" void foo() {\n");
buf.append(" bar(() -> System.out.println());\n");
buf.append(" }\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, 5);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface I {\n");
buf.append(" void method();\n");
buf.append("}\n");
buf.append("public class E {\n");
buf.append(" void bar(I i) {\n");
buf.append(" }\n");
buf.append(" void foo() {\n");
buf.append(" bar(new I() {\n");
buf.append(" @Override\n");
buf.append(" public void method() {\n");
buf.append(" System.out.println();\n");
buf.append(" }\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.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest method testReplaceCatchClauseWithThrowsWithFinally.
@Test
public void testReplaceCatchClauseWithThrowsWithFinally() 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 E {\n");
buf.append(" public void foo() {\n");
buf.append(" try {\n");
buf.append(" goo();\n");
buf.append(" } catch (IOException e) {\n");
buf.append(" } finally {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "(IOException e)";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
List proposals = collectAssists(context, false);
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("public class E {\n");
buf.append(" public void foo() throws IOException {\n");
buf.append(" try {\n");
buf.append(" goo();\n");
buf.append(" } finally {\n");
buf.append(" }\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.IOException;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" try {\n");
buf.append(" goo();\n");
buf.append(" } finally {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
Aggregations