Search in sources :

Example 21 with IMarker

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

the class SelectMarkerRulerAction method chooseMarker.

/**
 * Chooses the marker with the highest layer. If there are multiple
 * markers at the found layer, the first marker is taken.
 *
 * @param markers the list of markers to choose from
 * @return the chosen marker or <code>null</code> if none of the given markers has a marker annotation in the model
 */
protected final IMarker chooseMarker(List<? extends IMarker> markers) {
    AbstractMarkerAnnotationModel model = getAnnotationModel();
    IAnnotationAccessExtension access = getAnnotationAccessExtension();
    IMarker marker = null;
    int maxLayer = 0;
    Iterator<? extends IMarker> iter = markers.iterator();
    while (iter.hasNext()) {
        IMarker m = iter.next();
        Annotation a = model.getMarkerAnnotation(m);
        if (a != null) {
            if (access == null) {
                marker = m;
                break;
            }
            int l = access.getLayer(a);
            if (l == maxLayer) {
                if (marker == null)
                    marker = m;
            } else if (l > maxLayer) {
                maxLayer = l;
                marker = m;
            }
        }
    }
    return marker;
}
Also used : IAnnotationAccessExtension(org.eclipse.jface.text.source.IAnnotationAccessExtension) IMarker(org.eclipse.core.resources.IMarker) Annotation(org.eclipse.jface.text.source.Annotation)

Example 22 with IMarker

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

the class HoverTest method testProblemHover.

