Search in sources :

Example 96 with ICompilationUnit

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

the class AssistQuickFixTest method testConvertToStringBufferNoFixWithoutString.

@Test
public void testConvertToStringBufferNoFixWithoutString() 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 strX = 5+1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
    List proposals = collectAssists(context, false);
    assertNumberOfProposals(proposals, 3);
    assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("        int strX;\n");
    buf.append("        strX = 5+1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected2 = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class A {\n");
    buf.append("    private int strX;\n");
    buf.append("\n");
    buf.append("    public void foo() {\n");
    buf.append("        strX = 5+1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected3 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 97 with ICompilationUnit

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

the class AssistQuickFixTest method testInvertEquals13.

@Test
public void testInvertEquals13() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    boolean equals(boolean b) {\n");
    buf.append("        return false;\n");
    buf.append("    }\n");
    buf.append("    public void foo() {\n");
    buf.append("        new E().equals(true ? true : false);\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    String str = "E().equals";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
    List proposals = collectAssists(context, FILTER_EQ);
    assertNumberOfProposals(proposals, 0);
    assertCorrectLabels(proposals);
    context = getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0);
    proposals = collectAssists(context, FILTER_EQ);
    assertNumberOfProposals(proposals, 0);
    assertCorrectLabels(proposals);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) AssistContext(org.eclipse.jdt.internal.ui.text.correction.AssistContext) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 98 with ICompilationUnit

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

the class ConvertForLoopQuickFixTest method testCollectionsNotAcceptedYet.

@Test
public void testCollectionsNotAcceptedYet() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.util.List;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("public class A {\n");
    buf.append("    public void foo() {\n");
    buf.append("		List strings= new ArrayList();\n");
    buf.append("		for (int i= 0; i < strings.size(); i++);\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 99 with ICompilationUnit

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

the class ConvertForLoopQuickFixTest method testBodyPrecondition03.

@Test
public void testBodyPrecondition03() 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("    Object[] x;\n");
    buf.append("    public void foo() {\n");
    buf.append("        for (int i = 0; i < x.length; i++) {\n");
    buf.append("            System.out.println(this.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 100 with ICompilationUnit

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

the class ConvertForLoopQuickFixTest method testTwoIndexesNotAllowed.

@Test
public void testTwoIndexesNotAllowed() 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, j = 0; i < array.length; i++, j++){\n");
    buf.append("			System.out.println(array[i] + j);\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

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1356 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1049 Test (org.junit.Test)1046 ArrayList (java.util.ArrayList)799 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)503 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)97 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)78 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)44 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