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;
}
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();
}
}
}
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;
}
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);
}
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);
}
Aggregations