Search in sources :

Example 26 with XtextResourceSet

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

the class TypeBasedSimpleBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    owner = new StandardTypeReferenceOwner(services, resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 27 with XtextResourceSet

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

the class AbstractXtendTestCase method file.

protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    if (shouldBeSyntacticallyValid) {
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    if (validate) {
        List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {

            @Override
            public boolean apply(Issue issue) {
                return issue.getSeverity() == Severity.ERROR;
            }
        }));
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
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) XtextResource(org.eclipse.xtext.resource.XtextResource) Predicate(com.google.common.base.Predicate)

Example 28 with XtextResourceSet

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

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

the class CodeActionService method recordWorkspaceEdit.

private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
    try {
        final XtextResourceSet rs = new XtextResourceSet();
        final Resource copy = rs.createResource(resource.getURI());
        String _text = resource.getParseResult().getRootNode().getText();
        StringInputStream _stringInputStream = new StringInputStream(_text);
        copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
        this.serializer.<Resource>addModification(copy, mod);
        final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
        this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
            Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
            for (final ITextDocumentChange documentchange : _filter) {
                {
                    final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
                        TextEdit _textEdit = new TextEdit();
                        final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
                            it_1.setNewText(replacement.getReplacementText());
                            Position _position = doc.getPosition(replacement.getOffset());
                            Position _position_1 = doc.getPosition(replacement.getEndOffset());
                            Range _range = new Range(_position, _position_1);
                            it_1.setRange(_range);
                        };
                        return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
                    };
                    final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
                    it.getChanges().put(documentchange.getNewURI().toString(), edits);
                }
            }
        };
        return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) Range(org.eclipse.lsp4j.Range) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange)

Example 30 with XtextResourceSet

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

the class AbstractXtextResourceSetTest method testResourcesAreInMapWithNormalizedURI_01.

@Test
public void testResourcesAreInMapWithNormalizedURI_01() {
    final XtextResourceSet rs = this.createEmptyResourceSet();
    Assert.assertEquals(0, rs.getURIResourceMap().size());
    final XtextResource resource = new XtextResource();
    resource.setURI(URI.createURI("/a/../foo"));
    EList<Resource> _resources = rs.getResources();
    _resources.add(resource);
    Assert.assertEquals(2, rs.getURIResourceMap().size());
    rs.getResources().remove(resource);
    Assert.assertTrue(resource.eAdapters().isEmpty());
    Assert.assertEquals(0, rs.getURIResourceMap().size());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) AbstractResourceSetTest(org.eclipse.xtext.resource.AbstractResourceSetTest) Test(org.junit.Test)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)177 Resource (org.eclipse.emf.ecore.resource.Resource)81 XtextResource (org.eclipse.xtext.resource.XtextResource)77 Test (org.junit.Test)57 StringInputStream (org.eclipse.xtext.util.StringInputStream)42 URI (org.eclipse.emf.common.util.URI)33 EObject (org.eclipse.emf.ecore.EObject)20 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)19 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 Grammar (org.eclipse.xtext.Grammar)10 Issue (org.eclipse.xtext.validation.Issue)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)8 File (java.io.File)7 ArrayList (java.util.ArrayList)7 EList (org.eclipse.emf.common.util.EList)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 Before (org.junit.Before)7 Injector (com.google.inject.Injector)6 IOException (java.io.IOException)6 Diagnostic (org.eclipse.emf.common.util.Diagnostic)5