org.eclipse.jface.text.source.Annotation Java Examples

The following examples show how to use org.eclipse.jface.text.source.Annotation. 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: TypeScriptAnnotationIterator.java    From typescript.java with MIT License 6 votes vote down vote up
private void skip() {
	while (fIterator.hasNext()) {
		Annotation next = (Annotation) fIterator.next();
		if (isTypeScriptAnnotation(next) || next instanceof IQuickFixableAnnotation) {
			if (fSkipIrrelevants) {
				if (!next.isMarkedDeleted()) {
					fNext = next;
					return;
				}
			} else {
				fNext = next;
				return;
			}
		} else if (fReturnAllAnnotations) {
			fNext = next;
			return;
		}
	}
	fNext = null;
}
 
Example #2
Source File: JavaCorrectionAssistant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static int processAnnotation(Annotation annot, Position pos, int invocationLocation, int bestOffset) {
	int posBegin= pos.offset;
	int posEnd= posBegin + pos.length;
	if (isInside(invocationLocation, posBegin, posEnd) && JavaCorrectionProcessor.hasCorrections(annot)) { // covers invocation location?
		return invocationLocation;
	} else if (bestOffset != invocationLocation) {
		int newClosestPosition= computeBestOffset(posBegin, invocationLocation, bestOffset);
		if (newClosestPosition != -1) {
			if (newClosestPosition != bestOffset) { // new best
				if (JavaCorrectionProcessor.hasCorrections(annot)) { // only jump to it if there are proposals
					return newClosestPosition;
				}
			}
		}
	}
	return bestOffset;
}
 
Example #3
Source File: AbstractProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testAnnotationOnMultipleLines() throws Exception {
	IMarker warning = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	warning.setAttribute(IMarker.LOCATION, "line: 1 " + file.getFullPath().toString());
	warning.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
	warning.setAttribute(IMarker.CHAR_START, 0);
	warning.setAttribute(IMarker.CHAR_END, 43);
	warning.setAttribute(IMarker.LINE_NUMBER, 1);
	warning.setAttribute(IMarker.MESSAGE, "Foo");
	
	List<Annotation> annotations = hover.getAnnotations(1, 40);
	assertEquals(2, annotations.size());
	// The error is on the same line as the requested position, so it should be returned first
	assertEquals("org.eclipse.xtext.ui.editor.error", annotations.get(0).getType());
	assertEquals("org.eclipse.xtext.ui.editor.warning", annotations.get(1).getType());
	
	warning.delete();
}
 
Example #4
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void updateMarkerViews(Annotation annotation) {
	if (annotation instanceof IJavaAnnotation) {
		Iterator<IJavaAnnotation> e= ((IJavaAnnotation) annotation).getOverlaidIterator();
		if (e != null) {
			while (e.hasNext()) {
				Object o= e.next();
				if (o instanceof MarkerAnnotation) {
					super.updateMarkerViews((MarkerAnnotation)o);
					return;
				}
			}
		}
		return;
	}
	super.updateMarkerViews(annotation);
}
 
Example #5
Source File: TextColorDrawingStrategy.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int start, int length, Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      if (gc != null) {

        int end = start + length - 1;

        Rectangle bounds = textWidget.getTextBounds(start, end);

        gc.setForeground(color);

        gc.drawText(textWidget.getText(start, end), bounds.x, bounds.y, true);

      } else {
        textWidget.redrawRange(start, length, true);
      }
    }
  }
}
 
Example #6
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int getErrorTicksFromAnnotationModel(IAnnotationModel model, ISourceReference sourceElement) throws CoreException {
	int info= 0;
	Iterator<Annotation> iter= model.getAnnotationIterator();
	while ((info != ERRORTICK_ERROR) && iter.hasNext()) {
		Annotation annot= iter.next();
		IMarker marker= isAnnotationInRange(model, annot, sourceElement);
		if (marker != null) {
			int priority= marker.getAttribute(IMarker.SEVERITY, -1);
			if (priority == IMarker.SEVERITY_WARNING) {
				info= ERRORTICK_WARNING;
			} else if (priority == IMarker.SEVERITY_ERROR) {
				info= ERRORTICK_ERROR;
			}
		}
	}
	return info;
}
 
