Search in sources :

Example 16 with ICompletionProposal

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

the class ProjectBuildPage method generateFixes.

// look for available quick-fixes from the bnd build error details
private void generateFixes(String message, final IMarker marker) {
    boolean fixable = marker.getAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, false);
    if (!fixable)
        return;
    ITextEditor sourcePage = editor.getSourcePage();
    if (sourcePage == null)
        return;
    String type = marker.getAttribute("$bndType", (String) null);
    if (type == null)
        return;
    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
    if (handler == null)
        return;
    List<IAction> fixes = new LinkedList<>();
    List<ICompletionProposal> proposals = handler.getProposals(marker);
    if (proposals != null) {
        for (ICompletionProposal proposal : proposals) {
            fixes.add(new ApplyCompletionProposalAction(proposal, editor.getSourcePage(), editor, BndEditor.SOURCE_PAGE));
        }
    }
    // If no source completion fixes were found, add the marker resolution actions.
    if (fixes.isEmpty()) {
        List<IMarkerResolution> resolutions = handler.getResolutions(marker);
        for (final IMarkerResolution resolution : resolutions) {
            Action action = new Action(resolution.getLabel()) {

                @Override
                public void run() {
                    resolution.run(marker);
                }
            };
            fixes.add(action);
        }
    }
    messageFixesMap.put(message, fixes.toArray(new IAction[0]));
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAction(org.eclipse.jface.action.IAction) LinkedList(java.util.LinkedList) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 17 with ICompletionProposal

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

the class BundleClassCompletionProposalComputer method computeCompletionProposals.

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        return Collections.emptyList();
    }
    try {
        int offset = context.getInvocationOffset();
        CharSequence prefix = context.computeIdentifierPrefix();
        result.add(new CompletionProposal("foobar", offset - prefix.length(), prefix.length(), offset - prefix.length() + 6));
        result.add(new CompletionProposal("fizzbuzz", offset - prefix.length(), prefix.length(), offset - prefix.length() + 8));
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)17 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)5 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)5 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Point (org.eclipse.swt.graphics.Point)4 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)4 Image (org.eclipse.swt.graphics.Image)3 Iterator (java.util.Iterator)2 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)2 IMarker (org.eclipse.core.resources.IMarker)2 SourceField (org.eclipse.jdt.internal.core.SourceField)2 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)2 IDocument (org.eclipse.jface.text.IDocument)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)2 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1