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

项目:n4js    文件:BuilderUtil.java   
/***/
public static Set<IReferenceDescription> getIncomingReferences(URI uri) {
    Set<IReferenceDescription> desc = Sets.newHashSet();
    Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
    for (IResourceDescription res : descriptions) {
        Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
        for (IReferenceDescription ref : descriptions2) {
            if (uri.hasFragment()) {
                if (ref.getTargetEObjectUri().equals(uri))
                    desc.add(ref);
            } else {
                if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment()))
                    desc.add(ref);
            }
        }
    }
    return desc;
}
项目:n4js    文件:BuilderUtil.java   
/***/
public static Set<IReferenceDescription> getContainedReferences(URI uri) {
    Set<IReferenceDescription> desc = Sets.newHashSet();
    Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
    for (IResourceDescription res : descriptions) {
        Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
        for (IReferenceDescription ref : descriptions2) {
            if (uri.hasFragment()) {
                if (ref.getSourceEObjectUri().equals(uri))
                    desc.add(ref);
            } else {
                if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment()))
                    desc.add(ref);
            }
        }
    }
    return desc;
}
项目:n4js    文件:N4HeadlessCompiler.java   
/**
 * Install the given resource's description into the given index. Raw JavaScript files will not be indexed. Note
 * that when this method is called for the given resource, it is not yet fully processed and therefore the
 * serialized type model is not added to the index.
 * <p>
 * This is due to the fact that we keep a common resource set for all projects that contains the resources of all
 * projects with unprocessed dependencies, unlike in the IDE case where we have one resource set per open document
 * and load the type models from the index.
 * </p>
 * <p>
 * Since the type models are available in the resource set as long as they may still be referenced, they need not be
 * serialized and stored into the index.
 * </p>
 *
 * @param resource
 *            the resource to be indexed
 * @param index
 *            the index to add the given resource to
 */
