Search in sources :

Example 61 with ICompilationUnit

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

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

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

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

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

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