Search in sources :

Example 81 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method fileWithErrors.

protected XtendFile fileWithErrors(String string) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    assertTrue(resource.getErrors().toString(), resource.getErrors().size() > 0);
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 82 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method files.

protected Iterable<XtendFile> files(boolean validate, String... contents) throws Exception {
    XtextResourceSet set = getResourceSet();
    List<XtendFile> result = newArrayList();
    for (String string : contents) {
        String fileName = getFileName(string);
        Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
        resource.load(new StringInputStream(string), null);
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    for (Resource resource : new ArrayList<Resource>(set.getResources())) {
        XtendFile file = (XtendFile) resource.getContents().get(0);
        result.add(file);
    }
    if (validate) {
        for (XtendFile file : result) {
            List<Issue> issues = ((XtextResource) file.eResource()).getResourceServiceProvider().getResourceValidator().validate(file.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
            assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
        }
    }
    return result;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 83 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method getResourceSet.

protected XtextResourceSet getResourceSet() {
    XtextResourceSet set = resourceSetProvider.get();
    set.setClasspathURIContext(getClass().getClassLoader());
    return set;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 84 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet 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)

Example 85 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.

the class AbstractIncrementalBuilderTest method newBuildRequest.

protected BuildRequest newBuildRequest(final Procedure1<? super BuildRequest> init) {
    BuildRequest _buildRequest = new BuildRequest();
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        final ResourceDescriptionsData newIndex = this.indexState.getResourceDescriptions().copy();
        it.setBaseDir(this.uri(""));
        XtextResourceSet _get = this.resourceSetProvider.get();
        final Procedure1<XtextResourceSet> _function_1 = (XtextResourceSet it_1) -> {
            it_1.getURIConverter().getURIHandlers().clear();
            EList<URIHandler> _uRIHandlers = it_1.getURIConverter().getURIHandlers();
            _uRIHandlers.add(this.inMemoryURIHandler);
            it_1.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
            ProjectDescription _projectDescription = new ProjectDescription();
            final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it_2) -> {
                it_2.setName("test-project");
            };
            final ProjectDescription projectDescription = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function_2);
            projectDescription.attachToEmfObject(it_1);
            Map<String, ResourceDescriptionsData> _emptyMap = CollectionLiterals.<String, ResourceDescriptionsData>emptyMap();
            final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_emptyMap, it_1);
            index.setContainer(projectDescription.getName(), newIndex);
        };
        XtextResourceSet _doubleArrow = ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function_1);
        it.setResourceSet(_doubleArrow);
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Iterables.<Issue>addAll(this.issues, issues);
            return IterableExtensions.isEmpty(issues);
        };
        it.setAfterValidate(_function_2);
        final Procedure1<URI> _function_3 = (URI it_1) -> {
            this.deleted.add(it_1);
        };
        it.setAfterDeleteFile(_function_3);
        final Procedure2<URI, URI> _function_4 = (URI source, URI target) -> {
            this.generated.put(source, target);
        };
        it.setAfterGenerateFile(_function_4);
        Source2GeneratedMapping _copy = this.indexState.getFileMappings().copy();
        IndexState _indexState = new IndexState(newIndex, _copy);
        it.setState(_indexState);
    };
    final BuildRequest result = ObjectExtensions.<BuildRequest>operator_doubleArrow(_buildRequest, _function);
    init.apply(result);
    return result;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Source2GeneratedMapping(org.eclipse.xtext.build.Source2GeneratedMapping) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) IndexState(org.eclipse.xtext.build.IndexState) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) URIHandler(org.eclipse.emf.ecore.resource.URIHandler) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)72 XtextResource (org.eclipse.xtext.resource.XtextResource)61 Test (org.junit.Test)44 StringInputStream (org.eclipse.xtext.util.StringInputStream)36 URI (org.eclipse.emf.common.util.URI)24 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 EObject (org.eclipse.emf.ecore.EObject)11 File (java.io.File)10 AbstractResourceSetTest (org.eclipse.xtext.resource.AbstractResourceSetTest)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Issue (org.eclipse.xtext.validation.Issue)8 Grammar (org.eclipse.xtext.Grammar)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)7 ArrayList (java.util.ArrayList)5 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)5 Before (org.junit.Before)5 Injector (com.google.inject.Injector)4