private void indexResource(Resource resource, ResourceDescriptionsData index) {
    if (!shouldIndexResource(resource))
        return;

    final URI uri = resource.getURI();
    IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE
            .getResourceServiceProvider(uri);
    if (serviceProvider != null) {
        if (logger.isCreateDebugOutput()) {
            logger.debug("  Indexing resource " + uri);
        }

        IResourceDescription.Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager();
        IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);

        if (resourceDescription != null) {
            index.addDescription(uri, resourceDescription);
        }
    }
}
项目:n4js    文件:N4JSDirtyStateEditorSupport.java   
private boolean isSignificantChange(IResourceDescription.Delta delta) {
    if (delta.haveEObjectDescriptionsChanged()) {
        IResourceDescription newDescription = delta.getNew();
        IResourceDescription oldDescription = delta.getOld();
        if ((newDescription != null) != (oldDescription != null)) {
            return true;
        }
        if (newDescription == null || oldDescription == null) {
            throw new IllegalStateException();
        }
        List<IEObjectDescription> newDescriptions = Lists.newArrayList(newDescription.getExportedObjects());
        List<IEObjectDescription> oldDescriptions = Lists.newArrayList(oldDescription.getExportedObjects());
        if (newDescriptions.size() != oldDescriptions.size()) {
            return true;
        }
        URI resourceURI = delta.getUri();
        for (int i = 0; i < newDescriptions.size(); i++) {
            if (!equalDescriptions(newDescriptions.get(i), oldDescriptions.get(i), resourceURI)) {
                return true;
            }
        }
    }
    return false;
}
项目:n4js    文件:PrevStateAwareDirtyStateManager.java   
private IResourceDescription extractOldDescription(final IDirtyResource dirtyResource) {
    IDirtyResource myDirtyResource = reflectiveGetInnerResource(dirtyResource);
    if (myDirtyResource instanceof PrevStateAwareDocumentBasedDirtyResource) {
        return ((PrevStateAwareDocumentBasedDirtyResource) myDirtyResource).getPrevDescription();
    }
    return null;
}
项目:n4js    文件:N4JSResourceDescriptionManager.java   
/**
 * {@inheritDoc}
 *
 * This marks {@code n4js} as affected if the manifest of the project changes. In turn, they will be revalidated and
 * taken into consideration for the code generation step.
 */
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
        IResourceDescriptions context) {
    boolean result = basicIsAffected(deltas, candidate);
    if (!result) {
        for (IResourceDescription.Delta delta : deltas) {
            URI uri = delta.getUri();
            if (IN4JSProject.N4MF_MANIFEST.equalsIgnoreCase(uri.lastSegment())) {
                URI prefixURI = uri.trimSegments(1).appendSegment("");
                if (candidate.getURI().replacePrefix(prefixURI, prefixURI) != null) {
                    return true;
                }
            }
        }
    }
    return result;
}
项目:n4js    文件:OrderedResourceDescriptionsData.java   
@SuppressWarnings("unchecked")
@Override
protected void registerDescription(final IResourceDescription description,
        final Map<QualifiedName, Object> target) {

    for (final IEObjectDescription object : description.getExportedObjects()) {
        final QualifiedName lowerCase = object.getName().toLowerCase();
        final Object existing = target.put(lowerCase, description);
        if (existing != null && existing != description) {
            Set<IResourceDescription> set = null;
            if (existing instanceof IResourceDescription) {
                // The linked hash set is the difference comparing to the super class.
                set = Sets.newLinkedHashSetWithExpectedSize(2);
                set.add((IResourceDescription) existing);
            } else {
                set = (Set<IResourceDescription>) existing;
            }
            set.add(description);
            target.put(lowerCase, set);
        }
    }
}
项目:solidity-ide    文件:SolidityBuilderParticipant.java   
@Override
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor);
    if (!prefs.isCompilerEnabled()) {
        return;
    }
    final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context);
    if (deltas.isEmpty()) {
        return;
    }
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    progress.beginTask("Compiling solidity...", deltas.size());

    List<URI> uris = deltas.stream().map(delta -> delta.getUri()).collect(Collectors.toList());
    compiler.compile(uris, progress);
    context.getBuiltProject().refreshLocal(IProject.DEPTH_INFINITE, progress);
    progress.done();

}
项目:xtext-extras    文件:ResourceDescriptionProviderTest.java   
@Test
public void testStubGeneration_02() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public interface MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("public String helloWorld();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue(((JvmGenericType) _eObjectOrProxy).isInterface());
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
项目:xtext-extras    文件:ResourceDescriptionProviderTest.java   
@Test
public void testStubGeneration_04() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("public @interface MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("String value();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    EObject _eObjectOrProxy = IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getEObjectOrProxy();
    Assert.assertTrue((_eObjectOrProxy instanceof JvmAnnotationType));
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
项目:xtext-extras    文件:ResourceDescriptionProviderTest.java   
@Test
public void testStubGeneration_05() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package my.pack;");
  _builder.newLine();
  _builder.newLine();
  _builder.append("public abstract class MyTest {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("abstract String value();");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final Procedure1<IResourceDescription> _function = (IResourceDescription it) -> {
    Assert.assertEquals("my.pack.MyTest", IterableExtensions.<IEObjectDescription>head(it.getExportedObjects()).getQualifiedName().toString());
    Assert.assertEquals(1, IterableExtensions.size(it.getExportedObjects()));
  };
  this.resultsIn(_builder, _function);
}
项目:xtext-core    文件:WorkspaceSymbolService.java   
public List<? extends SymbolInformation> getSymbols(final String query, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
  final LinkedList<SymbolInformation> result = CollectionLiterals.<SymbolInformation>newLinkedList();
  Iterable<IResourceDescription> _allResourceDescriptions = indexData.getAllResourceDescriptions();
  for (final IResourceDescription resourceDescription : _allResourceDescriptions) {
    {
      this.operationCanceledManager.checkCanceled(cancelIndicator);
      final IResourceServiceProvider resourceServiceProvider = this._registry.getResourceServiceProvider(resourceDescription.getURI());
      DocumentSymbolService _get = null;
      if (resourceServiceProvider!=null) {
        _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
      }
      final DocumentSymbolService documentSymbolService = _get;
      if ((documentSymbolService != null)) {
        List<? extends SymbolInformation> _symbols = documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator);
        Iterables.<SymbolInformation>addAll(result, _symbols);
      }
    }
  }
  return result;
}
项目:xtext-extras    文件:XbaseResourceDescriptionStrategyTest.java   
@Test
public void testNoReferenceDescriptionsForPackageFragments() {
  try {
    final XExpression expression = this.expression("java::lang::String::valueOf(\"\")");
    final Resource resource = expression.eResource();
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(resource);
    final Function1<IReferenceDescription, String> _function = (IReferenceDescription it) -> {
      return it.getTargetEObjectUri().toString();
    };
    final Set<String> referenceDescriptions = IterableExtensions.<String>toSet(IterableExtensions.<IReferenceDescription, String>map(description.getReferenceDescriptions(), _function));
    Assert.assertEquals(2, referenceDescriptions.size());
    final Set<String> expectation = Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("java:/Objects/java.lang.String#java.lang.String", "java:/Objects/java.lang.String#java.lang.String.valueOf(java.lang.Object)"));
    Assert.assertEquals(expectation, referenceDescriptions);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:EObjectDescriptionBasedStubGenerator.java   
public String getJavaStubSource(IEObjectDescription description, IResourceDescription resourceDescription) {
    if(isNestedType(description) || !isJvmDeclaredType(description)) {
        return null;
    }
    Multimap<QualifiedName, IEObjectDescription> owner2nested = LinkedHashMultimap.create();
    for(IEObjectDescription other: resourceDescription.getExportedObjects()) {
        if(isJvmDeclaredType(other) && isNestedType(other))
            owner2nested.put(getOwnerClassName(other.getQualifiedName()), other);
    }
    StringBuilder classSignatureBuilder = new StringBuilder();
    QualifiedName qualifiedName = description.getQualifiedName();
    if (qualifiedName.getSegments().size() > 1) {
        String string = qualifiedName.toString();
        classSignatureBuilder.append("package " + string.substring(0, string.lastIndexOf('.')) + ";");
    }
    appendType(description, owner2nested, classSignatureBuilder);
    return classSignatureBuilder.toString();
}
项目: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-extras    文件:EcoreResourceDescriptionManagerTest.java   
@Test public void testPerformance() throws Exception {
        GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
        Collection<String> uris = ImmutableList.copyOf(EPackage.Registry.INSTANCE.keySet());
        for(String uri: uris) {
            EPackage pack = EPackage.Registry.INSTANCE.getEPackage(uri);
            IResourceDescription description = manager.getResourceDescription(pack.eResource());
            assertNotNull(description);
            for(int i = 0; i < 10; i++) {
                Iterator<EObject> iter = EcoreUtil.getAllProperContents(pack, true);
                while(iter.hasNext()) {
                    EObject next = iter.next();
                    if (next instanceof ENamedElement) {
                        String name = ((ENamedElement) next).getName();
//                      Iterable<IEObjectDescription> objects = 
                        description.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(name), false);
//                      assertFalse(name + " - " + uri + " - " + next, Iterables.isEmpty(objects));
                    }
                }
            }
        }
    }
