Java Code Examples for org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext#getSourceViewer()
The following examples show how to use
org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext#getSourceViewer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtextQuickAssistProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @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; } } } }
Example 2
Source File: TexSpellingEngine.java From texlipse with Eclipse Public License 1.0 | 6 votes |
@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; }
Example 3
Source File: XtextQuickAssistProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @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.getXtextDocument(sourceViewer); for(Annotation annotation : applicableAnnotations) { if (annotation instanceof SpellingAnnotation) { SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem(); ICompletionProposal[] proposals = spellingProblem.getProposals(); if (proposals != null) { result.addAll(asList(proposals)); } } else { final Issue issue = issueUtil.getIssueFromAnnotation(annotation); Position pos = annotationModel.getPosition(annotation); if (issue != null && pos != null) { @SuppressWarnings("deprecation") Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument); if (resolutions.iterator().hasNext()) { for (IssueResolution resolution : resolutions) { result.add(create(pos, resolution)); } } } } } return result; }
Example 4
Source File: PropertiesCorrectionProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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); }
Example 5
Source File: JavaCorrectionProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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; }
Example 6
Source File: PropertiesQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean getEscapeUnescapeBackslashProposals(IQuickAssistInvocationContext invocationContext, ArrayList<ICompletionProposal> resultingCollections) throws BadLocationException, BadPartitioningException { ISourceViewer sourceViewer= invocationContext.getSourceViewer(); IDocument document= sourceViewer.getDocument(); Point selectedRange= sourceViewer.getSelectedRange(); int selectionOffset= selectedRange.x; int selectionLength= selectedRange.y; int proposalOffset; int proposalLength; String text; if (selectionLength == 0) { if (selectionOffset != document.getLength()) { char ch= document.getChar(selectionOffset); if (ch == '=' || ch == ':') { //see PropertiesFilePartitionScanner() return false; } } ITypedRegion partition= null; if (document instanceof IDocumentExtension3) partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, invocationContext.getOffset(), false); if (partition == null) return false; String type= partition.getType(); if (!(type.equals(IPropertiesFilePartitions.PROPERTY_VALUE) || type.equals(IDocument.DEFAULT_CONTENT_TYPE))) { return false; } proposalOffset= partition.getOffset(); proposalLength= partition.getLength(); text= document.get(proposalOffset, proposalLength); if (type.equals(IPropertiesFilePartitions.PROPERTY_VALUE)) { text= text.substring(1); //see PropertiesFilePartitionScanner() proposalOffset++; proposalLength--; } } else { proposalOffset= selectionOffset; proposalLength= selectionLength; text= document.get(proposalOffset, proposalLength); } if (PropertiesFileEscapes.containsUnescapedBackslash(text)) { if (resultingCollections == null) return true; resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength, PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes)); return true; } if (PropertiesFileEscapes.containsEscapedBackslashes(text)) { if (resultingCollections == null) return true; resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.unescapeBackslashes(text), proposalOffset, proposalLength, PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_unescapeBackslashes)); return true; } return false; }
Example 7
Source File: PydevConsoleQuickAssistProcessor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * Computes quick assists for the console. */ @Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); List<ICompletionProposalHandle> props = new ArrayList<ICompletionProposalHandle>(); if (sourceViewer instanceof ScriptConsoleViewer) { ScriptConsoleViewer viewer = (ScriptConsoleViewer) sourceViewer; //currently, only the assign quick assist is used AssistAssign assistAssign = new AssistAssign(); ISelection selection = sourceViewer.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(sourceViewer, (ITextSelection) selection); int offset = viewer.getCaretOffset(); String commandLine = viewer.getCommandLine(); //let's calculate the 1st line that is not a whitespace. if (assistAssign.isValid(ps.getSelLength(), commandLine, offset)) { int commandLineOffset = viewer.getCommandLineOffset(); try { IDocument doc = sourceViewer.getDocument(); while (true) { if (commandLineOffset == doc.getLength() - 1) { break; } char c = doc.getChar(commandLineOffset); if (Character.isWhitespace(c)) { commandLineOffset++; } else { break; } } props.addAll(assistAssign.getProps(ps, SharedUiPlugin.getImageCache(), sourceViewer, offset, commandLine, commandLineOffset)); } catch (BadLocationException e) { Log.log(e); } } } } return ConvertCompletionProposals .convertHandlesToProposals(props.toArray(new ICompletionProposalHandle[props.size()])); }