Search in sources :

Example 1 with ICompletionProposal

use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.

the class CodeAssist method convertProposals.

private Proposals convertProposals(int offset, ICompilationUnit compilationUnit, TextViewer viewer, List<ICompletionProposal> proposals) {
    Proposals result = DtoFactory.getInstance().createDto(Proposals.class);
    String sessionId = UUID.randomUUID().toString();
    result.setSessionId(sessionId);
    ArrayList<ProposalPresentation> presentations = new ArrayList<>();
    for (int i = 0; i < proposals.size(); i++) {
        ProposalPresentation presentation = DtoFactory.getInstance().createDto(ProposalPresentation.class);
        ICompletionProposal proposal = proposals.get(i);
        presentation.setIndex(i);
        presentation.setDisplayString(proposal.getDisplayString());
        String image = proposal.getImage() == null ? null : proposal.getImage().getImg();
        presentation.setImage(image);
        if (proposal instanceof ICompletionProposalExtension4) {
            presentation.setAutoInsertable(((ICompletionProposalExtension4) proposal).isAutoInsertable());
        }
        if (proposal instanceof CheActionAcces) {
            String actionId = ((CheActionAcces) proposal).getActionId();
            if (actionId != null) {
                presentation.setActionId(actionId);
            }
        }
        presentations.add(presentation);
    }
    result.setProposals(presentations);
    cache.put(sessionId, new CodeAssistContext(viewer, offset, proposals, compilationUnit));
    return result;
}
Also used : CheActionAcces(org.eclipse.che.jdt.ui.CheActionAcces) ProposalPresentation(org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) Proposals(org.eclipse.che.ide.ext.java.shared.dto.Proposals) ICompletionProposalExtension4(org.eclipse.che.jface.text.contentassist.ICompletionProposalExtension4) Point(org.eclipse.swt.graphics.Point)

Example 2 with ICompletionProposal

use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.

the class QuickFixTest method assertNumberOfProposals.

protected static void assertNumberOfProposals(List proposals, int expectedProposals) {
    if (proposals.size() != expectedProposals) {
        StringBuffer buf = new StringBuffer();
        buf.append("Wrong number of proposals, is: ").append(proposals.size()).append(", expected: ").append(expectedProposals).append('\n');
        for (int i = 0; i < proposals.size(); i++) {
            ICompletionProposal curr = (ICompletionProposal) proposals.get(i);
            buf.append(" - ").append(curr.getDisplayString()).append('\n');
            if (curr instanceof CUCorrectionProposal) {
                appendSource(((CUCorrectionProposal) curr), buf);
            }
        }
        assertTrue(buf.toString(), false);
    }
}
Also used : CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal)

Example 3 with ICompletionProposal

use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.

the class QuickFixTest method assertCorrectLabels.

public static void assertCorrectLabels(List proposals) {
    for (int i = 0; i < proposals.size(); i++) {
        ICompletionProposal proposal = (ICompletionProposal) proposals.get(i);
        String name = proposal.getDisplayString();
        if (name == null || name.length() == 0 || name.charAt(0) == '!' || name.indexOf("{0}") != -1 || name.indexOf("{1}") != -1) {
            assertTrue("wrong proposal label: " + name, false);
        }
        if (proposal.getImage() == null) {
            assertTrue("wrong proposal image", false);
        }
    }
}
Also used : ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal)

Example 4 with ICompletionProposal

use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.

the class CompletionJavadocTest method computeProposals.

private static List<ICompletionProposal> computeProposals(ICompilationUnit compilationUnit, int offset) throws JavaModelException {
    IBuffer buffer = compilationUnit.getBuffer();
    IDocument document;
    if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
        document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
    } else {
        document = new DocumentAdapter(buffer);
    }
    TextViewer viewer = new TextViewer(document, new Point(offset, 0));
    JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(viewer, offset, compilationUnit);
    List<ICompletionProposal> proposals = new ArrayList<>();
    proposals.addAll(new JavaAllCompletionProposalComputer().computeCompletionProposals(context, null));
    //        proposals.addAll(new TemplateCompletionProposalComputer().computeCompletionProposals(context, null));
    Collections.sort(proposals, new RelevanceSorter());
    return proposals;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ArrayList(java.util.ArrayList) DocumentAdapter(org.eclipse.jdt.internal.core.DocumentAdapter) Point(org.eclipse.swt.graphics.Point) RelevanceSorter(org.eclipse.jdt.internal.ui.text.java.RelevanceSorter) IBuffer(org.eclipse.jdt.core.IBuffer) TextViewer(org.eclipse.che.jdt.javaeditor.TextViewer) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) JavaAllCompletionProposalComputer(org.eclipse.jdt.internal.ui.text.java.JavaAllCompletionProposalComputer) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with ICompletionProposal

use of org.eclipse.che.jface.text.contentassist.ICompletionProposal in project che by eclipse.

the class CompletionJavadocTest method testInheredJavadoc.

@Test
public void testInheredJavadoc() 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("    /**\n");
    buf.append("     * Test JavaDoc.\n");
    buf.append("     */\n");
    buf.append("    public void foo(int i) {\n");
    buf.append("    }\n");
    buf.append("}\n");
    pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    StringBuffer buf2 = new StringBuffer();
    buf2.append("package test1;\n");
    buf2.append("public class B extends E {\n");
    buf2.append("    @Override\n");
    buf2.append("    public void foo(int i) {\n");
    buf2.append("        foo(10);\n");
    buf2.append("    }\n");
    buf2.append("}\n");
    ICompilationUnit cu2 = pack1.createCompilationUnit("B.java", buf2.toString(), false, null);
    List<ICompletionProposal> proposals = computeProposals(cu2, buf2.indexOf("  foo") + "  foo".length());
    Assertions.assertThat(proposals).hasSize(1);
    ICompletionProposal proposal = proposals.get(0);
    String result;
    if (proposal instanceof ICompletionProposalExtension5) {
        result = ((ICompletionProposalExtension5) proposal).getAdditionalProposalInfo(null).toString();
    } else {
        result = proposal.getAdditionalProposalInfo();
    }
    Assertions.assertThat(result).contains("Test JavaDoc.");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) ICompletionProposalExtension5(org.eclipse.che.jface.text.contentassist.ICompletionProposalExtension5) QuickFixTest(org.eclipse.che.plugin.java.server.jdt.quickfix.QuickFixTest) Test(org.junit.Test)

Aggregations

ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)19 Point (org.eclipse.swt.graphics.Point)9 ArrayList (java.util.ArrayList)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)4 IDocument (org.eclipse.jface.text.IDocument)4 Position (org.eclipse.jface.text.Position)3 Test (org.junit.Test)3 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)2 ICompletionProposalExtension5 (org.eclipse.che.jface.text.contentassist.ICompletionProposalExtension5)2 LinkedDataImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl)2 LinkedModeModelImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl)2 LinkedPositionGroupImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedPositionGroupImpl)2 RegionImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.RegionImpl)2 QuickFixTest (org.eclipse.che.plugin.java.server.jdt.quickfix.QuickFixTest)2 IBuffer (org.eclipse.jdt.core.IBuffer)2 IType (org.eclipse.jdt.core.IType)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2