use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.
the class WrongDeallocationResolutionTest method testNewArrayDeleteQuickFix.
@Test
public void testNewArrayDeleteQuickFix() throws CoreException {
IMarker newArrayDeleteMarker = markers[9];
int markerLine = newArrayDeleteMarker.getAttribute(IMarker.LINE_NUMBER, -1);
createResolutionAndApply(newArrayDeleteMarker);
String newContent = getLineContent(document, markerLine);
// $NON-NLS-1$
assertTrue(newContent.contains("delete[]"));
}
use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.
the class WrongDeallocationResolutionTest method testMallocDeleteQuickFix.
@Test
public void testMallocDeleteQuickFix() throws CoreException {
IMarker mallocDeleteMarker = markers[1];
int markerLine = mallocDeleteMarker.getAttribute(IMarker.LINE_NUMBER, -1);
createResolutionAndApply(mallocDeleteMarker);
String newContent = getLineContent(document, markerLine);
// $NON-NLS-1$
assertTrue(newContent.contains("free"));
// $NON-NLS-1$
assertFalse(newContent.contains("delete"));
}
use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.
the class RpmlintParser method addMarker.
/**
* Adds a rpmlint marker.
*
* @param file
* The file to create the marker for.
* @param message
* The marker message.
* @param severity
* The marker severity.
* @param rpmlintID
* The id of the rpmlint warning/error.
* @param rpmlintrefferedContent
* Additional content referred by the marker.
*/
public static void addMarker(IFile file, String message, int severity, String rpmlintID, String rpmlintrefferedContent) {
try {
IMarker marker = file.createMarker(RpmlintBuilder.MARKER_ID);
marker.setAttribute(IMarker.LOCATION, file.getFullPath().toString());
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute(RpmlintMarkerResolutionGenerator.RPMLINT_ERROR_ID, rpmlintID);
marker.setAttribute(RpmlintMarkerResolutionGenerator.RPMLINT_REFFERED_CONTENT, rpmlintrefferedContent);
} catch (CoreException e) {
RpmlintLog.logError(e);
}
}
use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.
the class SyntaxProblemReporter method checkAndApply.
public void checkAndApply(IDocument document, int offset, int length, IResource resource) throws CoreException, BadLocationException {
// We can't do problem report when file is external (no IResource)
if (resource == null) {
return;
}
boolean fullScan = (offset == 0 && length == document.getLength());
// Clear any existing markers in the affected region.
IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
List<IMarker> markersToDelete = new ArrayList<>();
for (IMarker marker : markers) {
int markerLineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
int regionLineNr = document.getLineOfOffset(offset);
if (fullScan || markerLineNr == regionLineNr)
markersToDelete.add(marker);
}
for (IMarker marker : markersToDelete) marker.delete();
// Apply new problems as needed.
List<SyntaxProblem> problems = check(document, offset, length);
for (SyntaxProblem problem : problems) {
IMarker marker = resource.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.SEVERITY, problem.severity);
marker.setAttribute(IMarker.MESSAGE, problem.message);
marker.setAttribute(IMarker.LINE_NUMBER, document.getLineOfOffset(problem.offset));
marker.setAttribute(IMarker.CHAR_START, problem.offset);
marker.setAttribute(IMarker.CHAR_END, problem.offset + problem.length);
}
}
use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class MarkerUtilTest method addMarker.
/**
* Verifies that {@link MarkerUtil#addMarker(IFile, String, RuleViolation)} adds a marker to the provided file.
*/
@Test
public void addMarker() throws CoreException {
final IFile file = mock(IFile.class);
final IMarker marker = mock(IMarker.class);
when(file.createMarker(MARKER_TYPE)).thenReturn(marker);
final RuleViolation violation = mock(RuleViolation.class);
when(violation.getDescription()).thenReturn("message");
when(violation.getBeginLine()).thenReturn(1);
when(violation.getBeginColumn()).thenReturn(17);
when(violation.getEndLine()).thenReturn(1);
when(violation.getEndColumn()).thenReturn(22);
when(violation.getClassName()).thenReturn("ClassName");
final Rule rule = mock(Rule.class);
when(rule.getLanguage()).thenReturn(new JavaLanguageModule());
when(rule.getRuleSetName()).thenReturn("basic");
when(rule.getName()).thenReturn("ExtendsObject");
when(violation.getRule()).thenReturn(rule);
final IMarker actual = MarkerUtil.addMarker(file, "class A extends Object {}", violation);
assertNotNull("The method must always return a marker", actual);
verify(file).createMarker(MARKER_TYPE);
verify(actual).setAttribute(IMarker.MESSAGE, "message");
verify(actual).setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
verify(actual).setAttribute(IMarker.LINE_NUMBER, 1);
verify(actual).setAttribute(IMarker.CHAR_START, 16);
verify(actual).setAttribute(IMarker.CHAR_END, 22);
verify(actual).setAttribute("ruleId", "java.basic.ExtendsObject");
verify(actual).setAttribute("violationClassName", "ClassName");
verify(actual).setAttribute("markerText", "Object");
}
Aggregations