Search in sources :

Example 26 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project erlide_eclipse by erlang.

the class AbstractErlContentAssistProcessor method toProposal.

protected ICompletionProposal toProposal(final CompletionData data) {
    if (data instanceof FunctionCompletionData) {
        final FunctionCompletionData fdata = (FunctionCompletionData) data;
        final String info = fdata.getAdditionalProposalInfo();
        final StringBuffer buffer = new StringBuffer(info == null ? "" : info);
        return new ErlCompletionProposal(fdata.getOffsetsAndLengths(), fdata.getDisplayString(), fdata.getReplacementString(), fdata.getReplacementOffset(), fdata.getReplacementLength(), fdata.getCursorPosition(), null, null, HoverUtil.getHTML(buffer), sourceViewer);
    }
    return new CompletionProposal(data.getReplacementString(), data.getReplacementOffset(), data.getReplacementLength(), data.getCursorPosition());
}
Also used : FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 27 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project eclipse.platform.text by eclipse.

the class JavaCompletionProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
    for (int i = 0; i < fgProposals.length; i++) {
        // $NON-NLS-1$
        IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] }));
        // $NON-NLS-1$
        result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] }));
    }
    return result;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation)

Example 28 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project eclipse.platform.text by eclipse.

the class NaturesAndProjectsContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    String text = viewer.getDocument().get();
    String natureTag = "<nature>";
    String projectReferenceTag = "<project>";
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    int natureTagLength = natureTag.length();
    if (text.length() >= natureTagLength && offset >= natureTagLength && text.substring(offset - natureTagLength, offset).equals(natureTag)) {
        IProjectNatureDescriptor[] natureDescriptors = workspace.getNatureDescriptors();
        ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
        for (int i = 0; i < natureDescriptors.length; i++) {
            IProjectNatureDescriptor descriptor = natureDescriptors[i];
            proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length());
        }
        return proposals;
    }
    int projectReferenceTagLength = projectReferenceTag.length();
    if (text.length() >= projectReferenceTagLength && offset >= projectReferenceTagLength && text.substring(offset - projectReferenceTagLength, offset).equals(projectReferenceTag)) {
        IProject[] projects = workspace.getRoot().getProjects();
        // TODO - filter out the project this file is in
        ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
        for (int i = 0; i < projects.length; i++) {
            proposals[i] = new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
        }
        return proposals;
    }
    return new ICompletionProposal[0];
}
Also used : IProjectNatureDescriptor(org.eclipse.core.resources.IProjectNatureDescriptor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) IWorkspace(org.eclipse.core.resources.IWorkspace) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IProject(org.eclipse.core.resources.IProject)

Example 29 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project linuxtools by eclipse.

the class STPCompletionProcessor method getGlobalKeywordCompletion.

private ICompletionProposal[] getGlobalKeywordCompletion(String prefix, int offset) {
    ArrayList<ICompletionProposal> completions = new ArrayList<>();
    int prefixLength = prefix.length();
    for (String[] keyword : GLOBAL_KEYWORDS) {
        if (keyword[0].startsWith(prefix)) {
            CompletionProposal proposal = new CompletionProposal(keyword[0].substring(prefixLength), offset, 0, keyword[0].length() - prefixLength, null, keyword[0], // $NON-NLS-1$ //$NON-NLS-2$
            new ContextInformation("contextDisplayString", "informationDisplayString"), keyword[1]);
            completions.add(proposal);
        }
    }
    return completions.toArray(new ICompletionProposal[0]);
}
Also used : STPFunctionCompletionProposal(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPFunctionCompletionProposal) STPProbeCompletionProposal(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPProbeCompletionProposal) STPProbevarCompletionProposal(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.proposals.STPProbevarCompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList)

Example 30 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project webtools.sourceediting by eclipse.

the class MarkupQuickAssistProcessor method computeQuickAssistProposals.

