org.eclipse.jface.text.ITextViewer Java Examples
The following examples show how to use
org.eclipse.jface.text.ITextViewer.
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: SnippetTemplateProposal.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override public void apply(final ITextViewer viewer, char trigger, int stateMask, final int offset) { delegateTemplateProposal = null; if (contains(triggerChars, trigger)) { if (triggerChar == trigger) { doApply(viewer, trigger, stateMask, offset); } else { delegateTemplateProposal = templateProposals[trigger - '1']; ((ICompletionProposalExtension2) templateProposals[trigger - '1']).apply(viewer, trigger, stateMask, offset); } } else { doApply(viewer, trigger, stateMask, offset); } }
Example #2
Source File: CompletionProposalsGrouping.java From goclipse with Eclipse Public License 1.0 | 6 votes |
public Indexable<IContextInformation> computeContextInformation(ISourceBufferExt sourceBuffer, ITextViewer viewer, int offset) { clearErrorMessage(); ArrayList2<IContextInformation> proposals = new ArrayList2<>(); for (ILangCompletionProposalComputer computer : computers) { try { Indexable<IContextInformation> computerProposals = computer.computeContextInformation( sourceBuffer, viewer, offset); if(computerProposals != null) { proposals.addAll2(computerProposals); } } catch(OperationSoftFailure e) { updateErrorMessage(e.getMessage()); } } return proposals; }
Example #3
Source File: CrossReferenceProposalTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug276742_08b() throws Exception { String modelAsString = "Foo {}"; ContentAssistProcessorTestBuilder builder = newBuilder(); XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class); XtextResource resource = getResourceFromString(modelAsString); ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString)); ContentAssistContext[] contexts = processor.getContextFactory() .create(viewer, modelAsString.length(), resource); assertEquals(2, contexts.length); Set<EClass> contextTypes = Sets.newHashSet(CrossReferenceProposalTestPackage.Literals.MODEL, CrossReferenceProposalTestPackage.Literals.CLASS); CrossReferenceProposalTestLanguageGrammarAccess grammarAccess = get(CrossReferenceProposalTestLanguageGrammarAccess.class); for (ContentAssistContext context : contexts) { EObject model = context.getCurrentModel(); assertTrue(contextTypes.remove(model.eClass())); if (context.getFirstSetGrammarElements().contains( grammarAccess.getClassAccess().getRightCurlyBracketKeyword_3())) { assertEquals(CrossReferenceProposalTestPackage.Literals.CLASS, model.eClass()); } else { assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, model.eClass()); } } }
Example #4
Source File: OverrideMethodCompletionProposal.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { IDocument document = viewer.getDocument(); int finalOffset = applyOnDocument(viewer, document, trigger, stateMask, offset); if (finalOffset >= 0) { try { PySelection ps = new PySelection(document, finalOffset); int firstCharPosition = PySelection.getFirstCharPosition(ps.getLine()); int lineOffset = ps.getLineOffset(); int location = lineOffset + firstCharPosition; int len = finalOffset - location; fCursorPosition = location; fReplacementLength = len; } catch (Exception e) { Log.log(e); } } }
Example #5
Source File: TestSnippetContentAssistProcessor.java From corrosion with Eclipse Public License 2.0 | 6 votes |
private void validateCompletionProposals(String text, String[] expectedProposalTexts) throws IOException, CoreException { IProject project = getProject(BASIC_PROJECT_NAME); IFile file = project.getFolder("src").getFile("main.rs"); IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); ((ITextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput()).set(text); ICompletionProposal[] proposals = (new SnippetContentAssistProcessor()).computeCompletionProposals( (ITextViewer) editor.getAdapter(ITextOperationTarget.class), text.length() - 1); if (expectedProposalTexts == null) { assertTrue(proposals == null || proposals.length == 0); return; } assertNotNull(proposals); for (int i = 0; i < proposals.length; i++) { assertEquals(((LSCompletionProposal) proposals[i]).getItem().getTextEdit().getNewText(), expectedProposalTexts[i]); } }
Example #6
Source File: DefaultEObjectHoverProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public IInformationControlCreatorProvider getHoverInfo(final EObject object, final ITextViewer viewer, final IRegion region) { return new IInformationControlCreatorProvider2() { @Override public IInformationControlCreator getHoverControlCreator() { return DefaultEObjectHoverProvider.this.getHoverControlCreator(); } @Override public Object getInfo() { try { return getHoverInfo(object, region, null); } catch (RuntimeException e) { LOG.error("Error on computation of hover information. No hover information available for "+ object + " at " + region, e); return null; } } @Override public IInformationControlCreator getInformationPresenterControlCreator() { return DefaultEObjectHoverProvider.this.getInformationPresenterControlCreator(); }}; }
Example #7
Source File: CodeTemplateSourceViewerConfiguration.java From typescript.java with MIT License | 6 votes |
public String getHoverInfo(ITextViewer textViewer, IRegion subject) { try { IDocument doc= textViewer.getDocument(); int offset= subject.getOffset(); if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { //$NON-NLS-1$ String varName= doc.get(offset, subject.getLength()); TemplateContextType contextType= fProcessor.getContextType(); if (contextType != null) { Iterator iter= contextType.resolvers(); while (iter.hasNext()) { TemplateVariableResolver var= (TemplateVariableResolver) iter.next(); if (varName.equals(var.getType())) { return var.getDescription(); } } } } } catch (BadLocationException e) { } return null; }
Example #8
Source File: TextViewerOperationAction.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * The <code>TextOperationAction</code> implementation of this <code>IAction</code> method runs the operation with * the current operation code. */ @Override public void run() { if (fOperationCode == -1 || fOperationTarget == null) return; ITextViewer viewer = getTextViewer(); if (viewer == null) return; if (!fRunsOnReadOnly && !canModifyViewer()) return; Display display = null; Shell shell = viewer.getTextWidget().getShell(); if (shell != null && !shell.isDisposed()) display = shell.getDisplay(); BusyIndicator.showWhile(display, new Runnable() { @Override public void run() { fOperationTarget.doOperation(fOperationCode); } }); }
Example #9
Source File: ContenAssistProcessorExt.java From goclipse with Eclipse Public License 1.0 | 6 votes |
@Override public final ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { resetComputeState(); // The code below has been commented, it causes a bug with templates with "${word_selection} " usage, // and it's not clear this functionality made sense in the first place. // if(viewer instanceof LangSourceViewer) { // LangSourceViewer sourceViewer = (LangSourceViewer) viewer; // if(sourceViewer.getSelectedRange().y > 0) { // // Correct the invocation offset for content assist. // // The issue is that if text is selected, the cursor can either be on the left, or the right // // but the offset used will always be the left side of the selection, unless we correct it. // // int caretOffset = sourceViewer.getTextWidget().getCaretOffset(); // offset = sourceViewer.widgetOffset2ModelOffset(caretOffset); // } // } return doComputeCompletionProposals(viewer, offset); }
Example #10
Source File: CSSElementSelectorHover.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IParseNode activeNode = getActiveNode(textViewer, offset); if (activeNode instanceof CSSSimpleSelectorNode) { CSSSimpleSelectorNode node = (CSSSimpleSelectorNode) activeNode; // Verify that this is an HTML element selector String typeSelector = node.getTypeSelector(); if (!StringUtil.isEmpty(typeSelector)) { ElementElement element = new HTMLIndexQueryHelper().getElement(typeSelector.toLowerCase()); if (element != null) { return new Region(node.getStartingOffset(), node.getLength()); } } } return null; }
Example #11
Source File: SecuritySchemeHyperlinkDetector.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 6 votes |
@Override protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) { Matcher matcher = PATTERN.matcher(pointer.toString()); String link = matcher.find() ? matcher.group(1) : null; if (link != null) { Model model = doc.getModel(); AbstractNode securityScheme = model.find("/components/securitySchemes/" + link); if (securityScheme != null) { IRegion target = doc.getRegion(securityScheme.getPointer()); if (target != null) { return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) }; } } } return null; }
Example #12
Source File: JavaDebugElementCodeMiningProvider.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
@Override protected List provideCodeMinings(ITextViewer viewer, IJavaStackFrame frame, IProgressMonitor monitor) { List<ICodeMining> minings = new ArrayList<>(); ITextEditor textEditor = super.getAdapter(ITextEditor.class); ITypeRoot unit = EditorUtility.getEditorInputJavaElement(textEditor, true); if (unit == null) { return minings; } CompilationUnit cu = SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_YES, null); JavaDebugElementCodeMiningASTVisitor visitor = new JavaDebugElementCodeMiningASTVisitor(frame, cu, viewer, minings, this); cu.accept(visitor); return minings; }
Example #13
Source File: BestMatchHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the information which should be presented when a hover or persistent popup is shown * for the specified hover region. * * @param textViewer the viewer on which the hover popup should be shown * @param hoverRegion the text range in the viewer which is used to determine the hover display * information * @param forInformationProvider <code>true</code> iff the hover info is requested by the * information presenter. In this case, the method only considers text hovers for * which a proper IInformationControlCreator is available that can supply focusable * and resizable information controls. * * @return the hover popup display information, or <code>null</code> if none available * * @see ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion) * @since 3.8 */ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion, boolean forInformationProvider) { checkTextHovers(); fBestHover= null; if (fInstantiatedTextHovers == null) return null; for (Iterator<IJavaEditorTextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) { ITextHover hover= iterator.next(); if (hover == null) continue; if (hover instanceof ITextHoverExtension2) { Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion); if (info != null && !(forInformationProvider && getInformationPresenterControlCreator(hover) == null)) { fBestHover= hover; return info; } } else { String s= hover.getHoverInfo(textViewer, hoverRegion); if (s != null && s.trim().length() > 0) { fBestHover= hover; return s; } } } return null; }
Example #14
Source File: JavaDebugHoverProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public IInformationControlCreatorProvider getInformationControlCreatorProvider(ITextViewer textViewer, IRegion hoverRegion) { if (!IS_JAVA_DEBUG_HOVER_AVAILABLE) return null; final JavaDebugHover javaDebugHover = injector.getInstance(JavaDebugHover.class); final Object hoverInfo = javaDebugHover.getHoverInfo2(textViewer, hoverRegion); if (hoverInfo == null) return null; return new IEObjectHoverProvider.IInformationControlCreatorProvider2() { @Override public IInformationControlCreator getHoverControlCreator() { return javaDebugHover.getHoverControlCreator(); } @Override public Object getInfo() { return hoverInfo; } @Override public IInformationControlCreator getInformationPresenterControlCreator() { return javaDebugHover.getInformationPresenterControlCreator(); } }; }
Example #15
Source File: HDoubleClickStrategy.java From http4e with Apache License 2.0 | 5 votes |
public void doubleClicked( ITextViewer part){ int pos = part.getSelectedRange().x; if (pos < 0) return; fText = part; if (!selectComment(pos)) { selectWord(pos); } }
Example #16
Source File: JsonContentAssistProcessor.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 5 votes |
@Override protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) { String contextType = getContextTypeId(currentModel, currentPath.toString()); ContextTypeRegistry registry = getContextTypeRegistry(); if (registry != null) { return registry.getContextType(contextType); } else { return null; } }
Example #17
Source File: JavaDebugElementCodeMiningASTVisitor.java From jdt-codemining with Eclipse Public License 1.0 | 5 votes |
public JavaDebugElementCodeMiningASTVisitor(IJavaStackFrame frame, CompilationUnit cu, ITextViewer viewer, List<ICodeMining> minings, AbstractDebugVariableCodeMiningProvider provider) { this.cu = cu; this.minings = minings; this.provider = provider; this.viewer = viewer; this.fFrame = frame; }
Example #18
Source File: TemplateProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void beginCompoundChange(ITextViewer viewer) { if (viewer instanceof ITextViewerExtension) { ITextViewerExtension extension= (ITextViewerExtension) viewer; IRewriteTarget target= extension.getRewriteTarget(); target.beginCompoundChange(); } }
Example #19
Source File: DelegatingDebugTextHover.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public Object getHoverInfo(ISourceBuffer sourceBuffer, IRegion hoverRegion, ITextViewer textViewer) { fDelegate = getDelegate(); if (fDelegate instanceof ITextHoverExtension2) { return ((ITextHoverExtension2) fDelegate).getHoverInfo2(textViewer, hoverRegion); } // fall back to legacy method if (fDelegate != null) { return fDelegate.getHoverInfo(textViewer, hoverRegion); } return null; }
Example #20
Source File: PythonCompletionProcessor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Returns the template proposals as a list. */ private TokensOrProposalsList getTemplateProposals(ITextViewer viewer, int documentOffset, String activationToken, java.lang.String qualifier) { List<ICompletionProposalHandle> propList = new ArrayList<ICompletionProposalHandle>(); if (this.templatesCompletion != null) { this.templatesCompletion.addTemplateProposals(viewer, documentOffset, propList); } return new TokensOrProposalsList(propList); }
Example #21
Source File: PyDocumentTemplateContext.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @return the indent preferences to be used. */ private static IIndentPrefs getIndentPrefs(ITextViewer viewer) { if (viewer instanceof IPySourceViewer) { IPySourceViewer pyViewer = (IPySourceViewer) viewer; return pyViewer.getEdit().getIndentPrefs(); } else { return DefaultIndentPrefs.get(null); } }
Example #22
Source File: ContentAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset, IProgressMonitor monitor) { List<IContextInformation> proposals= new ArrayList<IContextInformation>(); ContentAssistInvocationContext context= createContext(viewer, offset); List<CompletionProposalCategory> providers= getCategories(); for (CompletionProposalCategory cat : providers) { List<IContextInformation> computed= cat.computeContextInformation(context, fPartition, new SubProgressMonitor(monitor, 1)); proposals.addAll(computed); if (fErrorMessage == null) fErrorMessage= cat.getErrorMessage(); } return proposals; }
Example #23
Source File: JSContextInformationValidator.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void install(IContextInformation info, ITextViewer viewer, int offset) { this._contextInformation = info; this._viewer = viewer; if (info instanceof IContextInformationExtension) { this._startingOffset = ((IContextInformationExtension) info).getContextInformationPosition(); } else { this._startingOffset = offset; } }
Example #24
Source File: TextViewerMoveLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Ends the compound change. */ private void endCompoundEdit() { ITextViewer viewer= getTextViewer(); if (!fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension)) return; IRewriteTarget target= ((ITextViewerExtension) viewer).getRewriteTarget(); if (target != null) { target.endCompoundChange(); } fEditInProgress= false; }
Example #25
Source File: SnippetContentAssistProcessor.java From corrosion with Eclipse Public License 2.0 | 5 votes |
/** * Get the current selection from the given {@code viewer}. If there is a (non * empty) selection returns a {@code Range} computed from the selection and * returns this wrapped in an optional, otherwise returns an empty optional. * * @param document currently active document * @param viewer the text viewer for the completion * @return either an optional containing the text selection, or an empty * optional, if there is no (non-empty) selection. */ private static Optional<Range> getRangeFromSelection(IDocument document, ITextViewer viewer) { if (!(viewer instanceof ITextViewerExtension9)) { return Optional.empty(); } ITextViewerExtension9 textViewer = (ITextViewerExtension9) viewer; ITextSelection textSelection = textViewer.getLastKnownSelection(); if (textSelection == null) { return Optional.empty(); } int selectionLength = textSelection.getLength(); if (selectionLength <= 0) { return Optional.empty(); } try { int startOffset = textSelection.getOffset(); Position startPosition = LSPEclipseUtils.toPosition(startOffset, document); int endOffset = startOffset + selectionLength; Position endPosition = LSPEclipseUtils.toPosition(endOffset, document); return Optional.of(new Range(startPosition, endPosition)); } catch (BadLocationException e) { return Optional.empty(); } }
Example #26
Source File: PyEditorTextHoverProxy.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { if (ensureHoverCreated() && fHover.isContentTypeSupported(this.contentType)) { return fHover.getHoverRegion(textViewer, offset); } return null; }
Example #27
Source File: PyLinkedModeCompletionProposal.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private void goToLinkedModeFromArgs(ITextViewer viewer, int offset, IDocument doc, int exitPos, int iPar, String newStr) throws BadLocationException { if (!goToLinkedMode) { return; } List<Integer> offsetsAndLens = new ArrayList<Integer>(); PySelection.computeArgsOffsetsAndLens(newStr, offsetsAndLens); goToLinkedMode(viewer, offset, doc, exitPos, iPar, offsetsAndLens); }
Example #28
Source File: HTMLTypeScriptPrinter.java From typescript.java with MIT License | 5 votes |
public static void endPage(StringBuffer buffer, ITextViewer textViewer) { ITheme theme = null; if (textViewer != null) { TMPresentationReconciler reconciler = getTMPresentationReconciler(textViewer); if (reconciler != null) { theme = (ITheme) reconciler.getTokenProvider(); } if (theme == null) { theme = TMUIPlugin.getThemeManager().getDefaultTheme(); } } HTMLPrinter.insertPageProlog(buffer, 0, colorInfoForeground, colorInfoBackround, HTMLTypeScriptPrinter.getStyleSheet() + (theme != null ? theme.toCSSStyleSheet() : "")); HTMLPrinter.addPageEpilog(buffer); }
Example #29
Source File: TextUtils.java From tm4e with Eclipse Public License 1.0 | 5 votes |
public static TabSpacesInfo getTabSpaces(ITextViewer viewer) { TabsToSpacesConverter converter = ClassHelper.getFieldValue(viewer, "fTabsToSpacesConverter", TextViewer.class); //$NON-NLS-1$ if (converter != null) { int tabSize = ClassHelper.getFieldValue(converter, "fTabRatio", TabsToSpacesConverter.class); //$NON-NLS-1$ return new TabSpacesInfo(tabSize, true); } return new TabSpacesInfo(-1, false); }
Example #30
Source File: LanguageConfigurationAutoEditStrategy.java From tm4e with Eclipse Public License 1.0 | 5 votes |
private void installViewer() { if (viewer == null) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editorPart = page.getActiveEditor(); viewer = editorPart.getAdapter(ITextViewer.class); } }