org.eclipse.xtext.resource.IResourceDescription.Manager Java Examples

The following examples show how to use org.eclipse.xtext.resource.IResourceDescription.Manager. 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: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add deltas for the removed resources.
 *
 * @param deletedUris
 *          URIs of the removed resources
 * @param deltas
 *          Deltas
 * @param savedDescriptions
 *          previously saved old resource descriptions
 * @param savedGeneratedObjectsInfo
 *          previously saved old generated objects info
 */
protected void addDeletedURIsToDeltas(final Set<URI> deletedUris, final Set<Delta> deltas, final Map<URI, IResourceDescription> savedDescriptions, final Map<URI, DerivedObjectAssociations> savedGeneratedObjectsInfo) {
  for (final URI uri : deletedUris) {
    final IResourceDescription oldDescription = getSavedResourceDescription(savedDescriptions, uri);
    if (oldDescription != null) {
      final IResourceDescription.Manager manager = getResourceDescriptionManager(uri);
      if (manager != null) {
        Delta delta = manager.createDelta(oldDescription, null);
        if (delta instanceof AbstractResourceDescriptionDelta) {
          // For languages that support extended delta, pass generated object info to builder participants using delta
          // All languages that manage life cycle of generated objects must support extended delta
          final DerivedObjectAssociations generatedObjectsInfo = getSavedDerivedObjectAssociations(savedGeneratedObjectsInfo, delta.getUri());
          ((AbstractResourceDescriptionDelta) delta).addExtensionData(DerivedObjectAssociations.class, generatedObjectsInfo);
        }
        deltas.add(delta);
      }
    }
  }
}
 
Example #2
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isReparseRequired(XtextResource resource, IResourceDescription.Event event) {
	IResourceDescription.Manager resourceDescriptionManager = resource.getResourceServiceProvider().getResourceDescriptionManager();
	IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
	if (resourceDescriptionManager.isAffected(event.getDeltas(), description, resourceDescriptions)) {
		return true;
	}
	if (!isDirty() && !dirtyStateManager.hasContent(resource.getURI())) {
		IResourceDescription originalDescription = resourceDescriptions.getResourceDescription(resource.getURI());
		if (originalDescription != null && descriptionUtils != null) {
			Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(originalDescription);
			for(IResourceDescription.Delta delta: event.getDeltas()) {
				if (delta.haveEObjectDescriptionsChanged() && outgoingReferences.contains(delta.getUri()))
					return true;
			}
		}
	}
	return false;
}
 
Example #3
Source File: ResourceSetBasedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(URI uri) {
	if (data != null) {
		return data.getResourceDescription(uri);
	}
	Resource resource = resourceSet.getResource(uri, false);
	if (resource == null)
		return null;
	IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
	if (resourceServiceProvider == null)
		return null;
	Manager manager = resourceServiceProvider.getResourceDescriptionManager();
	if (manager == null)
		return null;
	return manager.getResourceDescription(resource);
}
 
Example #4
Source File: LoadOnDemandResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IResourceDescription getResourceDescription(URI uri) {
	IResourceDescription result = delegate.getResourceDescription(uri);
	if (result == null) {
		Resource resource = EcoreUtil2.getResource(context, uri.toString());
		if (resource != null) {
			IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
			if (serviceProvider==null)
				throw new IllegalStateException("No "+IResourceServiceProvider.class.getSimpleName()+" found in registry for uri "+uri);
			final Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager();
			if (resourceDescriptionManager == null)
				throw new IllegalStateException("No "+IResourceDescription.Manager.class.getName()+" provided by service provider for URI "+uri);
			result = resourceDescriptionManager.getResourceDescription(resource);
		}
	}
	return result;
}
 
Example #5
Source File: XtextResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testComputeEObjectDescriptionsForEmptyFile() throws Exception {
	Resource res = getResourceAndExpect(new StringInputStream(""),URI.createURI("foo.xtext"),1);
	Manager manager = get(IResourceDescription.Manager.class);
	IResourceDescription description = manager.getResourceDescription(res);
	Iterable<IEObjectDescription> iterable = description.getExportedObjects();
	assertTrue(Lists.newArrayList(iterable).isEmpty());
}
 
