Search in sources :

Example 91 with IMarker

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

the class SelectMarkerRulerAction method run.

@Override
public void run() {
    IMarker marker = chooseMarker(getMarkers());
    if (marker == null)
        return;
    IWorkbenchPage page = fTextEditor.getSite().getPage();
    MarkerViewUtil.showMarker(page, marker, false);
    gotoMarker(marker);
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker)

Example 92 with IMarker

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

the class SelectMarkerRulerAction method hasMarkers.

/**
 * Returns <code>true</code> iff there are any markers which include the ruler's line of activity.
 *
 * @return <code>true</code> iff there are any markers which include the ruler's line of activity.
 * @since 3.3
 */
protected final boolean hasMarkers() {
    final IResource resource = getResource();
    if (resource == null || !resource.exists())
        return false;
    final IDocument document = getDocument();
    if (document == null)
        return false;
    final AbstractMarkerAnnotationModel model = getAnnotationModel();
    if (model == null)
        return false;
    final IMarker[] allMarkers;
    try {
        allMarkers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
    } catch (CoreException x) {
        handleCoreException(x, TextEditorMessages.SelectMarkerRulerAction_getMarker);
        return false;
    }
    if (allMarkers.length == 0)
        return false;
    final int activeLine = fRuler.getLineOfLastMouseButtonActivity();
    if (activeLine == -1)
        return false;
    Iterator<Annotation> it;
    try {
        IRegion line = document.getLineInformation(activeLine);
        it = model.getAnnotationIterator(line.getOffset(), line.getLength() + 1, true, true);
    } catch (BadLocationException e) {
        logException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e));
        it = model.getAnnotationIterator();
    }
    while (it.hasNext()) {
        Annotation annotation = it.next();
        if (annotation instanceof MarkerAnnotation) {
            Position position = model.getPosition(annotation);
            if (includesLine(position, document, activeLine)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Position(org.eclipse.jface.text.Position) 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)

Example 93 with IMarker

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

the class MarkerResoltionQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    IAnnotationModel annotationModel = invocationContext.getSourceViewer().getAnnotationModel();
    Collection<MarkerAnnotation> annotations = new HashSet<>();
    annotationModel.getAnnotationIterator().forEachRemaining(annotation -> {
        Position position = annotationModel.getPosition(annotation);
        if (invocationContext.getOffset() >= position.getOffset() && invocationContext.getOffset() + Math.max(0, invocationContext.getLength()) <= position.getOffset() + position.getLength() && annotation instanceof MarkerAnnotation) {
            annotations.add((MarkerAnnotation) annotation);
        }
    });
    Collection<MarkerResolutionCompletionProposal> resolutions = new ArrayList<>();
    for (MarkerAnnotation annotation : annotations) {
        IMarker marker = annotation.getMarker();
        for (IMarkerResolution resolution : IDE.getMarkerHelpRegistry().getResolutions(marker)) {
            resolutions.add(new MarkerResolutionCompletionProposal(marker, resolution));
        }
    }
    return resolutions.toArray(new ICompletionProposal[resolutions.size()]);
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) IMarkerResolution(org.eclipse.ui.IMarkerResolution) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IMarker(org.eclipse.core.resources.IMarker) HashSet(java.util.HashSet)

Example 94 with IMarker

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

the class EditorOpener method showWithMarker.

private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
    IMarker marker = null;
    try {
        marker = file.createMarker(NewSearchUI.SEARCH_MARKER);
        HashMap<String, Integer> attributes = new HashMap<>(4);
        attributes.put(IMarker.CHAR_START, Integer.valueOf(offset));
        attributes.put(IMarker.CHAR_END, Integer.valueOf(offset + length));
        marker.setAttributes(attributes);
        IDE.gotoMarker(editor, marker);
    } catch (CoreException e) {
        throw new PartInitException(SearchMessages.FileSearchPage_error_marker, e);
    } finally {
        if (marker != null)
            try {
                marker.delete();
            } catch (CoreException e) {
            // ignore
            }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) IMarker(org.eclipse.core.resources.IMarker) PartInitException(org.eclipse.ui.PartInitException)

Example 95 with IMarker

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

the class RemoveMatchAction method getMarkers.

private IMarker[] getMarkers(ISelection s) {
    if (!(s instanceof IStructuredSelection) || s.isEmpty())
        return null;
    IStructuredSelection selection = (IStructuredSelection) s;
    int size = selection.size();
    if (size != 1)
        return null;
    if (selection.getFirstElement() instanceof ISearchResultViewEntry) {
        IMarker marker = ((ISearchResultViewEntry) selection.getFirstElement()).getSelectedMarker();
        if (marker != null)
            return new IMarker[] { marker };
    }
    return null;
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMarker(org.eclipse.core.resources.IMarker) ISearchResultViewEntry(org.eclipse.search.ui.ISearchResultViewEntry)

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