Search in sources :

Example 76 with IMarker

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

the class OpenEditorTest method testOpenEditors.

@Test
public void testOpenEditors() throws Exception {
    IType bar = javaProject.findType("outlinetest.Bar");
    IEditorPart barEditor = globalURIEditorOpener.open(null, bar, true);
    assertEquals(JavaUI.ID_CU_EDITOR, barEditor.getEditorSite().getId());
    IType foo = javaProject.findType("outlinetest.Foo");
    IEditorPart fooJavaEditor = globalURIEditorOpener.open(null, foo, true);
    String expectedEditor = JavaUI.ID_CU_EDITOR;
    try {
        // if we are running in post 3.8 we have an Xtend editor
        if (Class.forName("org.eclipse.ui.ide.IEditorAssociationOverride") != null)
            expectedEditor = "org.eclipse.xtend.core.Xtend";
    } catch (ClassNotFoundException e) {
    // ignore
    }
    assertEquals(expectedEditor, fooJavaEditor.getEditorSite().getId());
    IResource resource = foo.getResource();
    assertTrue(resource instanceof IFile);
    IMarker[] markers = derivedResourceMarkers.findDerivedResourceMarkers(resource);
    assertEquals(1, markers.length);
    String source = derivedResourceMarkers.getSource(markers[0]);
    assertNotNull(source);
    IEditorPart fooXtendEditor = globalURIEditorOpener.open(URI.createURI(source), foo, true);
    assertEquals("org.eclipse.xtend.core.Xtend", fooXtendEditor.getEditorSite().getId());
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 77 with IMarker

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

the class FilesInJarsAreNotIndexedTest method testXtendInSourceIsIndexed_02.

@Test
public void testXtendInSourceIsIndexed_02() throws Exception {
    IProject project = workbenchTestHelper.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    addSourceFolder(javaProject, "src");
    IFile file = workbenchTestHelper.createFile("my/XtendClass.xtend", "package my\n" + "import static extension example5.Distance.*\n" + "import static extension example5.Time.*\n" + "import static extension example5.Speed.*\n" + "class XtendClass {\n" + "  def foo() {\n" + "    println((13.km + 2_000.m) * 2)\n" + "    println(65.sec + 59.min - 5_000.msec)\n" + "    println(42.km/h == (40_000.m + 2.km) / 60.min)\n" + "  }\n" + " } ");
    addJarToClasspath(javaProject, copyAndGetXtendExampleJar(javaProject));
    waitForBuild();
    IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, -1);
    if (markers.length > 0) {
        fail("No markers expected but got: " + markers[0].getAttribute(IMarker.MESSAGE));
    }
    IResourceDescriptions descriptions = descriptionsProvider.get();
    Iterator<IResourceDescription> iterator = descriptions.getAllResourceDescriptions().iterator();
    assertEquals(URI.createPlatformResourceURI(file.getFullPath().toString(), true), iterator.next().getURI());
    assertFalse(iterator.hasNext());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 78 with IMarker

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

the class UniqueClassNameValidatorUITest method testTwoXtendFilesSameProject.

@Test
public void testTwoXtendFilesSameProject() {
    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("first.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), 1, firstFileMarkers.length);
        Assert.assertEquals("The type A is already defined in B.xtend.", IterableExtensions.<IMarker>head(((Iterable<IMarker>) Conversions.doWrapArray(firstFileMarkers))).getAttribute(IMarker.MESSAGE));
        final Iterable<IMarker> secondFileMarkers = this.onlyErrors(((Iterable<IMarker>) Conversions.doWrapArray(secondFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE))));
        Assert.assertEquals(IResourcesSetupUtil.printMarker(((IMarker[]) Conversions.unwrapArray(secondFileMarkers, IMarker.class))), 1, ((Object[]) Conversions.unwrapArray(secondFileMarkers, Object.class)).length);
        Assert.assertEquals("The type A is already defined in A.xtend.", IterableExtensions.<IMarker>head(secondFileMarkers).getAttribute(IMarker.MESSAGE));
    } 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 79 with IMarker

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

the class MarkerAssertions method assertNoErrorMarker.

public void assertNoErrorMarker(IFile file) throws CoreException {
    int severity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
    if (severity != -1) {
        StringBuilder errors = new StringBuilder();
        for (IMarker marker : file.findMarkers(null, true, IResource.DEPTH_INFINITE)) {
            errors.append("\n").append(marker.getAttribute(IMarker.MESSAGE));
        }
        fail("Expected no error but got" + errors.toString());
    }
}
Also used : IMarker(org.eclipse.core.resources.IMarker)

Example 80 with IMarker

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

the class WorkspaceScenariosTest method testJarWithoutJava.

@Test
public void testJarWithoutJava() {
    try {
        final Function1<String, Boolean> _function = (String it) -> {
            return Boolean.valueOf((it.endsWith("java") || it.endsWith("class")));
        };
        final IProject project = this.createProjectWithJarDependency(_function);
        try {
            final ArrayList<IMarker> allXtendMarkers = CollectionLiterals.<IMarker>newArrayList();
            final IResourceVisitor _function_1 = (IResource it) -> {
                if ((it instanceof IFile)) {
                    boolean _endsWith = ((IFile) it).getFullPath().lastSegment().endsWith(".xtend");
                    if (_endsWith) {
                        final IMarker[] markers = ((IFile) it).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
                        for (final IMarker m : markers) {
                            allXtendMarkers.add(m);
                        }
                    }
                }
                return true;
            };
            project.accept(_function_1);
            Assert.assertEquals(2, allXtendMarkers.size());
            Assert.assertEquals(1, ((Object[]) Conversions.unwrapArray(this.persistedResourceDescriptions.get().getAllResourceDescriptions(), Object.class)).length);
        } finally {
            project.delete(true, true, null);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) 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