org.eclipse.xtext.resource.persistence.SourceLevelURIsAdapter Java Examples
The following examples show how to use
org.eclipse.xtext.resource.persistence.SourceLevelURIsAdapter.
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: N4ClusteringBuilderState.java From n4js with Eclipse Public License 1.0 | 6 votes |
protected void installSourceLevelURIs(BuildData buildData) { ResourceSet resourceSet = buildData.getResourceSet(); Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue()); Set<URI> sourceUris = newHashSet(); for (URI uri : sourceLevelUris) { if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) { sourceUris.add(uri); // unload resources loaded from storage previously Resource resource = resourceSet.getResource(uri, false); if (resource instanceof StorageAwareResource) { if (((StorageAwareResource) resource).isLoadedFromStorage()) { resource.unload(); } } } } SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, sourceUris); }
Example #2
Source File: ResourceForIEditorInputFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void configureResourceSet(ResourceSet resourceSet, URI primaryURI) { // TODO: Filter external content - primary resource should not use dirty state externalContentSupport.configureResourceSet(resourceSet, externalContentProvider); if (!(resourceServiceProvider instanceof IResourceServiceProviderExtension) || ((IResourceServiceProviderExtension)resourceServiceProvider).isSource(primaryURI)) { SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.singleton(primaryURI)); resourceSet.eAdapters().add(new ResourceStorageProviderAdapter() { @Override public ResourceStorageLoadable getResourceStorageLoadable(StorageAwareResource resource) { if (!dirtyStateManager.hasContent(resource.getURI())) { return null; } return ((DirtyStateManager)dirtyStateManager).getResourceStorageLoadable(resource.getURI()); } }); } }
Example #3
Source File: ClusteringBuilderState.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void installSourceLevelURIs(BuildData buildData) { ResourceSet resourceSet = buildData.getResourceSet(); Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue()); Set<URI> sourceUris = newHashSet(); for (URI uri : sourceLevelUris) { if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) { sourceUris.add(uri); // unload resources loaded from storage previously Resource resource = resourceSet.getResource(uri, false); if (resource instanceof StorageAwareResource) { if (((StorageAwareResource) resource).isLoadedFromStorage()) { resource.unload(); } } } } SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, sourceUris); }
Example #4
Source File: XClusteringStorageAwareResourceLoader.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Execute the given operation in a clustered fashion. */ public <T> List<T> executeClustered(Iterable<URI> uris, Function1<? super Resource, ? extends T> operation) { int loadedURIsCount = 0; Set<URI> sourceLevelURIs = new HashSet<>(); List<Resource> resources = new ArrayList<>(); List<T> result = new ArrayList<>(); Iterator<URI> iter = uris.iterator(); while (iter.hasNext()) { URI uri = iter.next(); XtextResourceSet resourceSet = context.getResourceSet(); if (!context.getClusteringPolicy().continueProcessing(resourceSet, uri, loadedURIsCount)) { result.addAll(ListExtensions.map(resources, operation::apply)); this.clearResourceSet(); resources.clear(); loadedURIsCount = 0; } loadedURIsCount++; if (this.isSource(uri)) { sourceLevelURIs.add(uri); Resource existingResource = resourceSet.getResource(uri, false); if (existingResource instanceof StorageAwareResource) { if (((StorageAwareResource) existingResource).isLoadedFromStorage()) { existingResource.unload(); } } SourceLevelURIsAdapter.setSourceLevelUrisWithoutCopy(resourceSet, sourceLevelURIs); } resources.add(resourceSet.getResource(uri, true)); } result.addAll(ListExtensions.map(resources, operation::apply)); return result; }
Example #5
Source File: ResourceStorageTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testShouldLoadFromStorage() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package mypack"); _builder.newLine(); _builder.newLine(); _builder.append("class MyClass {"); _builder.newLine(); _builder.append("\t"); _builder.append("public def void foo() {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final IFile file = this.helper.createFile("mypack/MyClass.xtend", _builder.toString()); IResourcesSetupUtil.waitForBuild(); final URI uri = this.uriMapper.getUri(file); final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject()); SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList())); Resource _createResource = resourceSet.createResource(uri); final StorageAwareResource resource = ((StorageAwareResource) _createResource); final Procedure0 _function = () -> { Assert.assertTrue(resource.getResourceStorageFacade().shouldLoadFromStorage(resource)); }; this.doWorkInJob(_function); NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); file.delete(true, _nullProgressMonitor); IResourcesSetupUtil.waitForBuild(); final Procedure0 _function_1 = () -> { Assert.assertFalse(resource.getResourceStorageFacade().shouldLoadFromStorage(resource)); }; this.doWorkInJob(_function_1); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #6
Source File: ClusteringStorageAwareResourceLoader.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Execute the given operation in a clustered fashion. */ public <T> Iterable<T> executeClustered(Iterable<URI> uris, Function1<? super Resource, ? extends T> operation) { int loadedURIsCount = 0; Set<URI> sourceLevelURIs = new HashSet<>(); List<Resource> resources = new ArrayList<>(); List<T> result = new ArrayList<>(); Iterator<URI> iter = uris.iterator(); while (iter.hasNext()) { URI uri = iter.next(); XtextResourceSet resourceSet = context.getResourceSet(); if (!context.getClusteringPolicy().continueProcessing(resourceSet, uri, loadedURIsCount)) { FluentIterable.from(resources).transform(operation::apply).copyInto(result); clearResourceSet(); resources.clear(); loadedURIsCount = 0; } loadedURIsCount++; if (isSource(uri)) { sourceLevelURIs.add(uri); Resource existingResource = resourceSet.getResource(uri, false); if (existingResource instanceof StorageAwareResource) { if (((StorageAwareResource) existingResource).isLoadedFromStorage()) { existingResource.unload(); } } SourceLevelURIsAdapter.setSourceLevelUrisWithoutCopy(resourceSet, sourceLevelURIs); } resources.add(resourceSet.getResource(uri, true)); } FluentIterable.from(resources).transform(operation::apply).copyInto(result); return result; }
Example #7
Source File: ResourceStorageTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Test public void testUpstreamResourcesAreLoadedFromStorage() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package mypack"); _builder.newLine(); _builder.newLine(); _builder.append("class MyClass {"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this.helper.createFile("mypack/MyClass.xtend", _builder.toString()); final IProject downStreamProject = WorkbenchTestHelper.createPluginProject("downstream", this.helper.getProject().getName()); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("package downstream"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("class SomeClass {"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("def void foo(mypack.MyClass myClass) {"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("}"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); final IFile downstreamFile = this.helper.createFileImpl("/downstream/src/downstream/SomeClass.xtend", _builder_1.toString()); IResourcesSetupUtil.waitForBuild(); final URI downstreamUri = this.uriMapper.getUri(downstreamFile); final ResourceSet resourceSet = this.resourceSetProvider.get(downStreamProject); SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(downstreamUri))); Resource _resource = resourceSet.getResource(downstreamUri, true); final StorageAwareResource downstreamResource = ((StorageAwareResource) _resource); EObject _get = downstreamResource.getContents().get(1); final JvmGenericType type = ((JvmGenericType) _get); final JvmType parameterType = IterableExtensions.<JvmFormalParameter>head(IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(type.getMembers(), JvmOperation.class)).getParameters()).getParameterType().getType(); Assert.assertNotNull(parameterType); Resource _eResource = parameterType.eResource(); Assert.assertTrue(((StorageAwareResource) _eResource).isLoadedFromStorage()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }