org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions Java Examples

The following examples show how to use org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions. 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: JavaSourceLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
	bind(Resource.Factory.class).to(JavaResource.Factory.class);
	bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
	bind(IGenerator.class).to(IGenerator.NullGenerator.class);
	bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
	bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
	bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
	bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
	bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
	bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
	bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME))
			.toInstance("org.eclipse.xtext.java.Java");
	bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
	bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
	bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
	bind(IResourceDescriptionsProvider.class)
			.toInstance((ResourceSet rs) -> ChunkedResourceDescriptions.findInEmfObject(rs));
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
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 #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;
}
 
Example #8
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 #9
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	return createContainer(resourceDescriptions, descriptions,
			ProjectDescription.findInEmfObject(descriptions.getResourceSet()).getName());
}
 
Example #10
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc,
		IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	ProjectDescription projectDescription = ProjectDescription.findInEmfObject(descriptions.getResourceSet());
	List<IContainer> allContainers = new ArrayList<>();
	allContainers.add(createContainer(resourceDescriptions, descriptions, projectDescription.getName()));
	for (String name : projectDescription.getDependencies())
		allContainers.add(createContainer(resourceDescriptions, descriptions, name));
	return allContainers;
}
 
Example #11
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ChunkedResourceDescriptions getChunkedResourceDescriptions(IResourceDescriptions resourceDescriptions) {
	if (resourceDescriptions instanceof ChunkedResourceDescriptions)
		return (ChunkedResourceDescriptions) resourceDescriptions;
	if (resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions)
		return getChunkedResourceDescriptions(
				((LiveShadowedChunkedResourceDescriptions) resourceDescriptions).getGlobalDescriptions());
	return null;
}
 
Example #12
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IContainer createContainer(IResourceDescriptions resourceDescriptions,
		ChunkedResourceDescriptions chunkedResourceDescriptions, String projectName) {
	if (resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions) {
		return new LiveShadowedChunkedContainer((LiveShadowedChunkedResourceDescriptions) resourceDescriptions,
				projectName);
	} else {
		ResourceDescriptionsData container = chunkedResourceDescriptions.getContainer(projectName);
		return new ResourceDescriptionsBasedContainer(
				container != null ? container : new ResourceDescriptionsData(Collections.emptySet()));
	}
}
 
Example #13
Source File: LiveShadowedChunkedContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    WorkspaceConfig _workspaceConfig = new WorkspaceConfig();
    this.workspaceConfig = _workspaceConfig;
    ProjectConfig _projectConfig = new ProjectConfig("foo", this.workspaceConfig);
    this.fooProject = _projectConfig;
    ProjectConfig _projectConfig_1 = new ProjectConfig("bar", this.workspaceConfig);
    this.barProject = _projectConfig_1;
    final XtextResourceSet rs0 = this.resourceSetProvider.get();
    this.fooURI = IterableExtensions.<SourceFolder>head(this.fooProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("foo.livecontainertestlanguage");
    this.barURI = IterableExtensions.<SourceFolder>head(this.barProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("bar.livecontainertestlanguage");
    ResourceDescriptionsData _createResourceDescriptionData = this.createResourceDescriptionData(this._parseHelper.parse("foo", this.fooURI, rs0).eResource());
    Pair<String, ResourceDescriptionsData> _mappedTo = Pair.<String, ResourceDescriptionsData>of("foo", _createResourceDescriptionData);
    ResourceDescriptionsData _createResourceDescriptionData_1 = this.createResourceDescriptionData(this._parseHelper.parse("bar", this.barURI, rs0).eResource());
    Pair<String, ResourceDescriptionsData> _mappedTo_1 = Pair.<String, ResourceDescriptionsData>of("bar", _createResourceDescriptionData_1);
    final Map<String, ResourceDescriptionsData> chunks = Collections.<String, ResourceDescriptionsData>unmodifiableMap(CollectionLiterals.<String, ResourceDescriptionsData>newHashMap(_mappedTo, _mappedTo_1));
    this.rs1 = this.resourceSetProvider.get();
    new ChunkedResourceDescriptions(chunks, this.rs1);
    ProjectConfigAdapter.install(this.rs1, this.fooProject);
    this.liveShadowedChunkedResourceDescriptions = this.provider.get();
    this.liveShadowedChunkedResourceDescriptions.setContext(this.rs1);
    LiveShadowedChunkedContainer _liveShadowedChunkedContainer = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "foo");
    this.fooContainer = _liveShadowedChunkedContainer;
    LiveShadowedChunkedContainer _liveShadowedChunkedContainer_1 = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "bar");
    this.barContainer = _liveShadowedChunkedContainer_1;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #14
Source File: WorkspaceManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns the current index.
 */
public IResourceDescriptions getIndex() {
	return new ChunkedResourceDescriptions(fullIndex);
}
 
Example #15
Source File: ConcurrentChunkedIndex.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** Create a snapshot of this index. */
public synchronized ChunkedResourceDescriptions toDescriptions() {
	return new ChunkedResourceDescriptions(containerHandle2Data);
}
 
Example #16
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public boolean shouldUseProjectDescriptionBasedContainers(IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	return (descriptions != null && descriptions.getResourceSet() != null
			&& ProjectDescription.findInEmfObject(descriptions.getResourceSet()) != null);
}
 
Example #17
Source File: LiveShadowedChunkedContainer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected ChunkedResourceDescriptions getChunkedResourceDescriptions() {
	return (ChunkedResourceDescriptions) descriptions.getGlobalDescriptions();
}
 
Example #18
Source File: ConcurrentChunkedIndex.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** Create a snapshot of this index and attach it to the given resource set. */
public synchronized ChunkedResourceDescriptions toDescriptions(ResourceSet resourceSet) {
	return new ChunkedResourceDescriptions(containerHandle2Data, resourceSet);
}