Example #6
Source File: ImportedResourceCache.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public IResourceDescription get(final URI uri) {
	refreshFile(uri);
	try {
		return (IResourceDescription) getEditingDomain()
				.runExclusive(new RunnableWithResult.Impl<IResourceDescription>() {
					@Override
					public void run() {
						final ResourceSet set = getResourceSet();
						final Resource resource = set.getResource(uri, true);
						if (resource != null) {
							IResourceServiceProvider serviceProvider = serviceProviderRegistry
									.getResourceServiceProvider(uri);
							if (serviceProvider == null) {
								setResult(new DefaultResourceDescription(resource, delegateStrategy));
								return;
							}
							final Manager resourceDescriptionManager = serviceProvider
									.getResourceDescriptionManager();
							if (resourceDescriptionManager == null)
								return;
							IResourceDescription result = resourceDescriptionManager
									.getResourceDescription(resource);
							setResult(result);
						}
					}
				});
	} catch (InterruptedException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #7
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets a map of URIs indexed by their {@link IResourceDescription.Manager}.
 *
 * @param uRIs
 *          the URIs to index
 * @return the map of URIs indexed by their managers
 */
private ImmutableListMultimap<Manager, URI> getUrisByManager(final Set<URI> uRIs) {
  ImmutableListMultimap.Builder<Manager, URI> builder = ImmutableListMultimap.builder();
  for (URI uri : uRIs) {
    Manager mgr = getResourceDescriptionManager(uri);
    if (mgr != null) {
      builder.put(mgr, uri);
    }
  }
  return builder.build();
}
 
Example #8
Source File: ProfilingTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSimple() throws Exception {
		with(new IndexTestLanguageStandaloneSetup(){
			@Override
			public Injector createInjector() {
				return Guice.createInjector(new org.eclipse.xtext.index.IndexTestLanguageRuntimeModule(){
					@Override
					public java.lang.Class<? extends org.eclipse.xtext.scoping.IScopeProvider> bindIScopeProvider() {
						return OptimizedScopeProvider.class;
					}
				}
				);
			}
		});
		XtextResourceSet rs = get(XtextResourceSet.class);
		Resource outer = rs.createResource(URI.createURI("outer."+getCurrentFileExtension()));
		outer.load(new StringInputStream(outerFile(ELEMENTS)), null);
		Resource inner = rs.createResource(URI.createURI("inner."+getCurrentFileExtension()));
		StopWatch watch = new StopWatch();
		
		inner.load(new StringInputStream(generateFile(ELEMENTS)), null);
//		resource.load(new StringInputStream(generateFile(1000)), null);
		watch.resetAndLog("loading");
		EcoreUtil.resolveAll(inner);
		watch.resetAndLog("linking");
		
		assertTrue(inner.getErrors().size()+" errors ", inner.getErrors().isEmpty());
		Manager manager = get(IResourceDescription.Manager.class);
//		Yourkit.startTracing();
		IResourceDescription iResourceDescription = manager.getResourceDescription(inner);
		Sets.newHashSet(iResourceDescription.getReferenceDescriptions());
//		Yourkit.stopCpuProfiling();
		watch.resetAndLog("resourcedescriptions");
//		System.out.println(Sets.newHashSet(inner.getAllContents()).size());
	}
 
Example #9
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	with(new IndexTestLanguageStandaloneSetup());

	globalScopeProvider = new ResourceSetGlobalScopeProvider();
	nameProvider = new DefaultDeclarativeQualifiedNameProvider();
	nameConverter = new IQualifiedNameConverter.DefaultImpl();
	final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
	strategy.setQualifiedNameProvider(nameProvider);
	final DefaultResourceDescriptionManager resourceDescMnr = new DefaultResourceDescriptionManager() {
		@Override
		public IResourceDescription getResourceDescription(Resource resource) {
			DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource,
					strategy);
			return resourceDescription;
		}
		
	};
	final DefaultResourceServiceProvider provider = new DefaultResourceServiceProvider() {
		@Override
		public Manager getResourceDescriptionManager() {
			return resourceDescMnr;
		}
	};
	globalScopeProvider.setGlobalResourceDecriptionProvider(new GlobalResourceDescriptionProvider(new ResourceServiceProviderRegistryImpl() {
		@Override
		public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) {
			return provider;
		}
	}));
	CaseInsensitivityHelper caseInsensitivityHelper = new CaseInsensitivityHelper();
	globalScopeProvider.setCaseInsensitivityHelper(caseInsensitivityHelper);
	scopeProvider = new ImportedNamespaceAwareLocalScopeProvider(globalScopeProvider, nameProvider, nameConverter, caseInsensitivityHelper);
}
 