Example #7
Source File: DirtyStateEditorValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 #8
Source File: AnnotationExpandHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void sort(List<Annotation> exact, final IAnnotationModel model) {
	class AnnotationComparator implements Comparator<Annotation> {

		/*
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Annotation a1, Annotation a2) {
			Position p1= model.getPosition(a1);
			Position p2= model.getPosition(a2);

			// annotation order:
			// primary order: by position in line
			// secondary: annotation importance
			if (p1.offset == p2.offset)
				return getOrder(a2) - getOrder(a1);
			return p1.offset - p2.offset;
		}
	}

	Collections.sort(exact, new AnnotationComparator());

}
 
Example #9
Source File: ModulaSpellingHover.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private HoverInfoWithSpellingAnnotation getSpellingHover(ITextViewer textViewer, IRegion hoverRegion) {
    IAnnotationModel model= null;
    if (textViewer instanceof ISourceViewerExtension2) {
        model = ((ISourceViewerExtension2)textViewer).getVisualAnnotationModel();
    } else if (textViewer instanceof SourceViewer) {
        model= ((SourceViewer)textViewer).getAnnotationModel();
    }
    if (model != null) {
        @SuppressWarnings("rawtypes")
        Iterator e= model.getAnnotationIterator();
        while (e.hasNext()) {
            Annotation a= (Annotation) e.next();
            if (a instanceof SpellingAnnotation) {
                Position p= model.getPosition(a);
                if (p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
                    return new HoverInfoWithSpellingAnnotation((SpellingAnnotation)a, textViewer, p.getOffset());
                }
            }
        }
    }
    return null;
}
 
Example #10
Source File: ScriptValidator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Clears all annotations.
 */
private void clearAnnotations( )
{
	IAnnotationModel annotationModel = scriptViewer.getAnnotationModel( );

	if ( annotationModel != null )
	{
		for ( Iterator iterator = annotationModel.getAnnotationIterator( ); iterator.hasNext( ); )
		{
			Annotation annotation = (Annotation) iterator.next( );

			if ( annotation != null &&
					IReportGraphicConstants.ANNOTATION_ERROR.equals( annotation.getType( ) ) )
			{
				annotationModel.removeAnnotation( annotation );
			}
		}
	}
}
 
Example #11
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected void updateMarkerAnnotation(IMarker marker) {
	
	Iterator<Annotation> iter = annotationModel.getAnnotationIterator();
	
	for (Annotation ann : (Iterable<Annotation>) () -> iter) {
		if(ann instanceof MarkerAnnotation) {
			MarkerAnnotation markerAnnotation = (MarkerAnnotation) ann;
			if(markerAnnotation.getMarker().equals(marker)) {
				
				Position position = annotationModel.getPosition(markerAnnotation);
				
				// Trigger a model update.
				annotationModelExt.modifyAnnotationPosition(markerAnnotation, position);
				
				return;
			}
		}
	}
}
 
Example #12
Source File: CorrectionMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IProblemLocation findProblemLocation(IEditorInput input, IMarker marker) {
	IAnnotationModel model= JavaPlugin.getDefault().getCompilationUnitDocumentProvider().getAnnotationModel(input);
	if (model != null) { // open in editor
		Iterator<Annotation> iter= model.getAnnotationIterator();
		while (iter.hasNext()) {
			Annotation curr= iter.next();
			if (curr instanceof JavaMarkerAnnotation) {
				JavaMarkerAnnotation annot= (JavaMarkerAnnotation) curr;
				if (marker.equals(annot.getMarker())) {
					Position pos= model.getPosition(annot);
					if (pos != null) {
						return new ProblemLocation(pos.getOffset(), pos.getLength(), annot);
					}
				}
			}
		}
	} else { // not open in editor
		ICompilationUnit cu= getCompilationUnit(marker);
		return createFromMarker(marker, cu);
	}
	return null;
}
 
Example #13
Source File: TLAProofFoldingStructureProvider.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Collapses all proofs.
 * 
 * @param cursorOffset
 */
private void foldAllProofs()
{
    Vector<Annotation> modifiedAnnotations = new Vector<Annotation>();
    for (Iterator<TLAProofPosition> it = foldPositions.iterator(); it.hasNext();)
    {
        TLAProofPosition proofPosition = it.next();
        if (!proofPosition.getAnnotation().isCollapsed())
        {
            // should fold every proof
            // so that only theorem statements are shown
            proofPosition.getAnnotation().markCollapsed();
            modifiedAnnotations.add(proofPosition.getAnnotation());
        }
    }

    editor.modifyProjectionAnnotations((Annotation[]) modifiedAnnotations
            .toArray(new ProjectionAnnotation[modifiedAnnotations.size()]));
}
 
Example #14
Source File: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public int getLayer(Annotation annotation) {

  if (annotation instanceof EclipseAnnotationPeer) {

    EclipseAnnotationPeer eclipseAnnotation = (EclipseAnnotationPeer) annotation;

    // ask document provider for this
    // getAnnotation must be added to cas document provider

    AnnotationStyle style = getAnnotationStyle(
        eclipseAnnotation.getAnnotationFS().getType());

    return style.getLayer();
  }
  else {
    return 0;
  }
}
 
Example #15
Source File: LocationAnnotationManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes all selection-related annotations of a user inside the given {@link IEditorPart}.
 *
 * @param user The originator of the annotations to be deleted.
 * @param editorPart
 */
public void clearSelectionForUser(final User user, IEditorPart editorPart) {
  IAnnotationModel model = annotationModelHelper.retrieveAnnotationModel(editorPart);

  if (model == null) {
    return;
  }

  annotationModelHelper.removeAnnotationsFromModel(
      model,
      new Predicate<Annotation>() {
        @Override
        public boolean evaluate(Annotation annotation) {
          return (annotation instanceof SelectionAnnotation
                  || annotation instanceof SelectionFillUpAnnotation
                  || annotation instanceof RemoteCursorAnnotation)
              && ((SarosAnnotation) annotation).getSource().equals(user);
        }
      });
}
 
Example #16
Source File: IndentFoldingStrategy.java    From typescript.java with MIT License 6 votes vote down vote up
/**
 * <p>
 * Searches the given {@link DirtyRegion} for annotations that now have a
 * length of 0. This is caused when something that was being folded has been
 * deleted. These {@link FoldingAnnotation}s are then added to the
 * {@link List} of {@link FoldingAnnotation}s to be deleted
 * </p>
 * 
 * @param dirtyRegion
 *            find the now invalid {@link FoldingAnnotation}s in this
 *            {@link DirtyRegion}
 * @param deletions
 *            the current list of {@link FoldingAnnotation}s marked for
 *            deletion that the newly found invalid
 *            {@link FoldingAnnotation}s will be added to
 */
protected void markInvalidAnnotationsForDeletion(DirtyRegion dirtyRegion, List<FoldingAnnotation> deletions,
		List<FoldingAnnotation> existing) {
	Iterator iter = getAnnotationIterator(dirtyRegion);
	if (iter != null) {
		while (iter.hasNext()) {
			Annotation anno = (Annotation) iter.next();
			if (anno instanceof FoldingAnnotation) {
				FoldingAnnotation folding = (FoldingAnnotation) anno;
				Position pos = projectionAnnotationModel.getPosition(anno);
				if (pos.length == 0) {
					deletions.add(folding);
				} else {
					existing.add(folding);
				}
			}
		}
	}
}
 
Example #17
Source File: TLAProofFoldingStructureProvider.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Folds all proofs not containing the cursor.
 * 
 * Note that this will fold every proof if the cursor
 * is not in a proof.
 * 
 * @param cursorOffset
 */
private void foldEverythingUnusable(int cursorOffset)
{
    Vector<Annotation> modifiedAnnotations = new Vector<Annotation>();
    for (Iterator<TLAProofPosition> it = foldPositions.iterator(); it.hasNext();)
    {
        TLAProofPosition proofPosition = it.next();
        try
        {
            if (proofPosition.containsInProofOrStatement(cursorOffset, document))
            {
                if (proofPosition.getAnnotation().isCollapsed())
                {
                    proofPosition.getAnnotation().markExpanded();
                    modifiedAnnotations.add(proofPosition.getAnnotation());
                }
            } else if (!proofPosition.getAnnotation().isCollapsed())
            {
                proofPosition.getAnnotation().markCollapsed();
                modifiedAnnotations.add(proofPosition.getAnnotation());
            }
        } catch (BadLocationException e)
        {
            Activator.getDefault().logError("Error changing expansion state of proofs.", e);
        }
    }

    editor.modifyProjectionAnnotations((Annotation[]) modifiedAnnotations
            .toArray(new ProjectionAnnotation[modifiedAnnotations.size()]));
}
 
Example #18
Source File: JavaAnnotationImageProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Image getImage(IJavaAnnotation annotation, int imageType) {
	if ((imageType == QUICKFIX_IMAGE || imageType == QUICKFIX_ERROR_IMAGE) && fCachedImageType == imageType)
		return fCachedImage;

	Image image= null;
	switch (imageType) {
		case OVERLAY_IMAGE:
			IJavaAnnotation overlay= annotation.getOverlay();
			image= getManagedImage((Annotation) overlay);
			fCachedImageType= -1;
			break;
		case QUICKFIX_IMAGE:
			image= getQuickFixImage();
			fCachedImageType= imageType;
			fCachedImage= image;
			break;
		case QUICKFIX_ERROR_IMAGE:
			image= getQuickFixErrorImage();
			fCachedImageType= imageType;
			fCachedImage= image;
			break;
		case GRAY_IMAGE: {
			String annotationType= annotation.getType();
			if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotationType)) {
				image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ERROR_ALT);
			} else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(annotationType)) {
				image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_WARNING_ALT);
			} else if (JavaMarkerAnnotation.INFO_ANNOTATION_TYPE.equals(annotationType)) {
				image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INFO_ALT);
			}
			fCachedImageType= -1;
			break;
		}
	}

	return image;
}
 
