Search in sources :

Example 51 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testSimplestClean.

@Test
public void testSimplestClean() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("		String[] array = {\"1\",\"2\"};\n");
    buf.append("		for (int i = 0; i < array.length; i++){\n");
    buf.append("			System.out.println(array[i]);\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("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("		String[] array = {\"1\",\"2\"};\n");
    buf.append("		for (String element : array) {\n");
    buf.append("			System.out.println(element);\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 52 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testBug148419.

@Test
public void testBug148419() 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("    private int[] ints;\n");
    buf.append("    public void foo() {\n");
    buf.append("        for (int i = 0; i < this.ints.length; i++) {\n");
    buf.append("            this.ints[i]= 0;\n");
    buf.append("        }\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 53 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testBug214340_2.

@Test
public void testBug214340_2() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E1 {\n");
    buf.append("    int[] array = new int[3];\n");
    buf.append("    static boolean same(E1 one, E1 two) {\n");
    buf.append("        for (int i = 0; i < one.array.length; i++) {\n");
    buf.append("            if (one.array[i] != two.array[i])\n");
    buf.append("                return false;\n");
    buf.append("        }\n");
    buf.append("        return true;\n");
    buf.append("    }\n");
    buf.append("}\n");
    buf.append("\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E1.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)

Example 54 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testIndexReadOutsideArrayAccess.

@Test
public void testIndexReadOutsideArrayAccess() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("		int[] array = {1,2,3,4};\n");
    buf.append("		for (int i = 0; i < array.length; i++){\n");
    buf.append("			if (i == 1){};\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 55 with IPackageFragment

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

the class ConvertForLoopQuickFixTest method testCollectionIsNotArray.

@Test
public void testCollectionIsNotArray() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("		java.util.List list = new ArrayList();\n");
    buf.append("		list.add(null);\n");
    buf.append("		for (int i = 0; i < list.size(); i++){\n");
    buf.append("			System.out.println(list.get(i);\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)

Aggregations

IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1147 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1052 Test (org.junit.Test)1039 ArrayList (java.util.ArrayList)755 List (java.util.List)453 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)435 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)384 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)284 Hashtable (java.util.Hashtable)136 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)100 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 Ignore (org.junit.Ignore)43 IType (org.eclipse.jdt.core.IType)37 IJavaElement (org.eclipse.jdt.core.IJavaElement)32 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)24 HashMap (java.util.HashMap)23 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)23 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 Map (java.util.Map)19