Java 类org.eclipse.xtext.resource.IContainer 实例源码

项目:n4js    文件:UserDataAwareScope.java   
/**
 * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the
 * produced scope would be empty.
 *
 * @param canLoadFromDescriptionHelper
 *            utility to decide if a resource must be loaded from source or may be loaded from the index.
 */
public static IScope createScope(
        IScope outer,
        ISelectable selectable,
        Predicate<IEObjectDescription> filter,
        EClass type, boolean ignoreCase,
        ResourceSet resourceSet,
        CanLoadFromDescriptionHelper canLoadFromDescriptionHelper,
        IContainer container) {
    if (selectable == null || selectable.isEmpty())
        return outer;
    IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet,
            canLoadFromDescriptionHelper,
            container);
    return scope;
}
项目:xtext-extras    文件:JavaSourceLanguageRuntimeModule.java   
@Override
protected void configure() {
  this.<Resource.Factory>bind(Resource.Factory.class).to(JavaResource.Factory.class);
  this.<IResourceValidator>bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
  this.<IGenerator>bind(IGenerator.class).to(IGenerator.NullGenerator.class);
  this.<IEncodingProvider>bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
  this.<IResourceServiceProvider>bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
  this.<IContainer.Manager>bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
  this.<IResourceDescription.Manager>bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
  this.<IQualifiedNameProvider>bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
  this.<String>bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
  this.<String>bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("org.eclipse.xtext.java.Java");
  this.<IJvmTypeProvider.Factory>bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
  this.<ClassLoader>bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
  this.<IReferableElementsUnloader>bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
  final IResourceDescriptionsProvider _function = (ResourceSet it) -> {
    return ChunkedResourceDescriptions.findInEmfObject(it);
  };
  this.<IResourceDescriptionsProvider>bind(IResourceDescriptionsProvider.class).toInstance(_function);
}
项目:xtext-extras    文件:BuilderIntegrationFragment.java   
@Override
public Set<Binding> getGuiceBindingsRt(Grammar grammar) {
    return new BindFactory()
    .addTypeToType(IContainer.Manager.class.getName(), StateBasedContainerManager.class.getName())
    .addTypeToType(IAllContainersState.Provider.class.getName(),
            org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.class.getName())
    .addConfiguredBinding(
                IResourceDescriptions.class.getName(),
                "binder.bind(" + IResourceDescriptions.class.getName() + ".class"
                        + ").to("
                        + ResourceSetBasedResourceDescriptions.class.getName() + ".class)")
        .addConfiguredBinding(
                IResourceDescriptions.class.getName() + "Persisted",
                "binder.bind("+ IResourceDescriptions.class.getName() + ".class"
                        + ").annotatedWith(com.google.inject.name.Names.named("
                        + "org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to("
                        + ResourceSetBasedResourceDescriptions.class.getName() + ".class)")
        .getBindings();
}
项目:xtext-core    文件:StateBasedContainerManager.java   
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
    if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
        return delegate.getContainer(desc, resourceDescriptions);
    }
    String root = internalGetContainerHandle(desc, resourceDescriptions);
    if (root == null) {
        if (log.isDebugEnabled())
            log.debug("Cannot find IContainer for: " + desc.getURI());
        return IContainer.NULL_CONTAINER;
    }
    IContainer result = createContainer(root, resourceDescriptions);
    if (!result.hasResourceDescription(desc.getURI())) {
        // desc has not been saved -> merge containers
        result = new DescriptionAddingContainer(desc, result);
    }
    return result;
}
项目:xtext-core    文件:StateBasedContainerManager.java   
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
    if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
        return delegate.getVisibleContainers(desc, resourceDescriptions);
    }
    String root = internalGetContainerHandle(desc, resourceDescriptions);
    if (root == null) {
        if (log.isDebugEnabled())
            log.debug("Cannot find IContainer for: " + desc.getURI());
        return Collections.emptyList();
    }
    List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
    List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
    if (!result.isEmpty()) {
        IContainer first = result.get(0);
        if (!first.hasResourceDescription(desc.getURI())) {
            first = new DescriptionAddingContainer(desc, first);
            result.set(0, first);
        }
    }
    return result;
}
项目:xtext-core    文件:SimpleResourceDescriptionsBasedContainerManager.java   
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
    if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
        return delegate.getContainer(desc, resourceDescriptions);
    }
    ResourceDescriptionsBasedContainer result = new ResourceDescriptionsBasedContainer(resourceDescriptions) {
        // this used to be the default implementation, which is wrong.
        // we fixed the orginal and moved the wrong impl here since old clients might see much worse performance with the new impl. 
        @Override
        public boolean hasResourceDescription(URI uri) {
            return true;
        }
    };
    result.setUriToDescriptionCacheEnabled(false);
    return result;
}
项目:xtext-core    文件:DefaultGlobalScopeProvider.java   
protected List<IContainer> getVisibleContainers(Resource resource) {
    IResourceDescription description = descriptionManager.getResourceDescription(resource);
    IResourceDescriptions resourceDescriptions = getResourceDescriptions(resource);
    String cacheKey = getCacheKey("VisibleContainers", resource.getResourceSet());
    OnChangeEvictingCache.CacheAdapter cache = new OnChangeEvictingCache().getOrCreate(resource);
    List<IContainer> result = null;
    result = cache.get(cacheKey);
    if (result == null) {
        result = containerManager.getVisibleContainers(description, resourceDescriptions);
        // SZ: I'ld like this dependency to be moved to the implementation of the
        // container manager, but it is not aware of a CacheAdapter
        if (resourceDescriptions instanceof IResourceDescription.Event.Source) {
            IResourceDescription.Event.Source eventSource = (Source) resourceDescriptions;
            DelegatingEventSource delegatingEventSource = new DelegatingEventSource(eventSource);
            delegatingEventSource.addListeners(Lists.newArrayList(Iterables.filter(result, IResourceDescription.Event.Listener.class)));
            delegatingEventSource.initialize();
            cache.addCacheListener(delegatingEventSource);
        }
        cache.set(cacheKey, result);
    }
    return result;
}
项目:xtext-core    文件:ProjectDescriptionBasedContainerManager.java   
@Override
public List<IContainer> getVisibleContainers(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
  final ChunkedResourceDescriptions chunkedResourceDescriptions = this.getChunkedResourceDescriptions(resourceDescriptions);
  if ((chunkedResourceDescriptions == null)) {
    String _name = ChunkedResourceDescriptions.class.getName();
    String _plus = ("expected " + _name);
    throw new IllegalArgumentException(_plus);
  }
  final ResourceSet resourceSet = chunkedResourceDescriptions.getResourceSet();
  final ProjectDescription projectDescription = ProjectDescription.findInEmfObject(resourceSet);
  final ArrayList<IContainer> allContainers = CollectionLiterals.<IContainer>newArrayList();
  allContainers.add(this.createContainer(resourceDescriptions, chunkedResourceDescriptions, projectDescription.getName()));
  List<String> _dependencies = projectDescription.getDependencies();
  for (final String name : _dependencies) {
    allContainers.add(this.createContainer(resourceDescriptions, chunkedResourceDescriptions, name));
  }
  return allContainers;
}
项目:xtext-core    文件:ProjectDescriptionBasedContainerManager.java   
protected IContainer createContainer(final IResourceDescriptions resourceDescriptions, final ChunkedResourceDescriptions chunkedResourceDescriptions, final String projectName) {
  IContainer _xifexpression = null;
  if ((resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions)) {
    _xifexpression = new LiveShadowedChunkedContainer(((LiveShadowedChunkedResourceDescriptions)resourceDescriptions), projectName);
  } else {
    ResourceDescriptionsData _elvis = null;
    ResourceDescriptionsData _container = chunkedResourceDescriptions.getContainer(projectName);
    if (_container != null) {
      _elvis = _container;
    } else {
      Set<IResourceDescription> _emptySet = CollectionLiterals.<IResourceDescription>emptySet();
      ResourceDescriptionsData _resourceDescriptionsData = new ResourceDescriptionsData(_emptySet);
      _elvis = _resourceDescriptionsData;
    }
    _xifexpression = new ResourceDescriptionsBasedContainer(_elvis);
  }
  return _xifexpression;
}
项目:xtext-core    文件:AbstractLiveContainerTest.java   
@Test
public void testContainerAddRemove() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    parse("other", resourceSet);
    IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
    IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
    List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
    assertEquals(1, containers.size());
    IContainer container = containers.get(0);

    assertEquals("local, other", format(container.getExportedObjects()));

    Resource foo = parse("foo", resourceSet).eResource();
    assertEquals("foo, local, other", format(container.getExportedObjects()));

    resourceSet.getResources().remove(foo);
    assertEquals("local, other", format(container.getExportedObjects()));
}
项目:xtext-core    文件:AbstractLiveContainerTest.java   
@Test
public void testContainerLoadUnload() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    Resource foo = resourceSet.createResource(computeUnusedUri(resourceSet));
    IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
    IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
    List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
    assertEquals(1, containers.size());
    IContainer container = containers.get(0);

    //      assertEquals("local", format(container.getExportedObjects()));

    foo.load(new StringInputStream("foo"), null);
    assertEquals("foo, local", format(container.getExportedObjects()));

    //      foo.unload();
    //      assertEquals("local", format(container.getExportedObjects()));
}
项目:dsl-devkit    文件:CachingStateBasedContainerManager.java   
@Override
protected synchronized IContainer createContainer(final String handle, final IResourceDescriptions resourceDescriptions) {
  final IResourceDescriptions descriptionsKey = resourceDescriptions instanceof CurrentDescriptions2.ResourceSetAware
      ? ((CurrentDescriptions2.ResourceSetAware) resourceDescriptions).getDelegate()
      : resourceDescriptions;

  Map<String, WeakReference<IContainer>> containersMap = descriptionsContainersCache.get(descriptionsKey);
  if (containersMap == null) {
    containersMap = new HashMap<String, WeakReference<IContainer>>();
    descriptionsContainersCache.put(descriptionsKey, containersMap);
  }

  WeakReference<IContainer> containerRef = containersMap.get(handle);
  IContainer container = containerRef != null ? containerRef.get() : null;
  if (container == null) {
    final IContainerState containerState = new ContainerState(handle, getStateProvider().get(descriptionsKey));
    container = new StateBasedContainerWithHandle(descriptionsKey, containerState, handle);
    new CacheInvalidator(descriptionsKey, handle, containerState);
    containerRef = new WeakReference<IContainer>(container);
    containersMap.put(handle, containerRef);
  }

  return container;
}
项目:PHDL    文件:PhdlJavaValidator.java   
@Check(CheckType.NORMAL)
public void checkDesignNameUnique(Design design) {
    List<Design> designs = new ArrayList<Design>();
    IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(design.eResource()
            .getURI());
    List<IContainer> visiblecontainers = containermanager.getVisibleContainers(resourceDescription,
            resourceDescriptions);
    for (IContainer container : visiblecontainers) {
        for (IEObjectDescription eobjectDescription : container.getExportedObjects()) {
            EObject eObjectOrProxy = eobjectDescription.getEObjectOrProxy();
            if (eObjectOrProxy instanceof Design)
                designs.add((Design) eObjectOrProxy);
        }
    }

    int count = 0;
    for (Design d : designs) {
        if (d.eIsProxy())
            d = (Design) EcoreUtil.resolve(d, design);
        if (design.getName().equals(d.getName()))
            count++;
    }
    if (count > 1)
        error("Duplicate design in project.", PhdlPackage.Literals.DESIGN__NAME);
}
项目:PHDL    文件:PhdlJavaValidator.java   
@Check(CheckType.NORMAL)
public void checkPackageNameUnique(Package pkg) {
    List<Package> packages = new ArrayList<Package>();
    IResourceDescription resourceDescription = resourceDescriptions
            .getResourceDescription(pkg.eResource().getURI());
    List<IContainer> visiblecontainers = containermanager.getVisibleContainers(resourceDescription,
            resourceDescriptions);
    for (IContainer container : visiblecontainers) {
        for (IEObjectDescription eobjectDescription : container.getExportedObjects()) {
            EObject eObjectOrProxy = eobjectDescription.getEObjectOrProxy();
            if (eObjectOrProxy instanceof Package)
                packages.add((Package) eObjectOrProxy);
        }
    }
    int count = 0;
    for (Package p : packages) {
        if (p.eIsProxy())
            p = (Package) EcoreUtil.resolve(p, pkg);
        if (pkg.getName().equals(p.getName()))
            count++;
    }
    if (count > 1)
        error("Duplicate package in project.", PhdlPackage.Literals.PACKAGE__NAME);
}
项目:PHDL    文件:PhdlProposalProvider.java   
@Override
public void complete_QualifiedNameWithWildCard(EObject model, RuleCall ruleCall, ContentAssistContext context,
        ICompletionProposalAcceptor acceptor) {
    IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(model.eResource()
            .getURI());
    List<IContainer> visiblecontainers = containermanager.getVisibleContainers(resourceDescription,
            resourceDescriptions);
    for (IContainer container : visiblecontainers) {
        for (IEObjectDescription eobjectDescription : container.getExportedObjects()) {
            EObject eObjectOrProxy = eobjectDescription.getEObjectOrProxy();
            if (eObjectOrProxy instanceof Device) {
                if (eobjectDescription.getQualifiedName().getSegmentCount() == 2) {
                    acceptor.accept(createCompletionProposal(eobjectDescription.getQualifiedName()
                            .getFirstSegment() + ".*", context));
                    acceptor.accept(createCompletionProposal(eobjectDescription.getQualifiedName().toString(),
                            context));
                }
            }
        }
    }
}
项目:packtpub-xtext-book-examples    文件:SmallJavaIndex.java   
public List<IContainer> getVisibleContainers(final EObject o) {
  List<IContainer> _xblockexpression = null;
  {
    Resource _eResource = o.eResource();
    final IResourceDescriptions index = this.rdp.getResourceDescriptions(_eResource);
    Resource _eResource_1 = o.eResource();
    URI _uRI = _eResource_1.getURI();
    final IResourceDescription rd = index.getResourceDescription(_uRI);
    List<IContainer> _xifexpression = null;
    boolean _notEquals = (!Objects.equal(rd, null));
    if (_notEquals) {
      _xifexpression = this.cm.getVisibleContainers(rd, index);
    } else {
      _xifexpression = CollectionLiterals.<IContainer>emptyList();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:n4js    文件:PolyfillAwareSelectableBasedScope.java   
/**
 * Creates this scope if container is present, otherwise parent is returned.
 */
public static IScope createPolyfillAwareScope(IScope parent, IContainer container,
        Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) {
    if (container == null || container.isEmpty())
        return parent;
    return new PolyfillAwareSelectableBasedScope(parent, container, filter, type, ignoreCase);
}
项目:n4js    文件:UserDataAwareScope.java   
UserDataAwareScope(IScope outer, ISelectable selectable, Predicate<IEObjectDescription> filter, EClass type,
        boolean ignoreCase, ResourceSet resourceSet, CanLoadFromDescriptionHelper canLoadFromDescriptionHelper,
        IContainer container) {
    super(outer, selectable, filter, type, ignoreCase);
    this.resourceSet = resourceSet;
    this.canLoadFromDescriptionHelper = canLoadFromDescriptionHelper;
    this.container = container;
    this.type = type;
}
项目:xtext-core    文件:StateBasedContainerManager.java   
protected IContainer createContainer(String handle, IResourceDescriptions resourceDescriptions) {
    IAllContainersState state = getState(resourceDescriptions);
    IContainerState containerState = new ContainerState(handle, state);
    StateBasedContainer result = new StateBasedContainer(resourceDescriptions, containerState);
    if (state instanceof FlatResourceSetBasedAllContainersState)
        result.setUriToDescriptionCacheEnabled(false);
    return result;
}
项目:xtext-core    文件:StateBasedContainerManager.java   
protected List<IContainer> getVisibleContainers(List<String> handles, IResourceDescriptions resourceDescriptions) {
    if (handles.isEmpty())
        return Collections.emptyList();
    List<IContainer> result = Lists.newArrayListWithExpectedSize(handles.size());
    for(String handle: handles) {
        IContainer container = createContainer(handle, resourceDescriptions);
        if (!container.isEmpty() || result.isEmpty())
            result.add(container);
    }
    return result;
}
项目:xtext-core    文件:SimpleResourceDescriptionsBasedContainerManager.java   
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
    if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
        return delegate.getVisibleContainers(desc, resourceDescriptions);
    }
    return Collections.singletonList(getContainer(desc, resourceDescriptions));
}
项目:xtext-core    文件:DefaultGlobalScopeProvider.java   
protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
    IScope result = parent;
    if (context == null || context.getResourceSet() == null)
        return result;
    List<IContainer> containers = Lists.newArrayList(getVisibleContainers(context));
    Collections.reverse(containers);
    Iterator<IContainer> iter = containers.iterator();
    while (iter.hasNext()) {
        IContainer container = iter.next();
        result = createContainerScopeWithContext(context, result, container, filter, type, ignoreCase);
    }
    return result;
}
项目:xtext-core    文件:ProjectDescriptionBasedContainerManager.java   
@Override
public IContainer getContainer(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
  final ChunkedResourceDescriptions chunkedResourceDescriptions = this.getChunkedResourceDescriptions(resourceDescriptions);
  if ((chunkedResourceDescriptions == null)) {
    String _name = ChunkedResourceDescriptions.class.getName();
    String _plus = ("expected " + _name);
    throw new IllegalArgumentException(_plus);
  }
  final ResourceSet resourceSet = chunkedResourceDescriptions.getResourceSet();
  final ProjectDescription projectDescription = ProjectDescription.findInEmfObject(resourceSet);
  final IContainer container = this.createContainer(resourceDescriptions, chunkedResourceDescriptions, projectDescription.getName());
  return container;
}
项目:xtext-core    文件:AbstractLiveContainerTest.java   
@Test
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
public void testNonNormalizedURIs() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
    parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
    IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
    IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
    List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
    List<IEObjectDescription> objects = Lists.newArrayList();
    EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
    for (IContainer container : containers)
        Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
    assertEquals(2, objects.size());
}
项目:xtext-core    文件:ServerModule.java   
@Override
protected void configure() {
  this.binder().<ExecutorService>bind(ExecutorService.class).toProvider(ExecutorServiceProvider.class);
  this.<LanguageServer>bind(LanguageServer.class).to(LanguageServerImpl.class);
  this.<IResourceServiceProvider.Registry>bind(IResourceServiceProvider.Registry.class).toProvider(ResourceServiceProviderServiceLoader.class);
  this.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class).to(ProjectWorkspaceConfigFactory.class);
  this.<IProjectDescriptionFactory>bind(IProjectDescriptionFactory.class).to(DefaultProjectDescriptionFactory.class);
  this.<IContainer.Manager>bind(IContainer.Manager.class).to(ProjectDescriptionBasedContainerManager.class);
}
项目:dsl-devkit    文件:CachingStateBasedContainerManager.java   
@Override
public List<IContainer> getVisibleContainers(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
  String root = internalGetContainerHandle(desc, resourceDescriptions);
  if (root == null) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Cannot find IContainer for: " + desc.getURI()); //$NON-NLS-1$
    }
    return Collections.emptyList();
  }
  List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
  return getContainersForHandlesAndResource(handles, desc, resourceDescriptions);
}
项目:dsl-devkit    文件:CachingStateBasedContainerManager.java   
/**
 * Returns the containers for the given handles, where one of the containers will also include {@code desc} when appropriate.
 * 
 * @param handles
 *          handles to get containers for, must not be {@code null}
 * @param desc
 *          description to add, must not be {@code null}
 * @param resourceDescriptions
 *          resource descriptions, must not be {@code null}
 * @return list of containers, never {@code null}
 */
