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