@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); }
@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; }
public IResourceDescription get(final URI uri) { final ResourceSet set = getResourceSet(); final Resource resource = set.getResource(uri, true); if (resource != null) { Optional<IResourceDescription> optional = cache.get(ImportedResourceCache.class, resource, new Provider<Optional<IResourceDescription>>() { @Override public Optional<IResourceDescription> get() { IResourceServiceProvider serviceProvider = serviceProviderRegistry .getResourceServiceProvider(uri); if (serviceProvider == null) return Optional.empty(); final Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager(); if (resourceDescriptionManager == null) return Optional.empty(); IResourceDescription result = resourceDescriptionManager.getResourceDescription(resource); return Optional.of(result); } }); if (optional.isPresent()) { return optional.get(); } } return null; }
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); }
@Override public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) { return new DefaultResourceServiceProvider() { @Override public Manager getResourceDescriptionManager() { return resourceDescriptionManager; } }; }
@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()); }
@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()); }
@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); }
@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); }
@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); }
@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); }
@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()); }
/** * 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(); }
/** * Add deltas for the removed resources. * * @param deletedUris * URIs of the removed resources * @param deltas * Deltas * @param savedDescriptions * previously saved old resource descriptions */ protected void addDeletedURIsToDeltas(final Set<URI> deletedUris, final Set<Delta> deltas, final Map<URI, IResourceDescription> savedDescriptions) { for (final URI uri : deletedUris) { final IResourceDescription oldDescription = getSavedResourceDescription(savedDescriptions, uri); if (oldDescription != null) { final IResourceDescription.Manager manager = getResourceDescriptionManager(uri); if (manager != null) { deltas.add(manager.createDelta(oldDescription, null)); } } } }