Search in sources :

Example 41 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest method testAssignParamToField.

@Test
public void testAssignParamToField() 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("    public  E(int count) {\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    String selection = "count";
    int offset = buf.toString().indexOf(selection);
    AssistContext context = getCorrectionContext(cu, offset, selection.length());
    List proposals = collectAssists(context, false);
    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    private int count;\n");
    buf.append("\n");
    buf.append("    public  E(int count) {\n");
    buf.append("        this.count = count;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String ex1 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { ex1 });
}
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 42 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AssistQuickFixTest method testChangeIfAndElseStatementToBlock2.

@Test
public void testChangeIfAndElseStatementToBlock2() 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("    public void foo() {\n");
    buf.append("        if (true)\n");
    buf.append("            ;\n");
    buf.append("        else\n");
    buf.append("            ;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    String str = "else";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
    List proposals = collectAssists(context, false);
    assertNumberOfProposals(proposals, 3);
    assertCorrectLabels(proposals);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        if (true)\n");
    buf.append("            ;\n");
    buf.append("        else {\n");
    buf.append("            ;\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        if (true) {\n");
    buf.append("            ;\n");
    buf.append("        } else {\n");
    buf.append("            ;\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected2 = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        if (false)\n");
    buf.append("            ;\n");
    buf.append("        else\n");
    buf.append("            ;\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 43 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext 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 44 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext 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 45 with AssistContext

use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.

the class AdvancedQuickAssistTest method testExchangeOperands7.

@Test
public void testExchangeOperands7() 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("    public boolean foo(int a, int b) {\n");
    buf.append("        return (a >= b);\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    int offset = buf.toString().indexOf(">=");
    AssistContext context = getCorrectionContext(cu, offset, 0);
    assertNoErrors(context);
    List proposals = collectAssists(context, false);
    assertCorrectLabels(proposals);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public boolean foo(int a, int b) {\n");
    buf.append("        return (b <= a);\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected1 = buf.toString();
    assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
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)

Aggregations

AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)390 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)385 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)384 Test (org.junit.Test)384 List (java.util.List)378 ArrayList (java.util.ArrayList)313 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)57 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)8 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 Ignore (org.junit.Ignore)4 IDocument (org.eclipse.jface.text.IDocument)3 Iterator (java.util.Iterator)2 IBuffer (org.eclipse.jdt.core.IBuffer)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Point (org.eclipse.swt.graphics.Point)2 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)1 LinkedModeModelImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl)1