Example #19
Source File: OverrideIndicatorModelListener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Map<Annotation, Position> createOverrideIndicatorAnnotationMap(XtextResource xtextResource, CancelIndicator cancelIndicator) {
	List<EObject> contents = xtextResource.getContents();
	if (contents.isEmpty())
		return Maps.newHashMap();
	EObject eObject = contents.get(0);
	if (!(eObject instanceof XtendFile)) {
		return Maps.newHashMap();
	}
	XtendFile xtendFile = (XtendFile) eObject;
	Map<Annotation, Position> annotationToPosition = Maps.newHashMap();
	for (XtendFunction xtendFunction : getXtendFunctions(xtendFile)) {
		if(cancelIndicator.isCanceled())
			throw new OperationCanceledException();
		if (xtendFunction.isOverride()) {
			typeResolver.resolveTypes(xtendFunction);
			INode node = NodeModelUtils.getNode(xtendFunction);
			JvmOperation inferredOperation = associations.getDirectlyInferredOperation(xtendFunction);
			if (inferredOperation != null) {
				JvmOperation jvmOperation = overrideHelper.findOverriddenOperation(inferredOperation);
				if (node != null && jvmOperation != null) {
					boolean overwriteIndicator = isOverwriteIndicator(jvmOperation);
					String text = (overwriteIndicator ? "overrides " : "implements ") + jvmOperation.getQualifiedName(); //$NON-NLS-1$ //$NON-NLS-2$
					node = getFirst(findNodesForFeature(xtendFunction, XtendPackage.eINSTANCE.getXtendFunction_Name()),
							node);
					annotationToPosition.put(
							new OverrideIndicatorAnnotation(overwriteIndicator, text, xtextResource
									.getURIFragment(xtendFunction)), new Position(node.getOffset()));
				}
			}
		}
	}
	return annotationToPosition;
}
 
