Java Code Examples for org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions#setContainer()

The following examples show how to use org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions#setContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractIncrementalBuilderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected BuildRequest newBuildRequest(Procedure1<? super BuildRequest> init) {
	BuildRequest result = new BuildRequest();
	ResourceDescriptionsData newIndex = indexState.getResourceDescriptions().copy();
	result.setBaseDir(uri(""));
	XtextResourceSet rs = resourceSetProvider.get();
	rs.getURIConverter().getURIHandlers().clear();
	rs.getURIConverter().getURIHandlers().add(inMemoryURIHandler);
	rs.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
	ProjectDescription projectDescription = new ProjectDescription();
	projectDescription.setName("test-project");
	projectDescription.attachToEmfObject(rs);
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), rs);
	index.setContainer(projectDescription.getName(), newIndex);
	result.setResourceSet(rs);
	result.setDirtyFiles(new ArrayList<>());
	result.setDeletedFiles(new ArrayList<>());
	result.setAfterValidate((uri, issues) -> {
		Iterables.addAll(this.issues, issues);
		return Iterables.isEmpty(issues);
	});
	result.setAfterDeleteFile(f -> deleted.add(f));
	result.setAfterGenerateFile((source, target) -> generated.put(source, target));
	result.setState(new IndexState(newIndex, indexState.getFileMappings().copy()));
	init.apply(result);
	return result;
}
 
Example 2
Source File: XProjectManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Create an empty resource set. */
protected XtextResourceSet createFreshResourceSet(ResourceDescriptionsData newIndex) {
	if (resourceSet == null) {
		resourceSet = createNewResourceSet(newIndex);
	} else {
		ChunkedResourceDescriptions resDescs = ChunkedResourceDescriptions.findInEmfObject(resourceSet);

		for (Entry<String, ResourceDescriptionsData> entry : fullIndex.entries()) {
			resDescs.setContainer(entry.getKey(), entry.getValue());
		}
		resDescs.setContainer(projectDescription.getName(), newIndex);
	}
	return resourceSet;
}
 
Example 3
Source File: XProjectManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Create and configure a new resource set for this project. */
protected XtextResourceSet createNewResourceSet(ResourceDescriptionsData newIndex) {
	XtextResourceSet result = resourceSetProvider.get();
	result.setURIResourceMap(uriResourceMap);
	projectDescription.attachToEmfObject(result);
	ProjectConfigAdapter.install(result, projectConfig);
	attachWorkspaceResourceLocator(result);

	ChunkedResourceDescriptions index = fullIndex.toDescriptions(result);
	index.setContainer(projectDescription.getName(), newIndex);
	return result;
}
 
Example 4
Source File: ReusedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	if (ReusedTypeProviderTest.typeProvider == null) {
		String pathToSources = "/org/eclipse/xtext/common/types/testSetups";
		List<String> files = ReusedTypeProviderTest.readResource(pathToSources + "/files.list");
		ResourceDescriptionsData part = new ResourceDescriptionsData(Collections.emptySet());
		XtextResourceSet resourceSet = resourceSetProvider.get();
		ProjectDescription projectDesc = new ProjectDescription();
		projectDesc.setName("my-test-project");
		projectDesc.attachToEmfObject(resourceSet);
		ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), resourceSet);
		index.setContainer(projectDesc.getName(), part);
		resourceSet.setClasspathURIContext(ReusedTypeProviderTest.class.getClassLoader());

		typeProviderFactory.createTypeProvider(resourceSet);
		BuildRequest buildRequest = new BuildRequest();
		for (String file : files) {
			if (file != null) {
				String fullPath = pathToSources + "/" + file;
				URL url = ReusedTypeProviderTest.class.getResource(fullPath);
				buildRequest.getDirtyFiles().add(URI.createURI(url.toExternalForm()));
			}
		}
		buildRequest.setResourceSet(resourceSet);
		buildRequest.setState(new IndexState(part, new Source2GeneratedMapping()));
		builder.build(buildRequest, (URI it) -> {
			return resourceServiceProviderRegistry.getResourceServiceProvider(it);
		});
		ReusedTypeProviderTest.typeProvider = typeProviderFactory.findTypeProvider(resourceSet);
	}
}
 
Example 5
Source File: IndexedJvmTypeAccessTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetIndexedJvmTypeByURI() throws ClassNotFoundException {
	ProjectDescription projectDescription = new ProjectDescription();
	projectDescription.setName("test-project");
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), resourceSet);
	ResourceDescriptionsData data = new ResourceDescriptionsData(new ArrayList<>());
	index.setContainer(projectDescription.getName(), data);
	ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(resourceSet, data);

	Resource resource = resourceSet.createResource(URI.createURI("test.typesRefactoring"));

	BinaryClass binaryClass = BinaryClass.forName("testdata.Outer", getClass().getClassLoader());
	JvmDeclaredType outerType = declaredTypeFactory.createType(binaryClass);
	resource.getContents().add(outerType);
	JvmDeclaredType innerType = findType(outerType, "Inner");
	JvmDeclaredType innerMostType = findType(outerType, "InnerMost");

	IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resource.getURI());
	IResourceDescription description = serviceProvider.getResourceDescriptionManager().getResourceDescription(resource);
	data.addDescription(description.getURI(), description);

	URI javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getOuter").getReturnType().getType());
	EObject outerTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(outerType, outerTypeFromIndex);

	javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getInner").getReturnType().getType());
	EObject innerTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(innerType, innerTypeFromIndex);

	javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getInnerMost").getReturnType().getType());
	EObject innerMostTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(innerMostType, innerMostTypeFromIndex);
}
 
Example 6
Source File: ProjectManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create and configure a new resource set for this project.
 */
public XtextResourceSet createNewResourceSet(ResourceDescriptionsData newIndex) {
	XtextResourceSet result = resourceSetProvider.get();
	projectDescription.attachToEmfObject(result);
	ProjectConfigAdapter.install(result, projectConfig);
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(indexProvider.get(), result);
	index.setContainer(projectDescription.getName(), newIndex);
	externalContentSupport.configureResourceSet(result, openedDocumentsContentProvider);
	return result;
}
 
Example 7
Source File: ProjectManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create an empty resource set.
 */
protected XtextResourceSet createFreshResourceSet(ResourceDescriptionsData newIndex) {
	if (resourceSet == null) {
		resourceSet = createNewResourceSet(newIndex);
	} else {
		ChunkedResourceDescriptions resDescs = ChunkedResourceDescriptions.findInEmfObject(resourceSet);
		for (Map.Entry<String, ResourceDescriptionsData> entry : indexProvider.get().entrySet()) {
			resDescs.setContainer(entry.getKey(), entry.getValue());
		}
		resDescs.setContainer(projectDescription.getName(), newIndex);
	}
	return resourceSet;
}