项目: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;
}
项目:dsl-devkit    文件:AbstractUtilTest.java   
/**
 * Prepare mocks for all tests.
 */
public static void prepareMocksBase() {
  oldDesc = mock(IResourceDescription.class);
  newDesc = mock(IResourceDescription.class);
  delta = mock(Delta.class);
  resource = mock(Resource.class);
  uriCorrect = mock(URI.class);
  when(uriCorrect.isPlatformResource()).thenReturn(true);
  when(uriCorrect.isFile()).thenReturn(true);
  when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
  when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
  when(delta.getNew()).thenReturn(newDesc);
  when(delta.getOld()).thenReturn(oldDesc);
  when(delta.getUri()).thenReturn(uriCorrect);
  when(resource.getURI()).thenReturn(uriCorrect);
  file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
  Iterable<Pair<IStorage, IProject>> storages = singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
  mapperCorrect = mock(Storage2UriMapperImpl.class);
  when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}
项目:xtext-core    文件:ResourceDescriptionsData.java   
@Override
public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName qualifiedName, final boolean ignoreCase) {
    Object existing = lookupMap.get(qualifiedName.toLowerCase());
    if (existing instanceof IResourceDescription) {
        return ((IResourceDescription) existing).getExportedObjects(type, qualifiedName, ignoreCase);
    } else if (existing instanceof Set<?>) {
        @SuppressWarnings("unchecked")
        Set<IResourceDescription> casted = (Set<IResourceDescription>) existing;
        return Iterables.concat(Iterables.transform(casted, new Function<IResourceDescription, Iterable<IEObjectDescription>>() {
            @Override
            public Iterable<IEObjectDescription> apply(IResourceDescription from) {
                if (from != null) {
                    return from.getExportedObjects(type, qualifiedName, ignoreCase);
                }
                return Collections.emptyList();
            }
        }));
    }
    return Collections.emptyList();
}
项目:dsl-devkit    文件:ResourceDescriptionDeltaTest.java   
@Test
public void testOldReconstruction() {
  IResourceDescription oldRes = createDescription("a");
  IResourceDescription newRes = createDescription("a", "b");

  ResourceDescriptionDelta delta = new ResourceDescriptionDelta(oldRes, createDescription("a"), null);
  assertFalse(delta.haveEObjectDescriptionsChanged());
  assertSame(delta.getNew(), delta.getOld());

  delta = new ResourceDescriptionDelta(oldRes, createDescription("a"), null);
  assertDeltaEquals(0, 0, 0, delta);
  assertSame(delta.getNew(), delta.getOld());

  delta = new ResourceDescriptionDelta(oldRes, newRes, null);
  assertTrue(delta.haveEObjectDescriptionsChanged());
  assertDeltaEquals(1, 0, 0, delta);
  assertDeltaEquals(0, 0, 0, new ResourceDescriptionDelta(oldRes, delta.getOld(), null));

  delta = new ResourceDescriptionDelta(newRes, oldRes, null);
  assertTrue(delta.haveEObjectDescriptionsChanged());
  assertDeltaEquals(0, 0, 1, delta);
  assertDeltaEquals(0, 0, 0, new ResourceDescriptionDelta(newRes, delta.getOld(), null));
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptions.java   
@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);
}
项目:dsl-devkit    文件:ResourceDescriptionDelta.java   
/**
 * Create a new delta from an old and a new resource description.
 * 
 * @param oldDesc
 *          The old description
 * @param newDesc
 *          The new description
 * @param index
 *          index
 */
