Search in sources :

Example 1 with StructuredTextInvocationContext

use of org.eclipse.wst.sse.ui.StructuredTextInvocationContext 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

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Position (org.eclipse.jface.text.Position)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IQuickAssistProcessor (org.eclipse.jface.text.quickassist.IQuickAssistProcessor)1 IQuickFixableAnnotation (org.eclipse.jface.text.quickassist.IQuickFixableAnnotation)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 IAnnotationModelExtension2 (org.eclipse.jface.text.source.IAnnotationModelExtension2)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 StructuredTextInvocationContext (org.eclipse.wst.sse.ui.StructuredTextInvocationContext)1 TemporaryAnnotation (org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)1