Search in sources :

Example 1 with XtextResourceSet

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

the class XtextResourceSetBasedProjectProvider method getJavaProject.

@Override
public IJavaProject getJavaProject(ResourceSet resourceSet) {
    if (resourceSet instanceof XtextResourceSet) {
        XtextResourceSet xtextResourceSet = (XtextResourceSet) resourceSet;
        Object context = xtextResourceSet.getClasspathURIContext();
        if (context instanceof IJavaProject)
            return (IJavaProject) context;
    }
    return null;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 2 with XtextResourceSet

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

the class AbstractXtextTests method doGetResource.

protected 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);
    if (resource instanceof LazyLinkingResource) {
        ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    } else {
        EcoreUtil.resolveAll(resource);
    }
    return resource;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 3 with XtextResourceSet

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

the class AbstractXbaseContentAssistBugTest method initializeTypeProvider.

protected void initializeTypeProvider(final XtextResource result) {
    ResourceSet _resourceSet = result.getResourceSet();
    final XtextResourceSet resourceSet = ((XtextResourceSet) _resourceSet);
    final JdtTypeProviderFactory typeProviderFactory = new JdtTypeProviderFactory(this);
    typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    resourceSet.setClasspathURIContext(this.getJavaProject(resourceSet));
}
Also used : JdtTypeProviderFactory(org.eclipse.xtext.common.types.access.jdt.JdtTypeProviderFactory) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 4 with XtextResourceSet

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

the class CompilationTestHelper method unLoadedResourceSet.

/**
 * same as {@link #resourceSet(Pair...)} but without actually loading the created resources.
 */
@SuppressWarnings("unchecked")
public ResourceSet unLoadedResourceSet(Pair<String, ? extends CharSequence>... resources) throws IOException {
    XtextResourceSet result = resourceSetProvider.get();
    for (Pair<String, ? extends CharSequence> entry : resources) {
        URI uri = copyToWorkspace(getSourceFolderPath() + "/" + entry.getKey(), entry.getValue());
        Resource resource = result.createResource(uri);
        if (resource == null)
            throw new IllegalStateException("Couldn't create resource for URI " + uri + ". Resource.Factory not registered?");
    }
    return result;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 5 with XtextResourceSet

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

the class AbstractXbaseContentAssistTest method getResourceSet.

protected final XtextResourceSet getResourceSet() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    IJvmTypeProvider.Factory typeProviderFactory = new JdtTypeProviderFactory(this);
    typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    resourceSet.setClasspathURIContext(getJavaProject(resourceSet));
    return resourceSet;
}
Also used : JdtTypeProviderFactory(org.eclipse.xtext.common.types.access.jdt.JdtTypeProviderFactory) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider)

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