Example #10
Source File: ResourceSetBasedResourceDescriptionsTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) {
	return new DefaultResourceServiceProvider() {
		@Override
		public Manager getResourceDescriptionManager() {
			return resourceDescriptionManager;
		}
	};
}
 
Example #11
Source File: XtextResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug350695() throws Exception {
	Resource res = getResource(new StringInputStream("grammar org.foo.Zonk generate x \"someURI\" Start : 'main';"), URI.createURI("foo.xtext"));
	Manager manager = get(IResourceDescription.Manager.class);
	IResourceDescription description = manager.getResourceDescription(res);
	assertTrue(Iterables.isEmpty(description.getExportedObjects(XtextPackage.Literals.GRAMMAR, QualifiedName.create("org.foo.Zonk"), false)));
	IEObjectDescription element = Iterables.getOnlyElement(
			description.getExportedObjects(XtextPackage.Literals.GRAMMAR, QualifiedName.create("org","foo","Zonk"), false));
	assertNotNull(element);
}
 
Example #12
Source File: XtextResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetExportedEObjects() throws Exception {
	Resource res = getResource(new StringInputStream("grammar foo generate x \"someURI\" Start : 'main';"),URI.createURI("foo.xtext"));
	Manager manager = get(IResourceDescription.Manager.class);
	IResourceDescription description = manager.getResourceDescription(res);
	Iterable<IEObjectDescription> iterable = description.getExportedObjects();
	assertTrue(Lists.newArrayList(iterable).size()==3);
}
 
Example #13
Source File: XtextResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetExportedEObjectsErroneousResource() throws Exception {
	Resource res = getResourceAndExpect(new StringInputStream("grammar foo Start : 'main';"),URI.createURI("foo.xtext"),1);
	Manager manager = get(IResourceDescription.Manager.class);
	IResourceDescription description = manager.getResourceDescription(res);
	Iterable<IEObjectDescription> iterable = description.getExportedObjects();
	assertTrue(Lists.newArrayList(iterable).size()==2);
}
 
Example #14
Source File: XtextResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testComputeEObjectDescriptionsForUnnamedGrammar() throws Exception {
	Resource res = getResourceAndExpect(new StringInputStream("grammar "),URI.createURI("foo.xtext"),1);
	Manager manager = get(IResourceDescription.Manager.class);
	IResourceDescription description = manager.getResourceDescription(res);
	Iterable<IEObjectDescription> iterable = description.getExportedObjects();
	assertTrue(Lists.newArrayList(iterable).isEmpty());
}
 
Example #15
Source File: NamesAreUniqueValidatorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) {
	return new DefaultResourceServiceProvider() {
		@Override
		public Manager getResourceDescriptionManager() {
			return resourceDescriptionManager;
		}
	}; 
}
 
