Search in sources :

Example 1 with ISourceFolder

use of org.eclipse.xtext.workspace.ISourceFolder in project xtext-core by eclipse.

the class SourceFolderDefaultImplTest method testDefaultSourceFolderImplementation.

/**
 * Asserts that the default implementation returns all files in the
 * configured source folder
 */
@Test
public void testDefaultSourceFolderImplementation() {
    this.writeFile("sample.testlang", "MyContent");
    this.initialize();
    ProjectManager projectManager = this.workspaceManager.getProjectManager("");
    Set<? extends ISourceFolder> sourceFolders = projectManager.getProjectConfig().getSourceFolders();
    Assert.assertTrue(sourceFolders.size() == 1);
    ISourceFolder sourceFolder = sourceFolders.iterator().next();
    List<URI> allResources = sourceFolder.getAllResources(this.scanner);
    Assert.assertTrue(allResources.stream().anyMatch((URI uri) -> uri.toString().endsWith("test-data/test-project/")));
    Assert.assertTrue(allResources.stream().anyMatch((URI uri) -> uri.toString().endsWith("test-data/test-project/sample.testlang")));
    Assert.assertEquals(allResources.size(), 2);
}
Also used : ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) URI(org.eclipse.emf.common.util.URI) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager) Test(org.junit.Test)

Example 2 with ISourceFolder

use of org.eclipse.xtext.workspace.ISourceFolder in project xtext-core by eclipse.

the class AbstractTraceForURIProvider method asFile.

protected SomeFile asFile(SourceRelativeURI srcRelativeDerivedResource, IProjectConfig project) {
    String[] pathSegments = srcRelativeDerivedResource.getURI().segments();
    Set<? extends ISourceFolder> sourceFolders = project.getSourceFolders();
    for (ISourceFolder folder : sourceFolders) {
        URI srcFolderPath = folder.getPath();
        URI absoluteURI = srcFolderPath.appendSegments(pathSegments);
        SomeFile result = asFile(new AbsoluteURI(absoluteURI), project);
        if (result != null) {
            return result;
        }
    }
    URI fromRoot = project.getPath().appendSegments(pathSegments);
    return asFile(new AbsoluteURI(fromRoot), project);
}
Also used : ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI)

Example 3 with ISourceFolder

use of org.eclipse.xtext.workspace.ISourceFolder in project xtext-core by eclipse.

the class AbsoluteURI method deresolve.

public SourceRelativeURI deresolve(final IProjectConfig projectConfig) {
    final ISourceFolder sourceFolder = projectConfig.findSourceFolderContaining(this.getURI());
    SourceRelativeURI _deresolve = null;
    if (sourceFolder != null) {
        _deresolve = this.deresolve(sourceFolder);
    }
    return _deresolve;
}
Also used : ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 4 with ISourceFolder

use of org.eclipse.xtext.workspace.ISourceFolder in project xtext-core by eclipse.

the class LiveShadowedChunkedContainer method isContained.

protected boolean isContained(final URI uri) {
    boolean _or = false;
    IResourceDescription _resourceDescription = this.getChunk().getResourceDescription(uri);
    boolean _tripleNotEquals = (_resourceDescription != null);
    if (_tripleNotEquals) {
        _or = true;
    } else {
        IProjectConfig _projectConfig = this.getProjectConfig();
        ISourceFolder _findSourceFolderContaining = null;
        if (_projectConfig != null) {
            _findSourceFolderContaining = _projectConfig.findSourceFolderContaining(uri);
        }
        boolean _tripleNotEquals_1 = (_findSourceFolderContaining != null);
        _or = _tripleNotEquals_1;
    }
    return _or;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) IProjectConfig(org.eclipse.xtext.workspace.IProjectConfig)

Example 5 with ISourceFolder

use of org.eclipse.xtext.workspace.ISourceFolder in project xtext-eclipse by eclipse.

the class JdtProjectConfig method getSourceFolders.

@Override
public Set<? extends ISourceFolder> getSourceFolders() {
    try {
        final IJavaProject javaProject = JavaCore.create(this.getProject());
        boolean _exists = javaProject.exists();
        boolean _not = (!_exists);
        if (_not) {
            return CollectionLiterals.<ISourceFolder>emptySet();
        }
        final IClasspathEntry[] classpath = javaProject.getRawClasspath();
        final Function1<IClasspathEntry, Boolean> _function = (IClasspathEntry it) -> {
            int _entryKind = it.getEntryKind();
            return Boolean.valueOf((_entryKind == IClasspathEntry.CPE_SOURCE));
        };
        final Iterable<IClasspathEntry> sourceEntries = IterableExtensions.<IClasspathEntry>filter(((Iterable<IClasspathEntry>) Conversions.doWrapArray(classpath)), _function);
        final Function1<IClasspathEntry, String> _function_1 = (IClasspathEntry it) -> {
            return it.getPath().removeFirstSegments(1).toString();
        };
        final Iterable<String> sourceFolders = IterableExtensions.<IClasspathEntry, String>map(sourceEntries, _function_1);
        final Function1<String, EclipseSourceFolder> _function_2 = (String it) -> {
            IProject _project = this.getProject();
            return new EclipseSourceFolder(_project, it);
        };
        return IterableExtensions.<EclipseSourceFolder>toSet(IterableExtensions.<String, EclipseSourceFolder>map(sourceFolders, _function_2));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ISourceFolder(org.eclipse.xtext.workspace.ISourceFolder) EclipseSourceFolder(org.eclipse.xtext.ui.workspace.EclipseSourceFolder) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

ISourceFolder (org.eclipse.xtext.workspace.ISourceFolder)6 URI (org.eclipse.emf.common.util.URI)3 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)2 ProjectManager (org.eclipse.xtext.ide.server.ProjectManager)2 Test (org.junit.Test)2 IProject (org.eclipse.core.resources.IProject)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 EclipseSourceFolder (org.eclipse.xtext.ui.workspace.EclipseSourceFolder)1 IProjectConfig (org.eclipse.xtext.workspace.IProjectConfig)1