public ResourceDescriptionDelta(final IResourceDescription oldDesc, final IResourceDescription newDesc, final IResourceDescriptions index) {
  super();
  if (oldDesc == newDesc) {
    throw new AssertionError("'old != new' constraint violated"); //$NON-NLS-1$
  }
  if (newDesc != null && oldDesc != null && !oldDesc.getURI().equals(newDesc.getURI())) {
    URI oldURI = oldDesc.getURI();
    URI newURI = newDesc.getURI();
    throw new AssertionError("'new != null && old != null && !old.getURI().equals(new.getURI())' constraint violated, old was " + oldURI + " new was: " //$NON-NLS-1$ //$NON-NLS-2$
        + newURI);
  }

  this.uri = oldDesc == null ? newDesc.getURI() : oldDesc.getURI();
  this.oldDesc = oldDesc;
  if (newDesc != null) {
    this.newDesc = new SoftReference<IResourceDescription>(newDesc);
  }
  this.index = index;
}
项目:xtext-core    文件:ReferenceFinder.java   
@Override
public void findReferences(final TargetURIs targetURIs, IResourceDescription resourceDescription,
        IResourceAccess resourceAccess, final Acceptor acceptor, final IProgressMonitor monitor) {
    final URI resourceURI = resourceDescription.getURI();
    if (resourceAccess != null && targetURIs.containsResource(resourceURI)) {
        IUnitOfWork.Void<ResourceSet> finder = new IUnitOfWork.Void<ResourceSet>() {
            @Override
            public void process(final ResourceSet state) throws Exception {
                Resource resource = state.getResource(resourceURI, true);
                findReferences(targetURIs, resource, acceptor, monitor);
            }
        };
        resourceAccess.readOnly(resourceURI, finder);
    } else {
        findReferencesInDescription(targetURIs, resourceDescription, resourceAccess, acceptor, monitor);
    }
}
项目:dsl-devkit    文件:FixedCopiedResourceDescription.java   
public FixedCopiedResourceDescription(final IResourceDescription original) {
  super();
  this.uri = original.getURI();
  this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedObjects(), new Function<IEObjectDescription, IEObjectDescription>() {
    @Override
    @SuppressWarnings("unchecked")
    public IEObjectDescription apply(final IEObjectDescription from) {
      if (from.getEObjectOrProxy().eIsProxy()) {
        return from;
      } else if (from instanceof IDetachableDescription) {
        return ((IDetachableDescription<IEObjectDescription>) from).detach();
      }
      InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
      result.eSetProxyURI(from.getEObjectURI());
      ImmutableMap.Builder<String, String> userData = ImmutableMap.builder();
      for (final String key : from.getUserDataKeys()) {
        userData.put(key, from.getUserData(key));
      }
      return EObjectDescription.create(from.getName(), result, userData.build());
    }
  }));
}
项目: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;
}
项目:n4js    文件:AbstractBuilderTest.java   
private void assertXtextIndexIsValidInternal() {
    final IResourceDescriptions index = getXtextIndex();
    final StringBuilder sb = new StringBuilder();
    for (IResourceDescription desc : index.getAllResourceDescriptions()) {
        if (desc instanceof ResourceDescriptionWithoutModuleUserData) {
            sb.append("\n");
            sb.append(IResourceDescription.class.getSimpleName());
            sb.append(" in index must not be an instance of ");
            sb.append(ResourceDescriptionWithoutModuleUserData.class.getSimpleName());
            sb.append(" but it was. URI: ");
            sb.append(desc.getURI());
        }
    }
    assertTrue(sb.toString(), 0 == sb.length());
}
项目:n4js    文件:TestEventListener.java   
@Override
public void descriptionsChanged(Event event) {
    URI expectedURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
    for (IResourceDescription.Delta delta : event.getDeltas()) {
        URI deltaURI = delta.getUri();
        if (expectedURI.equals(deltaURI)) {
            eventFired = true;
        }
    }
}
项目:n4js    文件:BuilderUtil.java   
/***/
public static String toString(IResourceDescriptions index) {
    StringBuffer buff = new StringBuffer();
    for (IResourceDescription desc : index.getAllResourceDescriptions()) {
        buff.append(EmfFormatter.objToStr(desc, new EStructuralFeature[0]));
    }
    return buff.toString();
}
项目:n4js    文件:BuilderUtil.java   
/***/
public static boolean indexContainsElement(final String fileUri, final String eObjectName) {
    IResourceDescriptions descriptions = getBuilderState();
    URI uri = URI.createURI("platform:/resource" + fileUri);
    IResourceDescription description = descriptions.getResourceDescription(uri);
    if (description != null) {
        return description
                .getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(eObjectName), false)
                .iterator().hasNext();
    }
    return false;
}
项目:n4js    文件:EagerResourceSetBasedResourceDescriptions.java   
private Map<URI, IResourceDescription> getDescriptionsMap() {
    Descriptions descriptions = getDescriptions(getResourceSet());
    if (descriptions == null) {
        descriptions = new Descriptions();
        getResourceSet().eAdapters().add(descriptions);
        List<Resource> list = new ArrayList<>(getResourceSet().getResources());
        for (Resource resource : list) {
            IResourceDescription description = computeResourceDescription(resource.getURI());
            if (description != null) {
                descriptions.map.put(resource.getURI(), description);
            }
        }
    }
    return descriptions.map;
}
项目:n4js    文件:EagerResourceSetBasedResourceDescriptions.java   
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;
    IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
    if (manager == null)
        return null;
    return manager.getResourceDescription(resource);
}
项目:n4js    文件:ExternalPackagesPluginTest.java   
/**
 * Checks if expected list of stringified file locations matches
 *
 * @param expected
 *            collection of entries
 * @param actual
 *            collection of entries
 */
