Search in sources :

Example 41 with IMarker

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[]"));
}
Also used : IMarker(org.eclipse.core.resources.IMarker) AbstractValgrindTest(org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest) Test(org.junit.Test)

Example 42 with IMarker

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"));
}
Also used : IMarker(org.eclipse.core.resources.IMarker) AbstractValgrindTest(org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest) Test(org.junit.Test)

Example 43 with IMarker

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker)

Example 44 with IMarker

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker)

Example 45 with IMarker

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");
}
Also used : IFile(org.eclipse.core.resources.IFile) JavaLanguageModule(net.sourceforge.pmd.lang.java.JavaLanguageModule) IMarker(org.eclipse.core.resources.IMarker) RuleViolation(net.sourceforge.pmd.RuleViolation) Rule(net.sourceforge.pmd.Rule) Test(org.junit.Test)

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