@Test
public void testProblemHover() throws Exception {
    String problemMessage = "Huston...";
    IMarker marker = null;
    try {
        marker = this.file.createMarker(IMarker.PROBLEM);
        marker.setAttribute(IMarker.LINE_NUMBER, 1);
        marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
        marker.setAttribute(IMarker.CHAR_START, 0);
        marker.setAttribute(IMarker.CHAR_END, 5);
        marker.setAttribute(IMarker.MESSAGE, problemMessage);
        marker.setAttribute(MarkerResolutionGenerator.FIXME, true);
        AbstractInformationControlManager manager = triggerCompletionAndRetrieveInformationControlManager();
        Object hoverData = getHoverData(manager);
        assertTrue(hoverData instanceof Map);
        assertTrue(((Map<?, ?>) hoverData).containsValue(Collections.singletonList(marker)));
        assertTrue(((Map<?, ?>) hoverData).containsValue(AlrightyHoverProvider.LABEL));
        assertFalse(((Map<?, ?>) hoverData).containsValue(HelloHoverProvider.LABEL));
        // check dialog content
        Shell shell = getHoverShell(manager);
        assertNotNull(findControl(shell, Label.class, marker.getAttribute(IMarker.MESSAGE, "NONE")));
        assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
        assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
        // check quick-fix works
        Link link = findControl(shell, Link.class, MarkerResolutionGenerator.FIXME);
        assertNotNull(link);
        Event event = new Event();
        event.widget = link;
        event.display = link.getDisplay();
        event.doit = true;
        event.type = SWT.Selection;
        link.notifyListeners(SWT.Selection, event);
        final IMarker m = marker;
        new DisplayHelper() {

            @Override
            protected boolean condition() {
                return !m.exists();
            }
        }.waitForCondition(event.display, 1000);
        assertFalse(marker.exists());
    } finally {
        if (marker != null && marker.exists()) {
            marker.delete();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) AbstractInformationControlManager(org.eclipse.jface.text.AbstractInformationControlManager) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) Link(org.eclipse.swt.widgets.Link) ScreenshotTest(org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest) Test(org.junit.Test)

Example 23 with IMarker

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

the class MarkerAnnotationHover method getHoverInfo2.

@Override
public List<IMarker> getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    if (!(textViewer instanceof ISourceViewerExtension2)) {
        return null;
    }
    List<MarkerAnnotation> annotations = findMarkerAnnotations((ISourceViewerExtension2) textViewer, hoverRegion);
    if (annotations.isEmpty()) {
        return null;
    }
    List<IMarker> markers = new ArrayList<>(annotations.size());
    for (MarkerAnnotation annotation : annotations) {
        markers.add(annotation.getMarker());
    }
    return markers;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Example 24 with IMarker

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

the class MarkerInformationControl method setInput.

@SuppressWarnings("unchecked")
@Override
public void setInput(Object input) {
    this.composites.values().forEach(Composite::dispose);
    this.markers = (List<IMarker>) input;
    for (IMarker marker : this.markers) {
        Composite markerComposite = new Composite(parent, SWT.NONE);
        this.composites.put(marker, markerComposite);
        GridLayout gridLayout = new GridLayout(1, false);
        gridLayout.verticalSpacing = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        markerComposite.setLayout(gridLayout);
        Composite markerLine = new Composite(markerComposite, SWT.NONE);
        RowLayout rowLayout = new RowLayout();
        rowLayout.marginTop = 0;
        rowLayout.marginBottom = 0;
        rowLayout.marginLeft = 0;
        rowLayout.marginRight = 0;
        markerLine.setLayout(rowLayout);
        IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(marker);
        if (resolutions.length > 0) {
            Label markerImage = new Label(markerLine, SWT.NONE);
            markerImage.setImage(getImage(marker));
        }
        Label markerLabel = new Label(markerLine, SWT.NONE);
        // $NON-NLS-1$
        markerLabel.setText(marker.getAttribute(IMarker.MESSAGE, "missing message"));
        for (IMarkerResolution resolution : resolutions) {
            Composite resolutionComposite = new Composite(markerComposite, SWT.NONE);
            GridData layoutData = new GridData();
            layoutData.horizontalIndent = 10;
            resolutionComposite.setLayoutData(layoutData);
            RowLayout resolutionRowLayout = new RowLayout();
            resolutionRowLayout.marginBottom = 0;
            resolutionComposite.setLayout(resolutionRowLayout);
            Label resolutionImage = new Label(resolutionComposite, SWT.NONE);
            // TODO: try to retrieve icon from QuickFix command
            Image resolutionPic = null;
            if (resolution instanceof IMarkerResolution2) {
                resolutionPic = ((IMarkerResolution2) resolution).getImage();
            }
            if (resolutionPic == null) {
                resolutionPic = PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OPEN_MARKER);
            }
            resolutionImage.setImage(resolutionPic);
            Link resolutionLink = new Link(resolutionComposite, SWT.NONE);
            // $NON-NLS-1$ //$NON-NLS-2$
            resolutionLink.setText("<A>" + resolution.getLabel() + "</a>");
            resolutionLink.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Job resolutionJob = new // $NON-NLS-1$
                    Job(// $NON-NLS-1$
                    "apply resolution - " + resolution.getLabel()) {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            resolution.run(marker);
                            return Status.OK_STATUS;
                        }
                    };
                    resolutionJob.setUser(true);
                    resolutionJob.setSystem(true);
                    resolutionJob.setPriority(Job.INTERACTIVE);
                    resolutionJob.schedule();
                    getShell().dispose();
                }
            });
        }
    }
    parent.layout(true);
}
Also used : IMarkerResolution2(org.eclipse.ui.IMarkerResolution2) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IMarkerResolution(org.eclipse.ui.IMarkerResolution) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMarker(org.eclipse.core.resources.IMarker) Job(org.eclipse.core.runtime.jobs.Job) Link(org.eclipse.swt.widgets.Link)

Example 25 with IMarker

use of org.eclipse.core.resources.IMarker in project xtext-xtend by eclipse.

the class MarkerAssertions method assertErrorMarker.

public void assertErrorMarker(IFile file, String issueCode, int expectedIssuesCount) throws CoreException {
    IMarker[] findMarkers = file.findMarkers(null, true, IResource.DEPTH_INFINITE);
    int matchingIssuesFound = 0;
    List<String> allCodes = new ArrayList<String>();
    for (IMarker iMarker : findMarkers) {
        String code = issueUtil.getCode(iMarker);
        if (code != null) {
            allCodes.add(code);
            if (issueCode.equals(code)) {
                matchingIssuesFound++;
            }
        }
    }
    String message = "Expected error marker not found: '" + issueCode + (allCodes.isEmpty() ? "'" : "' but found '" + Strings.concat(",", allCodes) + "'");
    assertTrue(message, matchingIssuesFound > 0);
    assertEquals("Expected error marker count for '" + issueCode + "'", expectedIssuesCount, matchingIssuesFound);
}
Also used : ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker)

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