public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<de.darwinspl.preferences.resource.dwprofile.IDwprofileQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
@SuppressWarnings("unchecked") @Override public ICompletionProposal[] getProposals(IQuickAssistInvocationContext context) { List<Word> sugg = fError.getSuggestions(); int length = fError.getInvalidWord().length(); ICompletionProposal[] props = new ICompletionProposal[sugg.size() + 2]; for (int i=0; i < sugg.size(); i++) { String suggestion = sugg.get(i).toString(); String s = MessageFormat.format(CHANGE_TO, new Object[] { suggestion }); props[i] = new CompletionProposal(suggestion, fOffset, length, suggestion.length(), fCorrectionImage, s, null, null); } props[props.length - 2] = new IgnoreProposal(ignore, fError.getInvalidWord(), context.getSourceViewer()); props[props.length - 1] = new AddToDictProposal(fError, fLang, context.getSourceViewer()); return props; }
private void addProposals(final SubMenuManager quickFixMenu) { IAnnotationModel sourceModel = sourceViewer.getAnnotationModel(); Iterator annotationIterator = sourceModel.getAnnotationIterator(); while (annotationIterator.hasNext()) { Annotation annotation = (Annotation) annotationIterator.next(); boolean isDeleted = annotation.isMarkedDeleted(); boolean isIncluded = includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset()); boolean isFixable = sourceViewer.getQuickAssistAssistant().canFix( annotation); if (!isDeleted && isIncluded && isFixable) { IQuickAssistProcessor processor = sourceViewer .getQuickAssistAssistant() .getQuickAssistProcessor(); IQuickAssistInvocationContext context = sourceViewer .getQuickAssistInvocationContext(); ICompletionProposal[] proposals = processor .computeQuickAssistProposals(context); for (ICompletionProposal proposal : proposals) quickFixMenu.add(createQuickFixAction(proposal)); } } }
@Override protected Object getHoverInfoInternal(ITextViewer textViewer, final int lineNumber, final int offset) { AnnotationInfo result = recentAnnotationInfo; if (result != null) return result; List<Annotation> annotations = getAnnotations(lineNumber, offset); if (annotations != null) { for (Annotation annotation : annotations) { if (annotation.getText() != null) { Position position = getAnnotationModel().getPosition(annotation); final IQuickAssistInvocationContext invocationContext = new QuickAssistInvocationContext(sourceViewer, position.getOffset(), position.getLength(), true); CompletionProposalRunnable runnable = new CompletionProposalRunnable(invocationContext); // Note: the resolutions have to be retrieved from the UI thread, otherwise // workbench.getActiveWorkbenchWindow() will return null in LanguageSpecificURIEditorOpener and // cause an exception Display.getDefault().syncExec(runnable); result = new AnnotationInfo (annotation, position, sourceViewer, runnable.proposals); recentAnnotationInfo = result; return result; } } } return null; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); if (sourceViewer == null) return new ICompletionProposal[0]; final IDocument document = sourceViewer.getDocument(); if (!(document instanceof IXtextDocument)) return new ICompletionProposal[0]; final IXtextDocument xtextDocument = (IXtextDocument) document; final IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); List<ICompletionProposal> result = Lists.newArrayList(); try { Set<Annotation> applicableAnnotations = getApplicableAnnotations(xtextDocument, annotationModel, invocationContext.getOffset()); result = createQuickfixes(invocationContext, applicableAnnotations); selectAndRevealQuickfix(invocationContext, applicableAnnotations, result); } catch (BadLocationException e) { errorMessage = e.getMessage(); } sortQuickfixes(result); return result.toArray(new ICompletionProposal[result.size()]); }
/** * @since 2.3 */ protected List<ICompletionProposal> createQuickfixes(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations) { List<ICompletionProposal> result = Lists.newArrayList(); ISourceViewer sourceViewer = invocationContext.getSourceViewer(); IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); IXtextDocument xtextDocument = XtextDocumentUtil.get(sourceViewer); for(Annotation annotation : applicableAnnotations) { if (annotation instanceof SpellingAnnotation) { SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem(); result.addAll(asList(spellingProblem.getProposals())); } else { final Issue issue = issueUtil.getIssueFromAnnotation(annotation); if (issue != null) { Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument); if (resolutions.iterator().hasNext()) { Position pos = annotationModel.getPosition(annotation); for (IssueResolution resolution : resolutions) { result.add(create(pos, resolution)); } } } } } return result; }
/** * @since 2.3 */ protected void selectAndRevealQuickfix(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations, List<ICompletionProposal> completionProposals) { if (completionProposals.isEmpty()) { return; } if (invocationContext instanceof QuickAssistInvocationContext && !((QuickAssistInvocationContext) invocationContext).isSuppressSelection()) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); Iterator<Annotation> iterator = applicableAnnotations.iterator(); while(iterator.hasNext()){ Position pos = annotationModel.getPosition(iterator.next()); if (pos != null) { sourceViewer.setSelectedRange(pos.getOffset(), pos.getLength()); sourceViewer.revealRange(pos.getOffset(), pos.getLength()); break; } } } }
@Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { List<IMarker> markers; try { markers = getMarkersFor(invocationContext.getSourceViewer(), invocationContext.getOffset()); } catch (BadLocationException e) { errorMessage = e.getMessage(); return new ICompletionProposal[0]; } List<ICompletionProposal> result = Lists.newArrayList(); for (IMarker marker : markers) { for (IMarkerResolution markerResolution : quickFixer.getResolutions(marker)) { result.add(new MarkerResolutionProposal(marker, markerResolution, invocationContext.getSourceViewer())); } } return result.toArray(new ICompletionProposal[0]); }
/** * Creates a new word correction proposal. * * @param word the corrected word * @param arguments the problem arguments associated with the spelling problem * @param offset the offset in the document where to apply the proposal * @param length the lenght in the document to apply the proposal * @param context the invocation context for this proposal * @param relevance the relevance of this proposal */ public WordCorrectionProposal(final String word, final String[] arguments, final int offset, final int length, final IQuickAssistInvocationContext context, final int relevance) { fWord= Character.isUpperCase(arguments[0].charAt(0)) ? Character.toUpperCase(word.charAt(0)) + word.substring(1) : word; fOffset= offset; fLength= length; fContext= context; fRelevance= relevance; final StringBuffer buffer= new StringBuffer(80); buffer.append("...<br>"); //$NON-NLS-1$ buffer.append(getHtmlRepresentation(arguments[1])); buffer.append("<b>"); //$NON-NLS-1$ buffer.append(getHtmlRepresentation(fWord)); buffer.append("</b>"); //$NON-NLS-1$ buffer.append(getHtmlRepresentation(arguments[2])); buffer.append("<br>..."); //$NON-NLS-1$ fLine= buffer.toString(); }
private PropertiesAssistContext createAssistContext(IQuickAssistInvocationContext invocationContext) { IEditorPart editorPart= fAssistant.getEditor(); IFile file= (IFile) editorPart.getEditorInput().getAdapter(IFile.class); ISourceViewer sourceViewer= invocationContext.getSourceViewer(); IType accessorType= ((PropertiesFileEditor) editorPart).getAccessorType(); return new PropertiesAssistContext(sourceViewer, invocationContext.getOffset(), invocationContext.getLength(), file, sourceViewer.getDocument(), accessorType); }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer= quickAssistContext.getSourceViewer(); int documentOffset= quickAssistContext.getOffset(); IEditorPart part= fAssistant.getEditor(); ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput()); IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(part.getEditorInput()); AssistContext context= null; if (cu != null) { int length= viewer != null ? viewer.getSelectedRange().y : 0; context= new AssistContext(cu, viewer, part, documentOffset, length); } Annotation[] annotations= fAssistant.getAnnotationsAtOffset(); fErrorMessage= null; ICompletionProposal[] res= null; if (model != null && context != null && annotations != null) { ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(10); IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res= proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) { fErrorMessage= status.getMessage(); JavaPlugin.log(status); } } if (res == null || res.length == 0) { return new ICompletionProposal[] { new ChangeCorrectionProposal(CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), IProposalRelevance.NO_SUGGESSTIONS_AVAILABLE, null) }; //$NON-NLS-1$ } if (res.length > 1) { Arrays.sort(res, new CompletionProposalComparator()); } return res; }
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer= quickAssistContext.getSourceViewer(); int documentOffset= quickAssistContext.getOffset(); IEditorPart part= fAssistant.getEditor(); ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput()); IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(part.getEditorInput()); AssistContext context= null; if (cu != null) { int length= viewer != null ? viewer.getSelectedRange().y : 0; context= new AssistContext(cu, viewer, part, documentOffset, length); } Annotation[] annotations= fAssistant.getAnnotationsAtOffset(); fErrorMessage= null; ICompletionProposal[] res= null; if (model != null && context != null && annotations != null) { ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(10); IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res= proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) { fErrorMessage= status.getMessage(); JavaPlugin.log(status); } } if (res == null || res.length == 0) { return new ICompletionProposal[] { new ChangeCorrectionProposal(CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), 0, null) }; //$NON-NLS-1$ } if (res.length > 1) { Arrays.sort(res, new CompletionProposalComparator()); } return res; }
public boolean canAssist(IQuickAssistInvocationContext invocationContext) { return false; }
@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext invocationContext) { return new ICompletionProposal[] {fix}; }
@Override public boolean canAssist(IQuickAssistInvocationContext invocationContext) { return false; }
public CompletionProposalRunnable(IQuickAssistInvocationContext invocationContext) { this.invocationContext = invocationContext; }