Search in sources :

Example 1 with ProjectManager

use of org.eclipse.xtext.ide.server.ProjectManager in project xtext-core by eclipse.

the class BuildManager method internalBuild.

protected List<IResourceDescription.Delta> internalBuild(final CancelIndicator cancelIndicator) {
    final ArrayList<URI> allDirty = new ArrayList<URI>(this.dirtyFiles);
    final HashMultimap<ProjectDescription, URI> project2dirty = HashMultimap.<ProjectDescription, URI>create();
    for (final URI dirty : allDirty) {
        {
            final ProjectDescription projectManager = this.workspaceManager.getProjectManager(dirty).getProjectDescription();
            project2dirty.put(projectManager, dirty);
        }
    }
    final HashMultimap<ProjectDescription, URI> project2deleted = HashMultimap.<ProjectDescription, URI>create();
    for (final URI deleted : this.deletedFiles) {
        {
            final ProjectDescription projectManager = this.workspaceManager.getProjectManager(deleted).getProjectDescription();
            project2deleted.put(projectManager, deleted);
        }
    }
    Set<ProjectDescription> _keySet = project2dirty.keySet();
    Set<ProjectDescription> _keySet_1 = project2deleted.keySet();
    Iterable<ProjectDescription> _plus = Iterables.<ProjectDescription>concat(_keySet, _keySet_1);
    final List<ProjectDescription> sortedDescriptions = this.sortByDependencies(_plus);
    final ArrayList<IResourceDescription.Delta> result = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
    for (final ProjectDescription it : sortedDescriptions) {
        {
            final ProjectManager projectManager = this.workspaceManager.getProjectManager(it.getName());
            final List<URI> projectDirty = IterableExtensions.<URI>toList(project2dirty.get(it));
            final List<URI> projectDeleted = IterableExtensions.<URI>toList(project2deleted.get(it));
            final IncrementalBuilder.Result partialResult = projectManager.doBuild(projectDirty, projectDeleted, result, cancelIndicator);
            final Function1<IResourceDescription.Delta, URI> _function = (IResourceDescription.Delta it_1) -> {
                return it_1.getUri();
            };
            allDirty.addAll(ListExtensions.<IResourceDescription.Delta, URI>map(partialResult.getAffectedResources(), _function));
            Iterables.removeAll(this.dirtyFiles, projectDirty);
            Iterables.removeAll(this.deletedFiles, projectDeleted);
            result.addAll(partialResult.getAffectedResources());
        }
    }
    return result;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) URI(org.eclipse.emf.common.util.URI) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager) ArrayList(java.util.ArrayList) List(java.util.List) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 2 with ProjectManager

use of org.eclipse.xtext.ide.server.ProjectManager in project xtext-core by eclipse.

the class WorkspaceManager method exists.

protected boolean exists(final URI uri) {
    ProjectManager _projectManager = this.getProjectManager(uri);
    XtextResourceSet _resourceSet = null;
    if (_projectManager != null) {
        _resourceSet = _projectManager.getResourceSet();
    }
    final XtextResourceSet rs = _resourceSet;
    if ((rs == null)) {
        return false;
    }
    return rs.getURIConverter().exists(uri, null);
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager)

Example 3 with ProjectManager

use of org.eclipse.xtext.ide.server.ProjectManager in project xtext-core by eclipse.

the class WorkspaceManager method doRead.

public <T extends Object> T doRead(final URI uri, final Function2<? super Document, ? super XtextResource, ? extends T> work) {
    final URI resourceURI = uri.trimFragment();
    final ProjectManager projectMnr = this.getProjectManager(resourceURI);
    Resource _resource = null;
    if (projectMnr != null) {
        _resource = projectMnr.getResource(resourceURI);
    }
    final XtextResource resource = ((XtextResource) _resource);
    if ((resource == null)) {
        return work.apply(null, null);
    }
    Document doc = this.getDocument(resource);
    Resource _resource_1 = projectMnr.getResource(resourceURI);
    return work.apply(doc, ((XtextResource) _resource_1));
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager)

