Java Code Examples for org.eclipse.jface.text.source.Annotation#getText()
The following examples show how to use
org.eclipse.jface.text.source.Annotation#getText() .
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: AnnotationWithQuickFixesHover.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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); for (Annotation annotation : sortBySeverity(annotations)) { Position position = getAnnotationModel().getPosition(annotation); if (annotation.getText() != null && position != null) { final QuickAssistInvocationContext 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); if (invocationContext.isMarkedCancelled()) { return null; } result = new AnnotationInfo(annotation, position, sourceViewer, runnable.proposals); recentAnnotationInfo = result; return result; } } return null; }
Example 2
Source File: DirtyStateEditorValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private void assertNumberOfErrorAnnotations(final XtextEditor editor, final int expectedNumber) { final Function0<Boolean> _function = () -> { int _size = this.getErrorAnnotations(editor).size(); return Boolean.valueOf((_size == expectedNumber)); }; this.helper.awaitUIUpdate(_function, DirtyStateEditorValidationTest.VALIDATION_TIMEOUT); final List<Annotation> errors = this.getErrorAnnotations(editor); final Function1<Annotation, String> _function_1 = (Annotation it) -> { String _text = it.getText(); String _plus = (_text + "("); boolean _isPersistent = it.isPersistent(); String _plus_1 = (_plus + Boolean.valueOf(_isPersistent)); return (_plus_1 + ")"); }; Assert.assertEquals(IterableExtensions.join(ListExtensions.<Annotation, String>map(errors, _function_1), ", "), expectedNumber, errors.size()); }
Example 3
Source File: XtextEditor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void updateStatusLine() { ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider != null) { final ITextSelection selection = (ITextSelection) selectionProvider.getSelection(); final Annotation annotation = getAnnotation(selection.getOffset(), selection.getLength()); String message = null; if (annotation != null) { updateMarkerViews(annotation); if (isProblemMarkerAnnotation(annotation)) { message = annotation.getText(); } } setStatusLineMessage(message); } }
Example 4
Source File: AnnotationWithQuickFixesHover.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText= annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 5
Source File: ProblemAnnotationHover.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected Object getHoverInfoInternal(final ITextViewer textViewer, final int lineNumber, final int offset) { final Set<String> messages = Sets.newLinkedHashSet(); List<Annotation> annotations = getAnnotations(lineNumber, offset); for (Annotation annotation : annotations) { String text = annotation.getText(); if (text != null) { messages.add(text.trim()); } } if (messages.size() > 0) return formatInfo(messages); return null; }
Example 6
Source File: TLAReconcilingStrategy.java From tlaplus with MIT License | 5 votes |
@Override public boolean equals(final Object other) { if (other == null) { return false; } if (!Annotation.class.isAssignableFrom(other.getClass())) { return false; } final Annotation otherAnnotation = (Annotation)other; final String otherText = otherAnnotation.getText(); return Objects.equals(getText(), otherText); }
Example 7
Source File: AbstractAnnotationHover.java From typescript.java with MIT License | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 2; layout.marginWidth = 2; layout.horizontalSpacing = 0; composite.setLayout(layout); final Canvas canvas = new Canvas(composite, SWT.NO_FOCUS); GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint = 17; gridData.heightHint = 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText = annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 8
Source File: CommonAnnotationHover.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private boolean includeAnnotation(Annotation annotation, Position position, Map<Position, Object> messagesAtPosition) { if (!isIncluded(annotation)) { return false; } String text = annotation.getText(); return (text != null && !isDuplicateAnnotation(messagesAtPosition, position, text)); }
Example 9
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void updateStatusLine() { ITextSelection selection= (ITextSelection) getSelectionProvider().getSelection(); Annotation annotation= getAnnotation(selection.getOffset(), selection.getLength()); String message= null; if (annotation != null) { updateMarkerViews(annotation); if (annotation instanceof IJavaAnnotation && ((IJavaAnnotation) annotation).isProblem() || isProblemMarkerAnnotation(annotation)) message= annotation.getText(); } setStatusLineErrorMessage(null); setStatusLineMessage(message); }
Example 10
Source File: AnnotationExpansionControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void computeInformation() { if (fSelection != null) { Rectangle subjectArea= fSelection.canvas.getBounds(); Annotation annotation= fSelection.fAnnotation; String msg; if (annotation != null) msg= annotation.getText(); else msg= null; setInformation(msg, subjectArea); } }
Example 11
Source File: AbstractAnnotationHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText= annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 12
Source File: AbstractAnnotationHover.java From goclipse with Eclipse Public License 1.0 | 5 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); String annotationText= annotation.getText(); if (annotationText != null) text.setText(annotationText); }
Example 13
Source File: AbstractAnnotationHover.java From typescript.java with MIT License | 4 votes |
@Override public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { IPath path; IAnnotationModel model; if (textViewer instanceof ISourceViewer) { path = null; model = ((ISourceViewer) textViewer).getAnnotationModel(); } else { // Get annotation model from file buffer manager path = getEditorInputPath(); model = getAnnotationModel(path); } if (model == null) return null; try { Iterator<Annotation> parent; if (model instanceof IAnnotationModelExtension2) parent = ((IAnnotationModelExtension2) model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength() > 0 ? hoverRegion.getLength() : 1, true, true); else parent = model.getAnnotationIterator(); Iterator<Annotation> e = new TypeScriptAnnotationIterator(parent, fAllAnnotations); int layer = -1; Annotation annotation = null; Position position = null; while (e.hasNext()) { Annotation a = e.next(); AnnotationPreference preference = getAnnotationPreference(a); if (preference == null || !(preference.getTextPreferenceKey() != null /* * && fStore.getBoolean(preference.getTextPreferenceKey()) || * (preference.getHighlightPreferenceKey() != null && * fStore.getBoolean(preference.getHighlightPreferenceKey())) */)) continue; Position p = model.getPosition(a); int l = fAnnotationAccess.getLayer(a); if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { String msg = a.getText(); if (msg != null && msg.trim().length() > 0) { layer = l; annotation = a; position = p; } } } if (layer > -1) return createAnnotationInfo(annotation, position, textViewer); } finally { try { if (path != null) { ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager(); manager.disconnect(path, LocationKind.NORMALIZE, null); } } catch (CoreException ex) { TypeScriptUIPlugin.log(ex.getStatus()); } } return null; }
Example 14
Source File: AbstractAnnotationHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { IPath path; IAnnotationModel model; if (textViewer instanceof ISourceViewer) { path= null; model= ((ISourceViewer)textViewer).getAnnotationModel(); } else { // Get annotation model from file buffer manager path= getEditorInputPath(); model= getAnnotationModel(path); } if (model == null) return null; try { Iterator<Annotation> parent; if (model instanceof IAnnotationModelExtension2) parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true); else parent= model.getAnnotationIterator(); Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations); int layer= -1; Annotation annotation= null; Position position= null; while (e.hasNext()) { Annotation a= e.next(); AnnotationPreference preference= getAnnotationPreference(a); if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey())))) continue; Position p= model.getPosition(a); int l= fAnnotationAccess.getLayer(a); if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { String msg= a.getText(); if (msg != null && msg.trim().length() > 0) { layer= l; annotation= a; position= p; } } } if (layer > -1) return createAnnotationInfo(annotation, position, textViewer); } finally { try { if (path != null) { ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); manager.disconnect(path, LocationKind.NORMALIZE, null); } } catch (CoreException ex) { JavaPlugin.log(ex.getStatus()); } } return null; }
Example 15
Source File: AbstractAnnotationHover.java From goclipse with Eclipse Public License 1.0 | 4 votes |
@Override public Object getHoverInfo(ISourceBuffer sourceBuffer, IRegion hoverRegion, ITextViewer textViewer) { if (!(textViewer instanceof ISourceViewer)) { return null; } ISourceViewer sourceViewer = (ISourceViewer) textViewer; // IPath path = null; IAnnotationModel model = sourceViewer.getAnnotationModel(); // if (editor.getSourceViewer_() instanceof ISourceViewer) { // path= null; // model= editor.getSourceViewer_().getAnnotationModel(); // } else { // // Get annotation model from file buffer manager // path= getEditorInputPath(); // model= getAnnotationModel(path); // } if (model == null) return null; // try { Iterator<Annotation> parent; if (model instanceof IAnnotationModelExtension2) parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true); else parent= model.getAnnotationIterator(); Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations); int layer= -1; Annotation annotation= null; Position position= null; while (e.hasNext()) { Annotation a= e.next(); AnnotationPreference preference= getAnnotationPreference(a); if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey())))) continue; Position p= model.getPosition(a); int l= fAnnotationAccess.getLayer(a); if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { String msg= a.getText(); if (msg != null && msg.trim().length() > 0) { layer= l; annotation= a; position= p; } } } if (layer > -1) return createAnnotationInfo(annotation, position, textViewer); // } finally { // try { // if (path != null) { // ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); // manager.disconnect(path, LocationKind.NORMALIZE, null); // } // } catch (CoreException ex) { // LangUIPlugin.logStatus(ex); // } // } return null; }