Search in sources :

Example 16 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest18 method testConvertToAnonymousClassCreation5.

@Test
public void testConvertToAnonymousClassCreation5() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("interface FX {\n");
    buf.append("    default int defaultMethod(String x) {\n");
    buf.append("        return -1;\n");
    buf.append("    }\n");
    buf.append("\n");
    buf.append("    int foo(int x);\n");
    buf.append("}\n");
    buf.append("\n");
    buf.append("class TestX {\n");
    buf.append("    FX fxx = x -> {\n");
    buf.append("        return (new FX() {\n");
    buf.append("            @Override\n");
    buf.append("            public int foo(int x) {\n");
    buf.append("                return 0;\n");
    buf.append("            }\n");
    buf.append("        }).defaultMethod(\"a\");\n");
    buf.append("    };\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("TestX.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 FX {\n");
    buf.append("    default int defaultMethod(String x) {\n");
    buf.append("        return -1;\n");
    buf.append("    }\n");
    buf.append("\n");
    buf.append("    int foo(int x);\n");
    buf.append("}\n");
    buf.append("\n");
    buf.append("class TestX {\n");
    buf.append("    FX fxx = new FX() {\n");
    buf.append("        @Override\n");
    buf.append("        public int foo(int x) {\n");
    buf.append("            return (new FX() {\n");
    buf.append("                @Override\n");
    buf.append("                public int foo(int x) {\n");
    buf.append("                    return 0;\n");
    buf.append("                }\n");
    buf.append("            }).defaultMethod(\"a\");\n");
    buf.append("        }\n");
    buf.append("    };\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) List(java.util.List) Test(org.junit.Test)

Example 17 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest18 method testConvertToLambda6.

@Test
public void testConvertToLambda6() 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("    boolean equals(Object obj);\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("            public boolean equals(Object obj) {\n");
    buf.append("                return false;\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("I()");
    AssistContext context = getCorrectionContext(cu, offset, 0);
    assertNoErrors(context);
    List proposals = collectAssists(context, false);
    assertNumberOfProposals(proposals, 1);
    assertProposalDoesNotExist(proposals, FixMessages.LambdaExpressionsFix_convert_to_lambda_expression);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) List(java.util.List) Test(org.junit.Test)

Example 18 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest18 method testChangeLambdaBodyToExpression1.

@Test
public void testChangeLambdaBodyToExpression1() 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 fi1= x -> {\n");
    buf.append("        return x=0;\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");
    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 fi1= x -> x=0;\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 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) List(java.util.List) Test(org.junit.Test)

Example 19 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest18 method testChangeLambdaBodyToExpression6.

@Test
public void testChangeLambdaBodyToExpression6() 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 fi2z= 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");
    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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) List(java.util.List) Test(org.junit.Test)

Example 20 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest18 method testChangeLambdaBodyToBlock2.

@Test
public void testChangeLambdaBodyToBlock2() 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 fi1b= x -> m1();\n");
    buf.append("    int m1(){ return 0; }\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 fi1b= x -> {\n");
    buf.append("        return m1();\n");
    buf.append("    };\n");
    buf.append("    int m1(){ return 0; }\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 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) List(java.util.List) Test(org.junit.Test)

Aggregations

AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)390 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)385 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)384 Test (org.junit.Test)384 List (java.util.List)378 ArrayList (java.util.ArrayList)313 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)57 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)8 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 Ignore (org.junit.Ignore)4 IDocument (org.eclipse.jface.text.IDocument)3 Iterator (java.util.Iterator)2 IBuffer (org.eclipse.jdt.core.IBuffer)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Point (org.eclipse.swt.graphics.Point)2 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)1 LinkedModeModelImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl)1