public void assertResourceDescriptions(Collection<String> expected, Iterable<IResourceDescription> actual) {
    Set<String> extraDescriptions = new HashSet<>();
    Set<String> missingDescriptions = new HashSet<>(expected);

    for (IResourceDescription iResourceDescription : actual) {
        URI uri = iResourceDescription.getURI();
        String stringUri = uri.isPlatform() ? uri.toPlatformString(false) : uri.toFileString();
        if (!missingDescriptions.contains(stringUri)) {
            extraDescriptions.add(stringUri);
        } else {
            missingDescriptions.remove(stringUri);
        }
    }

    if (missingDescriptions.isEmpty() && extraDescriptions.isEmpty()) {
        return;
    }

    StringBuilder msg = new StringBuilder("unexpected actual resources" + "\n");

    if (!extraDescriptions.isEmpty()) {
        msg.append("actual contains " + extraDescriptions.size() + " extra resources" + "\n");
    }

    if (!missingDescriptions.isEmpty()) {
        msg.append("actual is missing  " + missingDescriptions.size() + " expected resources" + "\n");
    }

    for (String extra : extraDescriptions) {
        msg.append("[extra] " + extra + "\n");
    }
    for (String missing : missingDescriptions) {
        msg.append("[missing] " + missing + "\n");
    }
    fail(msg.toString());
}
项目:n4js    文件:TestDiscoveryHelper.java   
private Map<URI, TModule> loadModules(final Iterable<URI> moduleUris, final IResourceDescriptions index,
        final ResourceSet resSet) {

    final Map<URI, TModule> uri2Modules = newHashMap();
    for (final URI moduleUri : moduleUris) {
        final IResourceDescription resDesc = index.getResourceDescription(moduleUri);
        uri2Modules.put(moduleUri, n4jsCore.loadModuleFromIndex(resSet, resDesc, false));
    }
    return uri2Modules;
}
项目:n4js    文件:TestDiscoveryHelper.java   
private boolean isTestModule(final ResourceSet resourceSet, final IResourceDescription module) {
    if (null == module) {
        return false;
    }
    final Iterable<IEObjectDescription> classes = module.getExportedObjectsByType(T_CLASS);
    return stream(classes).anyMatch(desc -> hasTestMethods(resourceSet, desc));
}
项目:n4js    文件:XpectN4JSES5TranspilerHelper.java   
/**
 * @return the resources retrieved from the Xpect resource set configuration
 */
