Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#getAllProperContents()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#getAllProperContents() . 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: GlobalObjectScope.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
	IDefaultResourceDescriptionStrategy strategy = ((XtextResource) resource).getResourceServiceProvider()
			.get(IDefaultResourceDescriptionStrategy.class);
	TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(resource, false);
	IAcceptor<IEObjectDescription> acceptor = new IAcceptor<>() {
		@Override
		public void accept(IEObjectDescription description) {
			elements.put(description.getQualifiedName(), description);
		}
	};
	while (allProperContents.hasNext()) {
		EObject content = allProperContents.next();
		if (!strategy.createEObjectDescriptions(content, acceptor)) {
			allProperContents.prune();
		}
	}
}
 
Example 2
Source File: EcoreResourceDescriptionManagerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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));
					}
				}
			}
		}
	}
 
Example 3
Source File: DefaultDependentElementsCalculator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<URI> getDependentElementURIs(EObject baseElement, IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	List<URI> elementURIs = Lists.newArrayList();
	int counter = 0;
	for (Iterator<EObject> iterator = EcoreUtil.getAllProperContents(baseElement, false); iterator.hasNext();) {
		if(progress.isCanceled()) {
			throw new OperationCanceledException();
		}
		EObject childElement = iterator.next();
		if (nameProvider.getFullyQualifiedName(childElement)!=null) {
			URI childURI = EcoreUtil.getURI(childElement);
			if (childURI != null) {
				elementURIs.add(childURI);
			}
		}
		counter++;
		if (counter % MONITOR_CHUNK_SIZE == 0) {
			progress.worked(1);
			progress.setWorkRemaining(2);
		}
	}
	return elementURIs;
}
 
Example 4
Source File: IReferableElementsUnloader.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void unloadRoot(EObject root) {
	// Content adapters should be removed the same way as they are added: top-down. 
	// Fragments are recursive, so we need them to be calculated before proxifying the container.
	// OTOH, some model elements resolve their children when being proxified (e.g. EPackageImpl).
	// => first calculate all fragments, then proxify elements starting form root.
	List<Pair<EObject, URI>> elementsToUnload = newArrayList();
	elementsToUnload.add(Tuples.create(root, EcoreUtil.getURI(root)));
	root.eAdapters().clear();
	for (Iterator<EObject> i = EcoreUtil.getAllProperContents(root, false); i.hasNext();) {
		EObject element = i.next();
		elementsToUnload.add(Tuples.create(element, EcoreUtil.getURI(element)));
		element.eAdapters().clear();
	}
	for (Pair<EObject,URI> elementToUnload : elementsToUnload) {
		((InternalEObject) elementToUnload.getFirst()).eSetProxyURI(elementToUnload.getSecond());
	}
}
 
Example 5
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected List<IEObjectDescription> computeExportedObjects() {
	if (!getResource().isLoaded()) {
		try {
			getResource().load(null);
		} catch (IOException e) {
			log.error(e.getMessage(), e);
			return Collections.<IEObjectDescription> emptyList();
		}
	}
	final List<IEObjectDescription> exportedEObjects = newArrayList();
	IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {
		@Override
		public void accept(IEObjectDescription eObjectDescription) {
			exportedEObjects.add(eObjectDescription);
		}
	};
	TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(getResource(), false);
	while (allProperContents.hasNext()) {
		EObject content = allProperContents.next();
		if (!strategy.createEObjectDescriptions(content, acceptor))
			allProperContents.prune();
	}
	return exportedEObjects;
}
 
Example 6
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<IReferenceDescription> computeReferenceDescriptions() {
	final List<IReferenceDescription> referenceDescriptions = Lists.newArrayList();
	IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
		@Override
		public void accept(IReferenceDescription referenceDescription) {
			referenceDescriptions.add(referenceDescription);
		}
	};
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
	TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(this.resource, true);
	while (contents.hasNext()) {
		EObject eObject = contents.next();
		URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
		if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, acceptor))
			contents.prune();
	}
	return referenceDescriptions;
}
 
Example 7
Source File: EcoreUtil2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testExternalFormOfEReference() throws Exception {
	Registry registry = EPackage.Registry.INSTANCE;
	Set<String> uris = Sets.newHashSet(registry.keySet());
	for (String string : uris) {
		EPackage ePackage = registry.getEPackage(string);
		TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ePackage, true);
		while (iterator.hasNext()) {
			Object next = iterator.next();
			if (next instanceof EReference) {
				EReference ref = (EReference) next;
				String externalForm = EcoreUtil2.toExternalForm(ref);
				assertEquals(ref.toString() + " - " + externalForm, ref, EcoreUtil2.getEReferenceFromExternalForm(registry,externalForm));
			}
		}
	}
}
 
Example 8
Source File: ResourceDescription2.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected List<IReferenceDescription> computeReferenceDescriptions() {
  final ImmutableList.Builder<IReferenceDescription> referenceDescriptions = ImmutableList.builder();
  EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl);
  Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
  TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(getResource(), true);
  while (contents.hasNext()) {
    EObject eObject = contents.next();
    URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
    if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, referenceDescriptions::add)) {
      contents.prune();
    }
  }
  if (strategy instanceof AbstractResourceDescriptionStrategy) {
    ((AbstractResourceDescriptionStrategy) strategy).createImplicitReferenceDescriptions(getResource(), referenceDescriptions::add);
  }
  return referenceDescriptions.build();
}
 
Example 9
Source File: ProcResourceDescription.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<IEObjectDescription> computeExportedObjects() {
    if (!getResource().isLoaded()) {
        try {
            getResource().load(null);
        } catch (final IOException e) {
            return Collections.<IEObjectDescription> emptyList();
        }
    }
    final List<IEObjectDescription> exportedEObjects = newArrayList();
    final IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {

        @Override
        public void accept(final IEObjectDescription eObjectDescription) {
            exportedEObjects.add(eObjectDescription);
        }
    };
    final TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(getResource(), false);
    while (allProperContents.hasNext()) {
        final EObject content = allProperContents.next();
        if (!strategy.createEObjectDescriptions(content, acceptor)) {
            allProperContents.prune();
        }
    }
    return exportedEObjects;
}
 
Example 10
Source File: LinkingErrorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private int getContentSize(EObject model) {
	Resource resource = model.eResource();
	assertNotNull(resource);
	ResourceSet resourceSet = resource.getResourceSet();
	assertNotNull(resourceSet);
	TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(resourceSet, true);
	return getTreeIteratorContentSize(iterator);
}
 
Example 11
Source File: ResourceDescription2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create EObjectDescriptions for exported objects.
 *
 * @param resource
 *          LazyLinkingResource
 * @return list of object descriptions
 */
protected List<IEObjectDescription> createDescriptions(final LazyLinkingResource resource) {
  final ImmutableList.Builder<IEObjectDescription> exportedEObjects = ImmutableList.builder();
  IAcceptor<IEObjectDescription> acceptor = decorateExportedObjectsAcceptor(exportedEObjects::add);
  TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(resource, false);
  while (allProperContents.hasNext()) {
    EObject content = allProperContents.next();
    if (!strategy.createEObjectDescriptions(content, acceptor)) {
      allProperContents.prune();
    }
  }
  return exportedEObjects.build();
}
 
Example 12
Source File: HierarchicalDocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Iterator<Object> getAllContents(Resource resource) {
	return EcoreUtil.getAllProperContents(resource, true);
}