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()]);
}
Aggregations