Search in sources :

Example 1 with IQuickAssistProcessor

use of org.eclipse.jface.text.quickassist.IQuickAssistProcessor in project xtext-eclipse by eclipse.

the class SpellingQuickfixTest method computeQuickAssistProposals.

protected ICompletionProposal[] computeQuickAssistProposals(int offset) {
    XtextSourceViewer sourceViewer = getSourceViewer();
    XtextReconciler reconciler = (XtextReconciler) sourceViewer.getAdapter(IReconciler.class);
    IReconcilingStrategyExtension reconcilingStrategyExtension = (IReconcilingStrategyExtension) reconciler.getReconcilingStrategy("");
    reconcilingStrategyExtension.initialReconcile();
    QuickAssistAssistant quickAssistAssistant = (QuickAssistAssistant) sourceViewer.getQuickAssistAssistant();
    IQuickAssistProcessor quickAssistProcessor = quickAssistAssistant.getQuickAssistProcessor();
    ICompletionProposal[] quickAssistProposals = quickAssistProcessor.computeQuickAssistProposals(new TextInvocationContext(sourceViewer, offset, -1));
    return quickAssistProposals;
}
Also used : IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) XtextReconciler(org.eclipse.xtext.ui.editor.reconciler.XtextReconciler) XtextSourceViewer(org.eclipse.xtext.ui.editor.XtextSourceViewer) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) TextInvocationContext(org.eclipse.jface.text.source.TextInvocationContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) QuickAssistAssistant(org.eclipse.jface.text.quickassist.QuickAssistAssistant) IReconcilingStrategyExtension(org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension)

Example 2 with IQuickAssistProcessor

use of org.eclipse.jface.text.quickassist.IQuickAssistProcessor in project xtext-eclipse by eclipse.

the class AbstractQuickfixTest method computeQuickAssistProposals.

protected ICompletionProposal[] computeQuickAssistProposals(XtextEditor editor, int offset) {
    IResourcesSetupUtil.waitForBuild();
    XtextSourceViewer sourceViewer = (XtextSourceViewer) editor.getInternalSourceViewer();
    QuickAssistAssistant quickAssistAssistant = (QuickAssistAssistant) sourceViewer.getQuickAssistAssistant();
    IQuickAssistProcessor quickAssistProcessor = quickAssistAssistant.getQuickAssistProcessor();
    ICompletionProposal[] quickAssistProposals = quickAssistProcessor.computeQuickAssistProposals(new TextInvocationContext(sourceViewer, offset, -1));
    return quickAssistProposals;
}
Also used : IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) XtextSourceViewer(org.eclipse.xtext.ui.editor.XtextSourceViewer) TextInvocationContext(org.eclipse.jface.text.source.TextInvocationContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) QuickAssistAssistant(org.eclipse.jface.text.quickassist.QuickAssistAssistant)

Example 3 with IQuickAssistProcessor

use of org.eclipse.jface.text.quickassist.IQuickAssistProcessor in project egit by eclipse.

the class SpellcheckableMessageArea method addProposals.

private void addProposals(final SubMenuManager quickFixMenu) {
    IAnnotationModel sourceModel = sourceViewer.getAnnotationModel();
    if (sourceModel == null) {
        return;
    }
    Iterator annotationIterator = sourceModel.getAnnotationIterator();
    while (annotationIterator.hasNext()) {
        Annotation annotation = (Annotation) annotationIterator.next();
        boolean isDeleted = annotation.isMarkedDeleted();
        boolean isIncluded = !isDeleted && includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset());
        boolean isFixable = isIncluded && sourceViewer.getQuickAssistAssistant().canFix(annotation);
        if (isFixable) {
            IQuickAssistProcessor processor = sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor();
            IQuickAssistInvocationContext context = sourceViewer.getQuickAssistInvocationContext();
            ICompletionProposal[] proposals = processor.computeQuickAssistProposals(context);
            for (ICompletionProposal proposal : proposals) {
                quickFixMenu.add(createQuickFixAction(proposal));
            }
        }
    }
}
Also used : IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IQuickAssistInvocationContext(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext) Annotation(org.eclipse.jface.text.source.Annotation)

Example 4 with IQuickAssistProcessor

use of org.eclipse.jface.text.quickassist.IQuickAssistProcessor in project webtools.sourceediting by eclipse.

the class QuickFixRegistry method getQuickFixProcessors.

