Search in sources :

Example 56 with XtextResourceSet

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

the class BasicLazyLinkingTest method doGetResource.

@Override
public XtextResource doGetResource(InputStream in, URI uri) throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    rs.setClasspathURIContext(getClass());
    XtextResource resource = (XtextResource) getResourceFactory().createResource(uri);
    rs.getResources().add(resource);
    resource.load(in, null);
    return resource;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 57 with XtextResourceSet

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

the class XtendHighlightingCalculatorTest method getResourceSet.

@Override
protected XtextResourceSet getResourceSet() {
    XtextResourceSet result = super.getResourceSet();
    result.setClasspathURIContext(getClass().getClassLoader());
    return result;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 58 with XtextResourceSet

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

the class JavaIoFileSystemTest method setUp.

@Before
public void setUp() {
    try {
        final File tempDir = this.temporaryFolder.newFolder();
        JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
        final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
            final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
                File _file = new File(tempDir, "foo");
                FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
                final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
                    it_2.addSourceFolder("src");
                };
                return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
            };
            it.setProjectConfigProvider(_function_1);
            IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
            it.setEncodingProvider(_runtime);
            XtextResourceSet _xtextResourceSet = new XtextResourceSet();
            it.setContext(_xtextResourceSet);
        };
        JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
        this.fs = _doubleArrow;
        this.createProject("foo");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JavaIOFileSystemSupport(org.eclipse.xtend.core.macro.JavaIOFileSystemSupport) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider) IProjectConfigProvider(org.eclipse.xtext.workspace.IProjectConfigProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 59 with XtextResourceSet

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

the class FormatterFacade method format.

public String format(final String xtendCode) {
    try {
        final XtextResourceSet resourceSet = new XtextResourceSet();
        Resource _createResource = this.resourceFactory.createResource(URI.createURI("synthetic://to-be-formatted.xtend"));
        final XtextResource resource = ((XtextResource) _createResource);
        EList<Resource> _resources = resourceSet.getResources();
        _resources.add(resource);
        StringInputStream _stringInputStream = new StringInputStream(xtendCode);
        resource.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
        final ITextRegionAccess regionAccess = this.regionAccessBuilder.get().forNodeModel(resource).create();
        FormatterRequest _formatterRequest = new FormatterRequest();
        final Procedure1<FormatterRequest> _function = (FormatterRequest it) -> {
            it.setAllowIdentityEdits(false);
            it.setTextRegionAccess(regionAccess);
            it.setPreferences(TypedPreferenceValues.castOrWrap(this.cfgProvider.getPreferenceValues(resource)));
        };
        FormatterRequest request = ObjectExtensions.<FormatterRequest>operator_doubleArrow(_formatterRequest, _function);
        List<ITextReplacement> replacements = this.formatter.format(request);
        return regionAccess.getRewriter().renderToString(replacements);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Example 60 with XtextResourceSet

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

the class JdtBasedProcessorProvider method getClassLoader.

@Override
public ClassLoader getClassLoader(final EObject ctx) {
    ResourceSet _resourceSet = ctx.eResource().getResourceSet();
    final XtextResourceSet rs = ((XtextResourceSet) _resourceSet);
    final boolean isBuilder = ResourceSetContext.get(rs).isBuilder();
    final boolean isEditor = ResourceSetContext.get(rs).isEditor();
    if (isBuilder) {
        final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(rs.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
        if ((adapter != null)) {
            return adapter.getClassLoader();
        }
    }
    if (isEditor) {
        final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter_1 = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(this.getEditorResource(ctx).eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
        if ((adapter_1 != null)) {
            ClassLoader _classLoader = adapter_1.getClassLoader();
            boolean _tripleEquals = (_classLoader == null);
            if (_tripleEquals) {
                this.getEditorResource(ctx).eAdapters().remove(adapter_1);
            } else {
                return adapter_1.getClassLoader();
            }
        }
    }
    Object _classpathURIContext = rs.getClasspathURIContext();
    final IJavaProject project = ((IJavaProject) _classpathURIContext);
    final URLClassLoader classloader = this.createClassLoaderForJavaProject(project);
    if (isBuilder) {
        EList<Adapter> _eAdapters = rs.eAdapters();
        ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
        _eAdapters.add(_processorClassloaderAdapter);
    }
    if (isEditor) {
        EList<Adapter> _eAdapters_1 = this.getEditorResource(ctx).eAdapters();
        ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter_1 = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
        _eAdapters_1.add(_processorClassloaderAdapter_1);
    }
    return classloader;
}
Also used : ProcessorInstanceForJvmTypeProvider(org.eclipse.xtend.core.macro.ProcessorInstanceForJvmTypeProvider) IJavaProject(org.eclipse.jdt.core.IJavaProject) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) EObject(org.eclipse.emf.ecore.EObject) Adapter(org.eclipse.emf.common.notify.Adapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

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