Search in sources :

Example 86 with IMarker

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

the class MarkerAnnotation method initialize.

/**
 * Initializes the annotation's icon representation and its drawing layer
 * based upon the properties of the underlying marker.
 *
 * @deprecated As of 3.0, visual presentation is no longer supported,
 *             annotation with a visible presentation should implement
 *             {@link org.eclipse.jface.text.source.IAnnotationPresentation}
 */
@Deprecated
protected void initialize() {
    IMarker marker = getMarker();
    String name = getUnknownImageName(marker);
    if (MarkerUtilities.isMarkerType(marker, IMarker.TASK)) {
        name = IDE.SharedImages.IMG_OBJS_TASK_TSK;
    } else if (MarkerUtilities.isMarkerType(marker, IMarker.BOOKMARK)) {
        name = IDE.SharedImages.IMG_OBJS_BKMRK_TSK;
    } else if (MarkerUtilities.isMarkerType(marker, IMarker.PROBLEM)) {
        switch(MarkerUtilities.getSeverity(marker)) {
            case IMarker.SEVERITY_INFO:
                name = ISharedImages.IMG_OBJS_INFO_TSK;
                break;
            case IMarker.SEVERITY_WARNING:
                name = ISharedImages.IMG_OBJS_WARN_TSK;
                break;
            case IMarker.SEVERITY_ERROR:
                name = ISharedImages.IMG_OBJS_ERROR_TSK;
                break;
        }
    }
    fImage = null;
    fImageName = name;
}
Also used : IMarker(org.eclipse.core.resources.IMarker)

Example 87 with IMarker

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

the class MarkerRulerAction method removeMarkers.

/**
 * Removes the given markers.
 *
 * @param markers the markers to be deleted
 */
protected void removeMarkers(final List<? extends IMarker> markers) {
    IMarker[] markersArray = markers.toArray(new IMarker[markers.size()]);
    execute(new DeleteMarkersOperation(markersArray, getOperationName()));
}
Also used : DeleteMarkersOperation(org.eclipse.ui.ide.undo.DeleteMarkersOperation) IMarker(org.eclipse.core.resources.IMarker)

Example 88 with IMarker

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

the class MarkerRulerAction method getMarkers.

/**
 * Returns all markers which include the ruler's line of activity.
 *
 * @return all a list of markers which include the ruler's line of activity
 */
protected List<IMarker> getMarkers() {
    List<IMarker> markers = new ArrayList<>();
    IResource resource = getResource();
    IDocument document = getDocument();
    AbstractMarkerAnnotationModel model = getAnnotationModel();
    if (resource != null && model != null && resource.exists()) {
        try {
            IMarker[] allMarkers = resource.findMarkers(fMarkerType, true, IResource.DEPTH_ZERO);
            if (allMarkers != null) {
                for (int i = 0; i < allMarkers.length; i++) {
                    if (includesRulerLine(model.getMarkerPosition(allMarkers[i]), document)) {
                        markers.add(allMarkers[i]);
                    }
                }
            }
        } catch (CoreException x) {
            handleCoreException(x, TextEditorMessages.MarkerRulerAction_getMarker);
        }
    }
    return markers;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument)

Example 89 with IMarker

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

the class MarkerUtilities method createMarker.

/**
 * Creates a marker on the given resource with the given type and attributes.
 * <p>
 * This method modifies the workspace (progress is not reported to the user).</p>
 *
 * @param resource the resource
 * @param attributes the attribute map
 * @param markerType the type of marker
 * @throws CoreException if this method fails
 * @see IResource#createMarker(java.lang.String)
 */
public static void createMarker(final IResource resource, final Map<String, Object> attributes, final String markerType) throws CoreException {
    IWorkspaceRunnable r = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            IMarker marker = resource.createMarker(markerType);
            marker.setAttributes(attributes);
        }
    };
    resource.getWorkspace().run(r, null, IWorkspace.AVOID_UPDATE, null);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IMarker(org.eclipse.core.resources.IMarker)

Example 90 with IMarker

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

the class SelectMarkerRulerAction method getMarkers.

/**
 * Returns all markers which include the ruler's line of activity.
 *
 * @return an unmodifiable list with all markers which include the ruler's line of activity
 */
protected final List<IMarker> getMarkers() {
    final IResource resource = getResource();
    if (resource == null || !resource.exists())
        return Collections.emptyList();
    final IDocument document = getDocument();
    if (document == null)
        return Collections.emptyList();
    final AbstractMarkerAnnotationModel model = getAnnotationModel();
    if (model == null)
        return Collections.emptyList();
    final IMarker[] allMarkers;
    try {
        allMarkers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
    } catch (CoreException x) {
        handleCoreException(x, TextEditorMessages.SelectMarkerRulerAction_getMarker);
        return Collections.emptyList();
    }
    if (allMarkers.length == 0)
        return Collections.emptyList();
    final int activeLine = fRuler.getLineOfLastMouseButtonActivity();
    if (activeLine == -1)
        return Collections.emptyList();
    Iterator<Annotation> it;
    try {
        IRegion line = document.getLineInformation(activeLine);
        it = model.getAnnotationIterator(line.getOffset(), line.getLength() + 1, true, true);
    } catch (BadLocationException e) {
        Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
        Platform.getLog(bundle).log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e));
        it = model.getAnnotationIterator();
    }
    List<IMarker> markers = null;
    while (it.hasNext()) {
        Annotation annotation = it.next();
        if (annotation instanceof MarkerAnnotation) {
            Position position = model.getPosition(annotation);
            if (includesLine(position, document, activeLine)) {
                if (markers == null)
                    markers = new ArrayList<>(10);
                markers.add(((MarkerAnnotation) annotation).getMarker());
            }
        }
    }
    if (markers == null)
        return Collections.emptyList();
    return Collections.unmodifiableList(markers);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Position(org.eclipse.jface.text.Position) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) Annotation(org.eclipse.jface.text.source.Annotation) IRegion(org.eclipse.jface.text.IRegion) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

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