public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ArrayList proposals = new ArrayList();
    switch(fProblemId) {
        case ProblemIDsXML.EmptyTag:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_0, null, ""));
            break;
        case ProblemIDsXML.MissingEndTag:
            String tagName = (String) ((Object[]) fAdditionalFixInfo)[0];
            String tagClose = (String) ((Object[]) fAdditionalFixInfo)[1];
            int tagCloseOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[2]).intValue();
            int startTagEndOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[3]).intValue();
            int firstChildStartOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[4]).intValue();
            int endOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[5]).intValue();
            // $NON-NLS-1$
            proposals.add(new CompletionProposal(tagClose, tagCloseOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_1, null, ""));
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), startTagEndOffset - invocationContext.getOffset(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_2, null, ""));
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            proposals.add(new CompletionProposal("</" + tagName + ">", firstChildStartOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_3, null, ""));
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            proposals.add(new CompletionProposal("</" + tagName + ">", endOffset, 0, 0, getImage(), XMLUIMessages.QuickFixProcessorXML_4, null, ""));
            break;
        case ProblemIDsXML.AttrsInEndTag:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_5, null, ""));
            break;
        case ProblemIDsXML.MissingAttrValue:
            String defaultAttrValue = (String) ((Object[]) fAdditionalFixInfo)[0];
            int insertOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            proposals.add(new CompletionProposal("\"" + defaultAttrValue + "\"", invocationContext.getOffset() + invocationContext.getLength() + insertOffset, 0, defaultAttrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, ""));
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
            break;
        case ProblemIDsXML.NoAttrValue:
            defaultAttrValue = (String) fAdditionalFixInfo;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            proposals.add(new CompletionProposal("=\"" + defaultAttrValue + "\"", invocationContext.getOffset() + invocationContext.getLength(), 0, defaultAttrValue.length() + 3, getImage(), XMLUIMessages.QuickFixProcessorXML_6, null, ""));
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
            break;
        case ProblemIDsXML.SpacesBeforeTagName:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_8, null, ""));
            break;
        case ProblemIDsXML.SpacesBeforePI:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_9, null, ""));
            break;
        case ProblemIDsXML.NamespaceInPI:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_10, null, ""));
            break;
        case ProblemIDsXML.UnknownElement:
            proposals.add(new RemoveUnknownElementQuickFixProposal(fAdditionalFixInfo, getImage(), XMLUIMessages.QuickFixProcessorXML_11));
            proposals.add(new RenameInFileQuickAssistProposal());
            break;
        case ProblemIDsXML.UnknownAttr:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_7, null, ""));
            proposals.add(new RenameInFileQuickAssistProposal());
            break;
        case ProblemIDsXML.InvalidAttrValue:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal("", invocationContext.getOffset(), invocationContext.getLength(), 0, getImage(), XMLUIMessages.QuickFixProcessorXML_12, null, ""));
            break;
        case ProblemIDsXML.MissingRequiredAttr:
            String requiredAttr = (String) ((Object[]) fAdditionalFixInfo)[0];
            insertOffset = ((Integer) ((Object[]) fAdditionalFixInfo)[1]).intValue();
            // $NON-NLS-1$
            proposals.add(new CompletionProposal(requiredAttr, invocationContext.getOffset() + insertOffset, 0, requiredAttr.length(), getImage(), XMLUIMessages.QuickFixProcessorXML_13, null, ""));
            break;
        case ProblemIDsXML.AttrValueNotQuoted:
            String attrValue = (String) fAdditionalFixInfo;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            proposals.add(new CompletionProposal("\"" + attrValue + "\"", invocationContext.getOffset(), invocationContext.getLength(), attrValue.length() + 2, getImage(), XMLUIMessages.QuickFixProcessorXML_14, null, ""));
            break;
        case ProblemIDsXML.MissingClosingBracket:
            // $NON-NLS-1$ //$NON-NLS-2$
            proposals.add(new CompletionProposal(">", invocationContext.getOffset() + invocationContext.getLength(), 0, 1, getImage(), XMLUIMessages.QuickFixProcessorXML_15, null, ""));
            break;
    }
    return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : RenameInFileQuickAssistProposal(org.eclipse.wst.xml.ui.internal.correction.RenameInFileQuickAssistProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) RemoveUnknownElementQuickFixProposal(org.eclipse.wst.xml.ui.internal.correction.RemoveUnknownElementQuickFixProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList)

Aggregations

CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)41 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)39 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)8 List (java.util.List)8 BadLocationException (org.eclipse.jface.text.BadLocationException)6 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IType (org.eclipse.jdt.core.IType)3 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)3 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)3 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)3 Image (org.eclipse.swt.graphics.Image)3 Point (org.eclipse.swt.graphics.Point)3 KindedName (abs.frontend.typechecker.KindedName)2 ResolvedName (abs.frontend.typechecker.ResolvedName)2 Map (java.util.Map)2