Example #20
Source File: CommonAnnotationHover.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public int compare(Annotation o1, Annotation o2)
{
	if (o1 instanceof SimpleMarkerAnnotation && o2 instanceof SimpleMarkerAnnotation)
	{
		// Compare the marker offset first. In case it was not set with an offset, compare via the line numbers.
		IMarker m1 = ((SimpleMarkerAnnotation) o1).getMarker();
		IMarker m2 = ((SimpleMarkerAnnotation) o2).getMarker();
		if (m1 != null && m2 != null)
		{
			// try comparing by offset
			int pos1 = m1.getAttribute(IMarker.CHAR_START, -1);
			int pos2 = m2.getAttribute(IMarker.CHAR_START, -1);
			if (pos1 > -1 && pos2 > -1)
			{
				return pos1 - pos2;
			}
			// in case one of the char-start values was not set, try comparing using the line number
			pos1 = m1.getAttribute(IMarker.LINE_NUMBER, -1);
			pos2 = m2.getAttribute(IMarker.LINE_NUMBER, -1);
			if (pos1 > -1 && pos2 > -1)
			{
				return pos1 - pos2;
			}
		}
	}
	// just return 0, as we can't really compare those.
	return 0;
}
 
Example #21
Source File: CorrectionCommandHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) {
	AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength());
	Collection<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>(10);
	if (isAssist) {
		if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) {
			return getLocalRenameProposal(context); // shortcut for local rename
		}
		JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals);
	} else {
		try {
			boolean goToClosest= selection.getLength() == 0;
			Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest);
			JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals);
		} catch (BadLocationException e) {
			return null;
		}
	}
	for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) {
		Object curr= iter.next();
		if (curr instanceof ICommandAccess) {
			if (id.equals(((ICommandAccess) curr).getCommandId())) {
				return (ICompletionProposal) curr;
			}
		}
	}
	return null;
}
 