protected List<IContainer> getContainersForHandlesAndResource(final List<String> handles, final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
  List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
  if (!result.isEmpty()) {
    URI descURI = desc.getURI();
    for (int i = 0; i < result.size(); i++) {
      if (result.get(i).getResourceDescription(descURI) != null) {
        return result;
      }
    }
    // Do *not* add the context resource description itself if we're in the first phase of a build: 'desc' itself
    // may not be in any consistent state, and adding it to the containers may result in recursive invocations of
    // getEObjectDescriptions(), leading to a stack overflow since it may in turn invoke getVisibleContainers() again.
    if (desc instanceof DefaultResourceDescription) {
      DefaultResourceDescription d = (DefaultResourceDescription) desc;
      if (BuildPhases.isIndexing(d.getResource())) {
        return result;
      }
    }
    // the IResourceDescription was found nowhere, add it to the first one that matches the description's domain.
    IDomain descDomain = mapper.map(descURI);
    IContainer wrappedContainer = null;
    int index = 0;
    for (int i = 0; i < result.size(); i++) {
      IContainer container = result.get(i);
      IDomain containerDomain = mapper.map(container);
      if (containerDomain != null && containerDomain.equals(descDomain)) {
        wrappedContainer = new DescriptionAddingContainer(desc, container);
        result.set(index, wrappedContainer);
        return result;
      }
      index++;
    }
    // If we get here, we found no container with a matching domain. Add to the first, but use a DescriptionAddingContainer that
    // will add the description at the end.
    wrappedContainer = new DescriptionAtEndAddingContainer(desc, result.get(0));
    result.set(0, wrappedContainer);
  }
  return result;
}
项目:dsl-devkit    文件:ExtensionPointAwareScopeProvider.java   
@Override
protected IScope createContainerScopeWithContext(final Resource eResource, final IScope parent, final IContainer container, final Predicate<IEObjectDescription> filter, final EClass type, final boolean ignoreCase) {
  IContainer theContainer = container;
  if (eResource != null) {
    URI uriToFilter = eResource.getURI();
    if (container.hasResourceDescription(uriToFilter)) {
      theContainer = new MyFilterUriContainer(uriToFilter, container);
    }
  }
  return createContainerScope(parent, theContainer, filter, type, ignoreCase);
}
项目:dsl-devkit    文件:BuilderIntegrationFragment.java   
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  final Set<Binding> bindings = super.getGuiceBindingsRt(grammar);
  final BindFactory factory = new BindFactory();
  factory.addTypeToType(IContainer.Manager.class.getName(), "com.avaloq.tools.ddk.xtext.builder.CachingStateBasedContainerManager");
  factory.addTypeToType(LazyLinkingResource.class.getName(), LazyLinkingResource2.class.getName());
  factory.addTypeToType(LazyURIEncoder.class.getName(), FastLazyURIEncoder.class.getName());
  final Set<Binding> result = factory.getBindings();
  result.addAll(bindings);
  return result;
}
项目:dsl-devkit    文件:AbstractCachingResourceDescriptionManager.java   
/** {@inheritDoc} */
@Override
public boolean isAffected(final Collection<Delta> deltas, final IResourceDescription candidate, final IResourceDescriptions context) { // NOPMD(NPathComplexity)
  final Collection<Delta> filteredDeltas = getInterestingDeltas(deltas);
  if (filteredDeltas.isEmpty()) {
    return false;
  }

  final List<IContainer> containers = getContainerManager().getVisibleContainers(candidate, context);
  for (final Delta delta : filteredDeltas) {
    final URI deltaURI = delta.getUri();// NOPMD - potentially could be lost due to call on getNew() after
    // deleted resources are no longer visible resources so we test them, too.
    if (delta.getNew() == null && isReferencedBy(delta, candidate, context)) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri()); //$NON-NLS-1$
      }
      return true;
    }
    for (IContainer container : containers) {
      if (container.getResourceDescription(deltaURI) != null) {
        if (isReferencedBy(delta, candidate, context)) {
          if (LOGGER.isDebugEnabled()) { // NOPMD AvoidDeeplyNestedIfStmts
            LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri()); //$NON-NLS-1$
          }
          return true;
        }
        break;
      }
    }
  }
  return false;
}
项目:dsl-devkit    文件:AbstractPolymorphicScopeProvider.java   
/**
 * Return the visible containers given a context object.
 *
 * @param context
 *          The context object
 * @param originalResource
 *          the original resource
 * @return The list of visible containers.
 */
