Search in sources :

Example 36 with IMarker

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

the class UniqueClassNameValidatorUITest method testXtendAndJavaSameProjectXtendFirst.

@Ignore("Since the name acme.A is considered to be derived, it is filtered from the Java delta")
@Test
public void testXtendAndJavaSameProjectXtendFirst() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package acme");
        _builder.newLine();
        _builder.append("class A {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/B.xtend", _builder.toString());
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package acme;");
        _builder_1.newLine();
        _builder_1.append("class A2 {");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile javaFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.java", _builder_1.toString());
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        StringInputStream _stringInputStream = new StringInputStream("package acme; class A{}");
        javaFile.setContents(_stringInputStream, false, false, null);
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, JavaCore.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        final IMarker[] markers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
        Assert.assertEquals(IResourcesSetupUtil.printMarker(markers), 1, markers.length);
        Assert.assertEquals("The type A is already defined in A.java.", IterableExtensions.<IMarker>head(((Iterable<IMarker>) Conversions.doWrapArray(markers))).getAttribute(IMarker.MESSAGE));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IMarker(org.eclipse.core.resources.IMarker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with IMarker

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

the class UniqueClassNameValidatorUITest method testTwoXtendFilesDifferentProject.

@Test
public void testTwoXtendFilesDifferentProject() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package acme");
        _builder.newLine();
        _builder.append("class A {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IFile firstFile = IResourcesSetupUtil.createFile("first.p384008/src/acme/A.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package acme");
        _builder_1.newLine();
        _builder_1.append("class A {");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile secondFile = IResourcesSetupUtil.createFile("second.p384008/src/acme/B.xtend", _builder_1.toString());
        this.first.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, XtextBuilder.BUILDER_ID, UniqueClassNameValidatorUITest.emptyStringMap(), null);
        final IMarker[] firstFileMarkers = firstFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
        Assert.assertEquals(IResourcesSetupUtil.printMarker(firstFileMarkers), 0, firstFileMarkers.length);
        final IMarker[] secondFileMarkers = secondFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
        Assert.assertEquals(IResourcesSetupUtil.printMarker(secondFileMarkers), 0, secondFileMarkers.length);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 38 with IMarker

use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.

the class LinkedResourceMarkerTest method findMarker.

private void findMarker(ArrayList<IMarker> markers, IValgrindMessage error) throws Exception, CoreException {
    ValgrindStackFrame frame = null;
    IValgrindMessage[] children = error.getChildren();
    for (int i = 0; i < children.length; i++) {
        if (frame == null && children[i] instanceof ValgrindStackFrame && isWorkspaceFrame((ValgrindStackFrame) children[i])) {
            frame = (ValgrindStackFrame) children[i];
        } else if (children[i] instanceof ValgrindError) {
            findMarker(markers, children[i]);
        }
    }
    int ix = -1;
    for (int i = 0; i < markers.size(); i++) {
        IMarker marker = markers.get(i);
        if (marker.getAttribute(IMarker.MESSAGE).equals(error.getText()) && marker.getResource().getName().equals(frame.getFile()) && marker.getAttribute(IMarker.LINE_NUMBER).equals(frame.getLine())) {
            ix = i;
        }
    }
    assertFalse(ix < 0);
    markers.remove(ix);
}
Also used : ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker)

Example 39 with IMarker

use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.

the class WrongDeallocationResolutionTest method testMallocDeleteArrayQuickFix.

@Test
public void testMallocDeleteArrayQuickFix() throws CoreException {
    IMarker mallocDeleteArrayMarker = markers[3];
    int markerLine = mallocDeleteArrayMarker.getAttribute(IMarker.LINE_NUMBER, -1);
    createResolutionAndApply(mallocDeleteArrayMarker);
    String newContent = getLineContent(document, markerLine);
    // $NON-NLS-1$
    assertTrue(newContent.contains("free"));
    // $NON-NLS-1$
    assertFalse(newContent.contains("delete"));
    // $NON-NLS-1$
    assertFalse(newContent.contains("["));
}
Also used : IMarker(org.eclipse.core.resources.IMarker) AbstractValgrindTest(org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest) Test(org.junit.Test)

Example 40 with IMarker

use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.

the class WrongDeallocationResolutionTest method testNewFreeQuickFix.

@Test
public void testNewFreeQuickFix() throws CoreException {
    IMarker newFreeMarker = markers[5];
    int markerLine = newFreeMarker.getAttribute(IMarker.LINE_NUMBER, -1);
    createResolutionAndApply(newFreeMarker);
    String newContent = getLineContent(document, markerLine);
    // $NON-NLS-1$
    assertTrue(newContent.contains("delete"));
    // $NON-NLS-1$
    assertFalse(newContent.contains("free"));
}
Also used : IMarker(org.eclipse.core.resources.IMarker) AbstractValgrindTest(org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest) 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