Search in sources :

Example 21 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testExpressionPrecondition07.

@Test
public void testExpressionPrecondition07() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo(Object[] x) {\n");
    buf.append("        for (int i = 0, length= x.length; i < length; i++) {}\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    assertTrue(satisfiesPrecondition(cu));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Test(org.junit.Test)

Example 22 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testBug130139_2.

@Test
public void testBug130139_2() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo(String[] strings) {\n");
    buf.append("        for (int i= x(); i < strings.length; i++) {\n");
    buf.append("            System.out.println(strings[i]);\n");
    buf.append("        }  \n");
    buf.append("    }\n");
    buf.append("    private int x(){\n");
    buf.append("        return 0;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.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 23 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testBodyPrecondition344674_3.

@Test
public void testBodyPrecondition344674_3() throws Exception {
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=344674
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    Object[] x;\n");
    buf.append("    public void foo(Object obj) {\n");
    buf.append("        for (int i = 0; i < ((E) obj).x.length; i++) {\n");
    buf.append("            System.out.println(((E) obj).x[i]);\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    assertTrue(satisfiesPrecondition(cu));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Test(org.junit.Test)

Example 24 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testNiceReduction.

@Test
public void testNiceReduction() 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("private Weirdy[] weirdies;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo(){\n");
    buf.append("		for (int i = 0, length = weirdies.length; i < length; i++){\n");
    buf.append("			System.out.println();\n");
    buf.append("		    Weirdy p = weirdies[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);
    assertNotNull(fConvertLoopProposal);
    assertCorrectLabels(proposals);
    String preview1 = getPreviewContent(fConvertLoopProposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("class Weirdy{}\n");
    buf.append("private Weirdy[] weirdies;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo(){\n");
    buf.append("		for (Weirdy p : weirdies) {\n");
    buf.append("			System.out.println();\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");
    String expected = buf.toString();
    assertEqualString(preview1, expected);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) List(java.util.List) Test(org.junit.Test)

Example 25 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testBodyPrecondition09.

@Test
public void testBodyPrecondition09() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo(Object[] x) {\n");
    buf.append("        for (int i = 0; i < x.length; i++) {\n");
    buf.append("            x[i]= null;\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    assertFalse(satisfiesPrecondition(cu));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) 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