Search in sources :

Example 91 with ICompilationUnit

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

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

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

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

Example 95 with ICompilationUnit

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

the class ConvertForLoopQuickFixTest method testBug214340_3.

@Test
public void testBug214340_3() 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("            System.out.println(one.array[i]);\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);
    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 E1 {\n");
    buf.append("    int[] array = new int[3];\n");
    buf.append("    static boolean same(E1 one, E1 two) {\n");
    buf.append("        for (int element : one.array) {\n");
    buf.append("            System.out.println(element);\n");
    buf.append("        }\n");
    buf.append("        return true;\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)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1368 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1050 Test (org.junit.Test)1046 ArrayList (java.util.ArrayList)799 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)505 List (java.util.List)466 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)385 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)284 Hashtable (java.util.Hashtable)142 IType (org.eclipse.jdt.core.IType)98 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)79 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)70 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)70 ASTNode (org.eclipse.jdt.core.dom.ASTNode)69 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)51 IJavaElement (org.eclipse.jdt.core.IJavaElement)47 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)44 Image (org.eclipse.swt.graphics.Image)41 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)38 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)38