Example #22
Source File: DefaultFoldingStructureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateFoldingRegions(boolean allowCollapse, ProjectionAnnotationModel model,
		Collection<FoldedPosition> foldedPositions, Annotation[] deletions) {
	Map<ProjectionAnnotation, Position> additionsMap = Maps.newHashMap();
	for (FoldedPosition foldedPosition: foldedPositions) {
		addProjectionAnnotation(allowCollapse, foldedPosition, additionsMap);
	}
	if (deletions.length != 0 || additionsMap.size() != 0) {
		model.modifyAnnotations(deletions, additionsMap, new Annotation[] {});
	}
}
 
Example #23
Source File: OverrideIndicatorImageProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getImageDescriptorId(Annotation annotation) {
	if (!(annotation instanceof OverrideIndicatorAnnotation)) {
		return null;
	}
	OverrideIndicatorAnnotation overrideIndicatorAnnotation = (OverrideIndicatorAnnotation) annotation;
	return overrideIndicatorAnnotation.isOverwriteIndicator() ? OVERRIDE_IMG_DESC_ID : IMPLEMENTS_IMG_DESC_ID;
}
 
Example #24
Source File: DefaultFoldingStructureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void calculateProjectionAnnotationModel(boolean allowCollapse) {
	ProjectionAnnotationModel projectionAnnotationModel = this.viewer.getProjectionAnnotationModel();
	if (projectionAnnotationModel != null) {
		// make a defensive copy as we modify the folded positions in subsequent operations
		Collection<FoldedPosition> foldedPositions = Sets.newLinkedHashSet(foldingRegionProvider.getFoldingRegions(editor.getDocument()));
		foldedPositions = filterFoldedPositions(foldedPositions);
		Annotation[] newRegions = mergeFoldingRegions(foldedPositions, projectionAnnotationModel);
		updateFoldingRegions(allowCollapse, projectionAnnotationModel, foldedPositions, newRegions);
	}
}
 
Example #25
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 5 votes vote down vote up
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 #26
Source File: CodeFoldingSetter.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Given the ast, create the needed marks and set them in the passed model.
 */
private synchronized void addMarksToModel(SimpleNode root2, ProjectionAnnotationModel model) {
    try {
        if (model != null) {
            ArrayList<Annotation> existing = new ArrayList<Annotation>();

            //get the existing annotations
            Iterator<Annotation> iter = model.getAnnotationIterator();
            while (iter != null && iter.hasNext()) {
                Annotation element = iter.next();
                existing.add(element);
            }

            //now, remove the annotations not used and add the new ones needed
            IDocument doc = editor.getDocument();
            if (doc != null) { //this can happen if we change the input of the editor very quickly.
                boolean foldInitial = initialFolding;
                initialFolding = false;
                List<FoldingEntry> marks = getMarks(doc, root2, foldInitial);
                Map<ProjectionAnnotation, Position> annotationsToAdd;
                if (marks.size() > OptimizationRelatedConstants.MAXIMUM_NUMBER_OF_CODE_FOLDING_MARKS) {
                    annotationsToAdd = new HashMap<ProjectionAnnotation, Position>();

                } else {
                    annotationsToAdd = getAnnotationsToAdd(marks, model, existing);
                }

                model.replaceAnnotations(existing.toArray(new Annotation[existing.size()]), annotationsToAdd);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}
 
Example #27
Source File: JavaAnnotationIterator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void skip() {
	while (fIterator.hasNext()) {
		Annotation next= fIterator.next();

		if (next.isMarkedDeleted())
			continue;

		if (fReturnAllAnnotations || next instanceof IJavaAnnotation || isProblemMarkerAnnotation(next)) {
			fNext= next;
			return;
		}
	}
	fNext= null;
}
 
Example #28
Source File: ProblemAnnotationHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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 #29
Source File: AbstractLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
	return new HTMLAnnotationHover(true) {
		@Override
		protected boolean isIncluded(Annotation annotation) {
			return isShowInOverviewRuler(annotation);
		}
	};
}
 
Example #30
Source File: IndentFoldingStrategy.java    From typescript.java with MIT License 5 votes vote down vote up
private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnotation> deletions,
		List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int line, int endLineNumber)
		throws BadLocationException {
	int startOffset = document.getLineOffset(line);
	int endOffset = document.getLineOffset(endLineNumber) + document.getLineLength(endLineNumber);
	Position newPos = new Position(startOffset, endOffset - startOffset);
	if (existing.size() > 0) {
		FoldingAnnotation existingAnnotation = existing.remove(existing.size() - 1);
		updateAnnotations(existingAnnotation, newPos, additions, modifications, deletions);
	} else {
		additions.put(new FoldingAnnotation(false), newPos);
	}
}