Search in sources :

Example 26 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ConvertForLoopQuickFixTest method testArrayIsAccessedByMethodInvocation.

@Test
public void testArrayIsAccessedByMethodInvocation() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("class Weirdy{}\n");
    buf.append("public class A {\n");
    buf.append("	private Weirdy[] weirdies;\n");
    buf.append("	private Weirdy[] getArray(){\n");
    buf.append("		return weirdies;\n");
    buf.append("	}\n");
    buf.append("    public void foo(){\n");
    buf.append("		for (int i = 0, length = this.weirdies.length; i < length; i++){\n");
    buf.append("			System.out.println();\n");
    buf.append("		    Weirdy p = getArray()[i];\n");
    buf.append("		    if (p != null){\n");
    buf.append("				System.out.println(p);\n");
    buf.append("	    	}\n");
    buf.append("	    }\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
    List proposals = fetchConvertingProposal(buf, cu);
    assertNull(fConvertLoopProposal);
    assertCorrectLabels(proposals);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) List(java.util.List) Test(org.junit.Test)

Example 27 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment 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 });
}
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 28 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment 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 });
}
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 29 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment 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 30 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment 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)

Aggregations

IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1638 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1456 Test (org.junit.Test)1439 ArrayList (java.util.ArrayList)767 List (java.util.List)454 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)436 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)384 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)284 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)165 Hashtable (java.util.Hashtable)136 IJavaElement (org.eclipse.jdt.core.IJavaElement)72 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 IJavaProject (org.eclipse.jdt.core.IJavaProject)59 Ignore (org.junit.Ignore)56 IType (org.eclipse.jdt.core.IType)55 JavaModelException (org.eclipse.jdt.core.JavaModelException)38 IResource (org.eclipse.core.resources.IResource)34 IFile (org.eclipse.core.resources.IFile)33 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33