Example 4 with ProjectManager

use of org.eclipse.xtext.ide.server.ProjectManager in project xtext-core by eclipse.

the class RenameService method rename.

@Override
public WorkspaceEdit rename(final WorkspaceManager workspaceManager, final RenameParams renameParams, final CancelIndicator cancelIndicator) {
    WorkspaceEdit _xblockexpression = null;
    {
        final URI uri = this._uriExtensions.toUri(renameParams.getTextDocument().getUri());
        final ServerRefactoringIssueAcceptor issueAcceptor = this.issueProvider.get();
        final Function2<Document, XtextResource, WorkspaceEdit> _function = (Document document, XtextResource resource) -> {
            final ProjectManager projectManager = workspaceManager.getProjectManager(uri);
            final XtextResourceSet resourceSet = projectManager.createNewResourceSet(projectManager.getIndexState().getResourceDescriptions());
            resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.valueOf(true));
            final int offset = document.getOffSet(renameParams.getPosition());
            final WorkspaceEdit workspaceEdit = new WorkspaceEdit();
            final Resource xtextResource = resourceSet.getResource(resource.getURI(), true);
            if ((xtextResource instanceof XtextResource)) {
                final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(((XtextResource) xtextResource), offset);
                if (((element == null) || element.eIsProxy())) {
                    StringConcatenation _builder = new StringConcatenation();
                    _builder.append("No element found at position line:");
                    int _line = renameParams.getPosition().getLine();
                    _builder.append(_line);
                    _builder.append(" column:");
                    int _character = renameParams.getPosition().getCharacter();
                    _builder.append(_character);
                    issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, _builder.toString());
                } else {
                    String _newName = renameParams.getNewName();
                    URI _uRI = EcoreUtil.getURI(element);
                    final RenameChange change = new RenameChange(_newName, _uRI);
                    final IChangeSerializer changeSerializer = this.changeSerializerProvider.get();
                    final RenameContext context = new RenameContext(Collections.<RenameChange>unmodifiableList(CollectionLiterals.<RenameChange>newArrayList(change)), resourceSet, changeSerializer, issueAcceptor);
                    this.renameStrategy.applyRename(context);
                    final ChangeConverter changeConverter = this.converterFactory.create(workspaceManager, workspaceEdit);
                    changeSerializer.applyModifications(changeConverter);
                }
            } else {
                issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, "Loaded resource is not an XtextResource", resource.getURI());
            }
            return workspaceEdit;
        };
        _xblockexpression = workspaceManager.<WorkspaceEdit>doRead(uri, _function);
    }
    return _xblockexpression;
}
Also used : RenameChange(org.eclipse.xtext.ide.refactoring.RenameChange) RenameContext(org.eclipse.xtext.ide.refactoring.RenameContext) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ChangeConverter(org.eclipse.xtext.ide.server.rename.ChangeConverter) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) XtextResource(org.eclipse.xtext.resource.XtextResource) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) ServerRefactoringIssueAcceptor(org.eclipse.xtext.ide.server.rename.ServerRefactoringIssueAcceptor) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

ProjectManager (org.eclipse.xtext.ide.server.ProjectManager)4 URI (org.eclipse.emf.common.util.URI)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Document (org.eclipse.xtext.ide.server.Document)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EObject (org.eclipse.emf.ecore.EObject)1 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 RenameChange (org.eclipse.xtext.ide.refactoring.RenameChange)1 RenameContext (org.eclipse.xtext.ide.refactoring.RenameContext)1 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)1 ChangeConverter (org.eclipse.xtext.ide.server.rename.ChangeConverter)1 ServerRefactoringIssueAcceptor (org.eclipse.xtext.ide.server.rename.ServerRefactoringIssueAcceptor)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)1