Example #16
Source File: EagerResourceSetBasedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private IResourceDescription computeResourceDescription(URI uri) {
	Resource resource = resourceSet.getResource(uri, false);
	if (resource == null)
		return null;
	IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
	if (resourceServiceProvider == null)
		return null;
	Manager manager = resourceServiceProvider.getResourceDescriptionManager();
	if (manager == null)
		return null;
	return manager.getResourceDescription(resource);
}
 
Example #17
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.8
 */
protected IResourceDescription.Manager getResourceDescriptionManagerIfOwnLanguage(XtextResource resource) {
	IResourceServiceProvider rsp = resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());
	if (rsp == null)
		return null;
	String uriLanguageName = rsp.get(LanguageInfo.class).getLanguageName();
	String resourceLanguageName = resource.getLanguageName();
	if (!uriLanguageName.equals(resourceLanguageName))
		return null;
	return getResourceDescriptionManager(resource.getURI());
}
 
Example #18
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
public void announceDirtyState(XtextResource resource) {
	if (resource == null || !dirtyResource.isInitialized())
		return;
	ClientAwareDirtyResource clientAwareResource = delegatingClientAwareResource;
	if (state != State.CLEAN || ((!resource.isTrackingModification() || resource.isModified()) && clientAwareResource.isDirty() && dirtyStateManager.manageDirtyState(clientAwareResource))) {
		synchronized (dirtyStateManager) {
			Manager resourceDescriptionManager = getResourceDescriptionManagerIfOwnLanguage(resource);
			if (resourceDescriptionManager != null) {
				final IResourceDescription newDescription = resourceDescriptionManager.getResourceDescription(resource);
				if (state == State.SHOULD_UPDATE || haveEObjectDescriptionsChanged(newDescription, resourceDescriptionManager)) {
					if(state == State.SHOULD_UPDATE) {
						if(clientAwareResource.isDirty())
							state = State.DIRTY;
						else 
							state = State.CLEAN;
					}
					IResourceDescription oldDescription = dirtyResource.getDescription();
					dirtyResource.copyState(newDescription);
					if (resoureStorageFacade != null && (resource instanceof StorageAwareResource)) {
						try {
							StorageAwareResource storageAwareResource = (StorageAwareResource) resource;
							class MyByteArrayOutputStream extends ByteArrayOutputStream {
								@Override
								public synchronized byte[] toByteArray() {
									return buf;
								}
								public int length() { 
									return count;
								}
							}
							final MyByteArrayOutputStream bout = new MyByteArrayOutputStream();
							ResourceStorageWritable resourceOutputStream = resoureStorageFacade.createResourceStorageWritable(bout);
							resourceOutputStream.writeResource(storageAwareResource);
							dirtyResource.setResourceStorageLoadableProvider(new Provider<ResourceStorageLoadable>() {
								@Override
								public ResourceStorageLoadable get() {
									return resoureStorageFacade.createResourceStorageLoadable(new ByteArrayInputStream(bout.toByteArray(), 0 , bout.length()));
								}
							});
						} catch(IOException e) {
							// something went wrong when writing the resource - stream's content is bogus and not attached to the dirty resource info
							LOG.warn("Cannot persist storage for " + resource.getURI(), e);
						}
					}
					if (dirtyStateManager instanceof DirtyStateManager) {
						((DirtyStateManager)dirtyStateManager).announceDirtyStateChanged(oldDescription, clientAwareResource);
					} else {
						dirtyStateManager.announceDirtyStateChanged(clientAwareResource);
					}
				}
			}
		}
	}
}
 
Example #19
Source File: XtendRuntimeModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Class<? extends Manager> bindIResourceDescription$Manager() {
	return XtendResourceDescriptionManager.class;
}
 
Example #20
Source File: SharedCommonTypesResourceServiceProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Manager getResourceDescriptionManager() {
	return null;
}
 
Example #21
Source File: DirtyStateEditorSupport.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
protected IResourceDescription.Manager getResourceDescriptionManager(URI resourceURI) {
	return resourceServiceProviderRegistry.getResourceServiceProvider(resourceURI).get(DirtyStateResourceDescription.Manager.class);
}