Search in sources :

Example 16 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class SearchResultViewer method isPotentialMatchSelected.

private boolean isPotentialMatchSelected() {
    if (getSelectedEntriesCount() == 0)
        return false;
    Iterator<?> iter = Collections.emptyList().iterator();
    ISelection selection = getSelection();
    if (selection instanceof IStructuredSelection)
        iter = ((IStructuredSelection) selection).iterator();
    while (iter.hasNext()) {
        Object entry = iter.next();
        if (entry instanceof ISearchResultViewEntry) {
            IMarker marker = ((ISearchResultViewEntry) entry).getSelectedMarker();
            if (marker != null && marker.getAttribute(SearchUI.POTENTIAL_MATCH, false))
                return true;
        }
    }
    return false;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMarker(org.eclipse.core.resources.IMarker) ISearchResultViewEntry(org.eclipse.search.ui.ISearchResultViewEntry)

Example 17 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method updateMarkerViews.

/**
 * Updates visible views that show markers.
 * <p>
 * If the given annotation can be associated with a marker then this method tries select the
 * this marker in views that show markers.
 * </p>
 *
 * @param annotation the annotation
 * @since 3.2
 */
protected void updateMarkerViews(Annotation annotation) {
    if (fIsComingFromGotoMarker) {
        fIsComingFromGotoMarker = false;
        return;
    }
    IMarker marker = null;
    if (annotation instanceof MarkerAnnotation)
        marker = ((MarkerAnnotation) annotation).getMarker();
    if (marker != null) {
        try {
            fIsUpdatingMarkerViews = true;
            IWorkbenchPage page = getSite().getPage();
            MarkerViewUtil.showMarker(page, marker, false);
        } finally {
            fIsUpdatingMarkerViews = false;
        }
    }
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker)

Example 18 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class AbstractMarkerAnnotationModel method removeAnnotations.

@Override
protected void removeAnnotations(List<? extends Annotation> annotations, boolean fireModelChanged, boolean modelInitiated) {
    if (annotations != null && annotations.size() > 0) {
        List<Annotation> markerAnnotations = new ArrayList<>();
        for (Iterator<? extends Annotation> e = annotations.iterator(); e.hasNext(); ) {
            Annotation a = e.next();
            if (a instanceof MarkerAnnotation)
                markerAnnotations.add(a);
            // remove annotations from annotation model
            removeAnnotation(a, false);
        }
        if (markerAnnotations.size() > 0) {
            if (modelInitiated) {
                // if model initiated also remove it from the marker manager
                listenToMarkerChanges(false);
                try {
                    IMarker[] m = new IMarker[markerAnnotations.size()];
                    for (int i = 0; i < m.length; i++) {
                        MarkerAnnotation ma = (MarkerAnnotation) markerAnnotations.get(i);
                        m[i] = ma.getMarker();
                    }
                    deleteMarkers(m);
                } catch (CoreException x) {
                    handleCoreException(x, TextEditorMessages.AbstractMarkerAnnotationModel_removeAnnotations);
                }
                listenToMarkerChanges(true);
            } else {
                // remember deleted annotations in order to remove their markers later on
                fDeletedAnnotations.addAll(markerAnnotations);
            }
        }
        if (fireModelChanged)
            fireModelChanged();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IMarker(org.eclipse.core.resources.IMarker) Annotation(org.eclipse.jface.text.source.Annotation) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 19 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class AbstractMarkerAnnotationModel method updateMarkers.

/**
 * Updates the markers managed by this annotation model by calling
 * all registered marker updaters (<code>IMarkerUpdater</code>).
 *
 * @param document the document to which this model is currently connected
 * @throws CoreException if there is a problem updating the markers
 */
public void updateMarkers(IDocument document) throws CoreException {
    Assert.isTrue(fDocument == document);
    IAnnotationMap annotationMap = getAnnotationMap();
    if (annotationMap.size() == 0 && fDeletedAnnotations.size() == 0)
        return;
    if (fMarkerUpdaterSpecifications == null)
        installMarkerUpdaters();
    listenToMarkerChanges(false);
    try {
        // update all markers with the positions known by the annotation model
        for (Iterator<Annotation> e = getAnnotationIterator(false); e.hasNext(); ) {
            Object o = e.next();
            if (o instanceof MarkerAnnotation) {
                MarkerAnnotation a = (MarkerAnnotation) o;
                IMarker marker = a.getMarker();
                Position position = annotationMap.get(a);
                if (!updateMarker(marker, document, position)) {
                    if (!fDeletedAnnotations.contains(a))
                        fDeletedAnnotations.add(a);
                }
            }
        }
        if (!fDeletedAnnotations.isEmpty()) {
            removeAnnotations(fDeletedAnnotations, true, true);
            fDeletedAnnotations.clear();
        }
    } finally {
        listenToMarkerChanges(true);
    }
}
Also used : Position(org.eclipse.jface.text.Position) IMarker(org.eclipse.core.resources.IMarker) IAnnotationMap(org.eclipse.jface.text.source.IAnnotationMap) Annotation(org.eclipse.jface.text.source.Annotation)

Example 20 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class ResourceMarkerAnnotationModel method batchedUpdate.

/**
 * Updates this model to the given marker deltas.
 *
 * @param markerDeltas the array of marker deltas
 */
private void batchedUpdate(IMarkerDelta[] markerDeltas) {
    HashSet<IMarker> removedMarkers = new HashSet<>(markerDeltas.length);
    HashSet<IMarker> modifiedMarkers = new HashSet<>(markerDeltas.length);
    for (int i = 0; i < markerDeltas.length; i++) {
        IMarkerDelta delta = markerDeltas[i];
        switch(delta.getKind()) {
            case IResourceDelta.ADDED:
                addMarkerAnnotation(delta.getMarker());
                break;
            case IResourceDelta.REMOVED:
                removedMarkers.add(delta.getMarker());
                break;
            case IResourceDelta.CHANGED:
                modifiedMarkers.add(delta.getMarker());
                break;
        }
    }
    if (modifiedMarkers.isEmpty() && removedMarkers.isEmpty())
        return;
    Iterator<Annotation> e = getAnnotationIterator(false);
    while (e.hasNext()) {
        Object o = e.next();
        if (o instanceof MarkerAnnotation) {
            MarkerAnnotation a = (MarkerAnnotation) o;
            IMarker marker = a.getMarker();
            if (removedMarkers.remove(marker))
                removeAnnotation(a, false);
            if (modifiedMarkers.remove(marker)) {
                Position p = createPositionFromMarker(marker);
                if (p != null) {
                    a.update();
                    modifyAnnotationPosition(a, p, false);
                }
            }
            if (modifiedMarkers.isEmpty() && removedMarkers.isEmpty())
                return;
        }
    }
    Iterator<IMarker> iter = modifiedMarkers.iterator();
    while (iter.hasNext()) addMarkerAnnotation(iter.next());
}
Also used : Position(org.eclipse.jface.text.Position) IMarker(org.eclipse.core.resources.IMarker) IMarkerDelta(org.eclipse.core.resources.IMarkerDelta) Annotation(org.eclipse.jface.text.source.Annotation) HashSet(java.util.HashSet)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5