Search in sources :

Example 16 with XtextResourceSet

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

the class WorkspaceEncodingProviderTest method testProjectSpecificEncoding.

@Test
public void testProjectSpecificEncoding() throws CoreException {
    project.setDefaultCharset("UTF-16", new NullProgressMonitor());
    XtextResourceSet resourceSet = resourceSetProvider.get();
    XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("platform:/resource/WorkspaceEncodingProviderTest/test1.xtextgrammar"));
    assertEquals("UTF-16", resource.getEncoding());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 17 with XtextResourceSet

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

the class WorkspaceEncodingProviderTest method testWorkspaceDefaultEncoding.

@Test
public void testWorkspaceDefaultEncoding() {
    XtextResourceSet resourceSet = resourceSetProvider.get();
    XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("platform:/resource/WorkspaceEncodingProviderTest/test1.xtextgrammar"));
    assertEquals(defaultEncoding, resource.getEncoding());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 18 with XtextResourceSet

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

the class Bug297909Test method testReconcileDocument.

@Test
public void testReconcileDocument() throws Exception {
    Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
    XtextDocument document = injector.getInstance(XtextDocument.class);
    document.setValidationJob(new Job("Job") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            return Status.OK_STATUS;
        }
    });
    XtextResource resource = injector.getInstance(XtextResource.class);
    XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
    resourceSet.getResources().add(resource);
    resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
    document.setInput(resource);
    document.set("abstract rules firstRule");
    XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
    strategy.setDocument(document);
    strategy.setResource(resource);
    try {
        strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
        fail("Expected ParseException");
    } catch (ParseException expected) {
        assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextDocumentReconcileStrategy(org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy) ReconcilerReplaceRegion(org.eclipse.xtext.ui.editor.reconciler.ReconcilerReplaceRegion) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ParseException(org.eclipse.xtext.parser.ParseException) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Example 19 with XtextResourceSet

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

the class HighlightingReconciler method updatePresentation.

/**
 * Update the presentation.
 *
 * @param textPresentation
 *            the text presentation
 * @param addedPositions
 *            the added positions
 * @param removedPositions
 *            the removed positions
 * @param resource
 *            the resource for which the positions have been computed
 */
private void updatePresentation(TextPresentation textPresentation, List<AttributedPosition> addedPositions, List<AttributedPosition> removedPositions, XtextResource resource) {
    final Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
    if (runnable == null)
        return;
    final XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet();
    final int modificationStamp = resourceSet.getModificationStamp();
    Display display = getDisplay();
    display.asyncExec(new Runnable() {

        @Override
        public void run() {
            // never apply outdated highlighting
            if (sourceViewer != null && modificationStamp == resourceSet.getModificationStamp())
                runnable.run();
        }
    });
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Display(org.eclipse.swt.widgets.Display)

Example 20 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-eclipse 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.junit4.util.InMemoryURIHandler) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

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