@Override
public List<Resource> getResources() {
    final List<Resource> configuredResources = newArrayList();
    if (configuredWorkspace != null && fileSetupCtx != null) {
        for (IResourceDescription res : index.getAllResourceDescriptions()) {
            if (fileExtensionProvider.isValid(res.getURI().fileExtension())) {
                configuredResources.add(resourceSet.getResource(res.getURI(), true));
            }
        }
    }
    return configuredResources;
}
项目:n4js    文件:OpenTypeSelectionDialog.java   
@Override
public String getText(final Object element) {
    if (element instanceof IEObjectDescription) {
        final IEObjectDescription description = (IEObjectDescription) element;
        final StringBuilder sb = new StringBuilder(getFqn(description));
        if (description instanceof EObject && null != ((EObject) description).eContainer()) {
            final EObject container = ((EObject) description).eContainer();
            if (container instanceof IResourceDescription) {
                final URI uri = ((IResourceDescription) container).getURI();
                final IN4JSEclipseProject project = core.findProject(uri).orNull();
                if (null != project && project.exists()) {
                    sb.append(" [");
                    sb.append(project.getProjectId());
                    sb.append("]");
                    if (project.isExternal()) {
                        final IProject resourceProject = project.getProject();
                        sb.append(" External library: ");
                        sb.append(resourceProject.getLocation().toFile().getAbsolutePath());
                    }
                }
            }
        }
        return sb.toString();
    } else {
        return "";
    }
}
项目:n4js    文件:N4JSToBeBuiltComputer.java   
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
    if (IN4JSArchive.NFAR_FILE_EXTENSION.equals(storage.getFullPath().getFileExtension())
            && storage instanceof IFile) {
        IProject project = ((IFile) storage).getProject();
        String key = project.getName() + "|" + storage.getFullPath().toPortableString();
        Set<URI> cachedURIs = knownEntries.remove(key);
        if (cachedURIs != null) {
            toBeBuilt.getToBeDeleted().addAll(cachedURIs);
        } else {
            // cache not populated, use the index to find the URIs that shall be removed, e.g.
            // can happen after a restart of Eclipse
            Iterable<IResourceDescription> descriptions = builderState.getAllResourceDescriptions();
            String expectedAuthority = "platform:/resource" + storage.getFullPath() + "!";
            Set<URI> toBeDeleted = toBeBuilt.getToBeDeleted();
            for (IResourceDescription description : descriptions) {
                URI knownURI = description.getURI();
                if (knownURI.isArchive()) {
                    String authority = knownURI.authority();
                    if (expectedAuthority.equals(authority)) {
                        toBeDeleted.add(knownURI);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
项目:n4js    文件:N4JSDirtyStateEditorSupport.java   
@Override
public void scheduleUpdateEditorJob(final IResourceDescription.Event event) {
    N4JSUpdateEditorStateJob job = updateEditorStateJob;
    if (job == null) {
        job = createUpdateEditorJob();
        updateEditorStateJob = job;
    }
    job.scheduleFor(event);
}
项目:n4js    文件:N4JSDirtyStateEditorSupport.java   
private Set<URI> collectDeltaURIs(Event event) {
    Set<URI> deltaURIs = Sets.newHashSet();
    for (IResourceDescription.Delta delta : event.getDeltas()) {
        deltaURIs.add(delta.getUri());
    }
    return deltaURIs;
}