protected List<IContainer> getVisibleContainers(final EObject context, final Resource originalResource) { // NOPMD by WTH on 26.01.11 09:26 (NPath
                                                                                                          // complexity...)
  final Resource ctxRsc = originalResource == null ? context.eResource() : originalResource;
  if (!(ctxRsc instanceof XtextResource)) {
    LOGGER.error(MessageFormat.format("Context {0} is not in an Xtext resource: {1}", context, ctxRsc != null ? ctxRsc.getURI() : "null")); //$NON-NLS-1$ //$NON-NLS-2$
    throw new IllegalStateException();
  }
  final XtextResource rsc = (XtextResource) ctxRsc;
  // Cache these container lists, they're expensive to create
  final String key = "CONTAINERCACHE&" + rsc.getURI().toString(); //$NON-NLS-1$
  List<IContainer> result = null;
  final ResourceCache<String, List<IContainer>> cache = CacheManager.getInstance().getOrCreateResourceCache("AbstractPolymorphicScopeProvider#cache", rsc); //$NON-NLS-1$
  if (cache != null) {
    result = cache.get(key);
    if (result != null) {
      return result;
    }
  }

  final EObject ctx = ctxRsc != context.eResource() ? ctxRsc.getContents().get(0) : context;
  // We need to get the container manager dynamically, otherwise we may end up using the wrong ResourceDescriptions if
  // the context object in actually from another resource.
  final IResourceServiceProvider resourceServiceProvider = rsc.getResourceServiceProvider();
  final IResourceDescription.Manager descriptionManager = resourceServiceProvider.getResourceDescriptionManager();
  final IContainer.Manager containerManager = resourceServiceProvider.getContainerManager();

  final IResourceDescription description = descriptionManager.getResourceDescription(ctx.eResource());
  final IResourceDescriptions resourceDescriptions = getResourceDescriptions(ctx.eResource());
  result = containerManager.getVisibleContainers(description, resourceDescriptions);
  if (cache != null) {
    cache.set(key, result);
  }
  return result;
}
项目:dsl-devkit    文件:ContainerQuery.java   
/**
 * Execute the query on a list of containers, in the order given.
 *
 * @param containers
 *          The containers.
 * @return The query result.
 */