public IQuickAssistProcessor[] getQuickFixProcessors(Annotation anno) {
    // Collect all matches
    List processors = new ArrayList();
    for (Iterator iter = resolutionQueries.keySet().iterator(); iter.hasNext(); ) {
        AnnotationQuery query = (AnnotationQuery) iter.next();
        AnnotationQueryResult result = null;
        try {
            /* AnnotationQuery objects are contributed by extension point */
            result = query.performQuery(anno);
        } catch (Exception e) {
            Logger.logException(e);
        }
        if (result != null) {
            // See if a matching result is registered
            Map resultsTable = (Map) resolutionQueries.get(query);
            if (resultsTable.containsKey(result)) {
                Iterator elements = ((Collection) resultsTable.get(result)).iterator();
                while (elements.hasNext()) {
                    IConfigurationElement element = (IConfigurationElement) elements.next();
                    IQuickAssistProcessor processor = null;
                    try {
                        processor = (IQuickAssistProcessor) element.createExecutableExtension(ATT_CLASS);
                    } catch (CoreException e) {
                    }
                    if (processor != null) {
                        processors.add(processor);
                    }
                }
            }
        }
    }
    return (IQuickAssistProcessor[]) processors.toArray(new IQuickAssistProcessor[processors.size()]);
}
Also used : IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException)

Example 5 with IQuickAssistProcessor

use of org.eclipse.jface.text.quickassist.IQuickAssistProcessor in project webtools.sourceediting by eclipse.

the class SourceValidationQuickAssistProcessor method computeQuickAssistProposals.

public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) {
    ISourceViewer viewer = quickAssistContext.getSourceViewer();
    int documentOffset = quickAssistContext.getOffset();
    int length = viewer != null ? viewer.getSelectedRange().y : 0;
    IAnnotationModel model = viewer.getAnnotationModel();
    if (model == null)
        return null;
    List allProposals = new ArrayList();
    if (model instanceof IAnnotationModelExtension2) {
        Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
        while (iter.hasNext()) {
            List processors = new ArrayList();
            Annotation anno = (Annotation) iter.next();
            if (canFix(anno)) {
                // fix processor attached to it
                if (anno instanceof TemporaryAnnotation) {
                    Object o = ((TemporaryAnnotation) anno).getAdditionalFixInfo();
                    if (o instanceof IQuickAssistProcessor) {
                        processors.add(o);
                    }
                }
                // get all relevant quick fixes for this annotation
                QuickFixRegistry registry = QuickFixRegistry.getInstance();
                processors.addAll(Arrays.asList(registry.getQuickFixProcessors(anno)));
                // set up context
                Map attributes = null;
                if (anno instanceof TemporaryAnnotation) {
                    attributes = ((TemporaryAnnotation) anno).getAttributes();
                }
                Position pos = model.getPosition(anno);
                StructuredTextInvocationContext sseContext = new StructuredTextInvocationContext(viewer, pos.getOffset(), pos.getLength(), attributes);
                // call each processor
                for (int i = 0; i < processors.size(); ++i) {
                    List proposals = new ArrayList();
                    collectProposals((IQuickAssistProcessor) processors.get(i), anno, sseContext, proposals);
                    if (proposals.size() > 0) {
                        allProposals.addAll(proposals);
                    }
                }
            }
        }
    }
    if (allProposals.isEmpty())
        return null;
    return (ICompletionProposal[]) allProposals.toArray(new ICompletionProposal[allProposals.size()]);
}
Also used : Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IQuickFixableAnnotation(org.eclipse.jface.text.quickassist.IQuickFixableAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) Map(java.util.Map) StructuredTextInvocationContext(org.eclipse.wst.sse.ui.StructuredTextInvocationContext)

Aggregations

IQuickAssistProcessor (org.eclipse.jface.text.quickassist.IQuickAssistProcessor)8 Iterator (java.util.Iterator)5 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 QuickAssistAssistant (org.eclipse.jface.text.quickassist.QuickAssistAssistant)2 Annotation (org.eclipse.jface.text.source.Annotation)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 TextInvocationContext (org.eclipse.jface.text.source.TextInvocationContext)2 XtextSourceViewer (org.eclipse.xtext.ui.editor.XtextSourceViewer)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Position (org.eclipse.jface.text.Position)1 IQuickAssistInvocationContext (org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)1 IQuickFixableAnnotation (org.eclipse.jface.text.quickassist.IQuickFixableAnnotation)1