public Iterable<IEObjectDescription> execute(final Iterable<IContainer> containers) {
  if (Iterables.size(containers) == 1) {
    return execute(containers.iterator().next());
  }

  return Iterables.concat(Iterables.transform(containers, new Function<IContainer, Iterable<IEObjectDescription>>() {
    @Override
    public Iterable<IEObjectDescription> apply(final IContainer container) {
      return execute(container);
    }
  }));
}
项目:sadlos2    文件:SadlGlobalScopeProvider.java   
private Iterable<IResourceDescription> getVisibleResourceDescriptions (Resource resource) {
    IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
    IResourceDescriptions resourceDescriptions = getResourceDescriptions(resource);
    List<IContainer> visibleContainers = containerManager.getVisibleContainers(description, resourceDescriptions);
    Set<IResourceDescription> visibleResourceDescriptions = new HashSet<>();
    for (IContainer container: visibleContainers) {
        for (IResourceDescription rd: container.getResourceDescriptions()) {
            visibleResourceDescriptions.add(rd);
        }
    }
    return visibleResourceDescriptions;
}
项目:packtpub-xtext-book-examples    文件:SmallJavaIndex.java   
public Iterable<IEObjectDescription> getVisibleEObjectDescriptions(final EObject o) {
  List<IContainer> _visibleContainers = this.getVisibleContainers(o);
  final Function1<IContainer, Iterable<IEObjectDescription>> _function = new Function1<IContainer, Iterable<IEObjectDescription>>() {
    @Override
    public Iterable<IEObjectDescription> apply(final IContainer container) {
      return container.getExportedObjects();
    }
  };
  List<Iterable<IEObjectDescription>> _map = ListExtensions.<IContainer, Iterable<IEObjectDescription>>map(_visibleContainers, _function);
  return Iterables.<IEObjectDescription>concat(_map);
}
项目:packtpub-xtext-book-examples    文件:SmallJavaIndex.java   
public Iterable<IEObjectDescription> getVisibleEObjectDescriptions(final EObject o, final EClass type) {
  List<IContainer> _visibleContainers = this.getVisibleContainers(o);
  final Function1<IContainer, Iterable<IEObjectDescription>> _function = new Function1<IContainer, Iterable<IEObjectDescription>>() {
    @Override
    public Iterable<IEObjectDescription> apply(final IContainer container) {
      return container.getExportedObjectsByType(type);
    }
  };
  List<Iterable<IEObjectDescription>> _map = ListExtensions.<IContainer, Iterable<IEObjectDescription>>map(_visibleContainers, _function);
  return Iterables.<IEObjectDescription>concat(_map);
}
项目:pokemon-tcgo-deck-generator    文件:AbstractPkmntcgoRuntimeModule.java   
public Class<? extends IContainer.Manager> bindIContainer$Manager() {
    return StateBasedContainerManager.class;
}
项目:n4js    文件:DefaultN4GlobalScopeProvider.java   
@Override
protected IScope createContainerScope(IScope parent, IContainer container, Predicate<IEObjectDescription> filter,
        EClass type, boolean ignoreCase) {
    return PolyfillAwareSelectableBasedScope.createPolyfillAwareScope(parent, container, filter, type, ignoreCase);
}
项目:n4js    文件:AbstractRegularExpressionRuntimeModule.java   
public Class<? extends IContainer.Manager> bindIContainer$Manager() {
    return StateBasedContainerManager.class;
}
项目:n4js    文件:AbstractN4JSRuntimeModule.java   
public Class<? extends IContainer.Manager> bindIContainer$Manager() {
    return StateBasedContainerManager.class;
}
项目:n4js    文件:N4JSGlobalScopeProvider.java   
@Override
protected IScope createContainerScope(IScope parent, IContainer container, Predicate<IEObjectDescription> filter,
        EClass type, boolean ignoreCase) {
    throw new UnsupportedOperationException();
}