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

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#getAllContents() . 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: FragmentFakingEcoreResourceTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testFakedURIs_01() {
	ResourceSaveIndicator indicator = new ResourceSaveIndicator();
	EPackage sub = metamodel.getESubpackages().get(0);
	Resource resource = new FragmentFakingEcoreResource(URI.createURI(sub.getNsURI()), indicator);
	resource.getContents().add(sub);
	Iterator<Object> contents = EcoreUtil.getAllContents(sub, true);
	indicator.set(Boolean.TRUE);
	while(contents.hasNext()) {
		Object content = contents.next();
		if (content instanceof EClassifier) {
			EClassifier classifier = (EClassifier) content;
			if (classifier.getName().equals(SubsubpackagePackage.Literals.ANOTHER_TYPE.getName())) {
				assertEquals(EcoreUtil.getURI(classifier), EcoreUtil.getURI(SubsubpackagePackage.Literals.ANOTHER_TYPE));
			}
			if (classifier.getName().equals(AsubpackagePackage.Literals.ATYPE.getName())) {
				assertEquals(EcoreUtil.getURI(classifier), EcoreUtil.getURI(AsubpackagePackage.Literals.ATYPE));
			}
			if (classifier.getName().equals(AsubpackagePackage.Literals.AMODEL.getName())) {
				assertEquals(EcoreUtil.getURI(classifier), EcoreUtil.getURI(AsubpackagePackage.Literals.AMODEL));
			}
		}
	}
}
 
Example 2
Source File: AbstractSCTResource.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public void resolveLazyCrossReferences(CancelIndicator monitor) {
	TreeIterator<Object> iterator = EcoreUtil.getAllContents(this, true);
	while (iterator.hasNext()) {
		InternalEObject source = (InternalEObject) iterator.next();
		EStructuralFeature[] eStructuralFeatures = ((EClassImpl.FeatureSubsetSupplier) source.eClass()
				.getEAllStructuralFeatures()).crossReferences();
		if (eStructuralFeatures != null) {
			for (EStructuralFeature crossRef : eStructuralFeatures) {
				if (monitor.isCanceled()) {
					return;
				}
				resolveLazyCrossReference(source, crossRef, monitor);
			}
		}
	}
}
 
Example 3
Source File: SerializerTester.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected List<Pair<EObject, ICompositeNode>> detachNodeModel(EObject eObject) {
	EcoreUtil.resolveAll(eObject);
	List<Pair<EObject, ICompositeNode>> result = Lists.newArrayList();
	Iterator<Object> iterator = EcoreUtil.getAllContents(eObject.eResource(), false);
	while (iterator.hasNext()) {
		EObject object = (EObject) iterator.next();
		Iterator<Adapter> adapters = object.eAdapters().iterator();
		while (adapters.hasNext()) {
			Adapter adapter = adapters.next();
			if (adapter instanceof ICompositeNode) {
				adapters.remove();
				result.add(Tuples.create(object, (ICompositeNode) adapter));
				break;
			}
		}
	}
	return result;
}
 
Example 4
Source File: FragmentFakingEcoreResourceTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testFakedURIs_02() {
	ResourceSaveIndicator indicator = new ResourceSaveIndicator();
	EPackage sub = metamodel.getESubpackages().get(0);
	Resource resource = new FragmentFakingEcoreResource(URI.createURI(sub.getNsURI()), indicator);
	resource.getContents().add(sub);
	Iterator<Object> contents = EcoreUtil.getAllContents(sub, true);
	indicator.set(Boolean.FALSE);
	while(contents.hasNext()) {
		Object content = contents.next();
		if (content instanceof EClassifier) {
			EClassifier classifier = (EClassifier) content;
			if (classifier.getName().equals(SubsubpackagePackage.Literals.ANOTHER_TYPE.getName())) {
				assertFalse(EcoreUtil.getURI(classifier).equals(EcoreUtil.getURI(SubsubpackagePackage.Literals.ANOTHER_TYPE)));
			}
			if (classifier.getName().equals(AsubpackagePackage.Literals.ATYPE.getName())) {
				assertEquals(EcoreUtil.getURI(classifier), EcoreUtil.getURI(AsubpackagePackage.Literals.ATYPE));
			}
			if (classifier.getName().equals(AsubpackagePackage.Literals.AMODEL.getName())) {
				assertEquals(EcoreUtil.getURI(classifier), EcoreUtil.getURI(AsubpackagePackage.Literals.AMODEL));
			}
		}
	}
}
 
Example 5
Source File: TypeProviderErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNoException_08() throws Exception {
	XtendFile file = file(
			"import org.eclipse.emf.ecore.EReference\n" + 
			"import org.eclipse.emf.ecore.EPackage\n" +
			"import org.eclipse.emf.ecore.EObject\n" + 
			"import org.eclipse.xtext.resource.EObjectDescription\n" +
			"class Foo  {\n" + 
			"	def doStuff(EObject context, EReference reference) {\n" + 
			"		switch (context) {\n" + 
			"			EPackage: {\n" + 
			" 				val descriptions = (context as EPackage).EClassifiers.map(c|EObjectDescription::create(null, c))\n" + 
			" 			}\n" + 
			" 		}\n" + 
			"		return null\n" + 
			"	}" +
			"}");
	Iterator<Object> contents = EcoreUtil.getAllContents(file.eResource(), true);
	while(contents.hasNext()) {
		EObject object = (EObject) contents.next();
		if (object instanceof XExpression) {
			XExpression expression = (XExpression) object;
			getReturnType(expression);
		}
	}
}
 
Example 6
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, EPackage> findAllUsedEPackages(List<EPackage> generatedPackages) {
	Map<String, EPackage> result = Maps.newHashMap();
	TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
	while(packageContentIterator.hasNext()) {
		EObject current = packageContentIterator.next();
		for(EObject referenced: current.eCrossReferences()) {
			if (referenced.eIsProxy())
				throw new RuntimeException("Unresolved proxy: " + referenced + " in " + current);
			if (referenced instanceof EClassifier) {
				EPackage referencedPackage = ((EClassifier) referenced).getEPackage();
				if (!generatedPackages.contains(referencedPackage)) {
					result.put(referencedPackage.getNsURI(), referencedPackage);
				}
			}
		}
	}
	return result;
}
 
Example 7
Source File: TypeProviderErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNoException_03() throws Exception {
	XtendFile file = file(" \n" + 
			"import static java.util.Arrays.*\n" + 
			"import static extension java.util.Collections.*\n" + 
			"class NoException {\n" + 
			"	@com.google.inject.Inject\n" + 
			"	ArrayList myList\n" + 
			"	@com.google.inject.Inject extension String\n" + 
			"	def boolean something(int i) {\n" + 
			"	  if (i.indexOf() == 0) {\n" + 
			"	    return myList.contains(i)\n" + 
			"	  } \n" + 
			"	  asList(i)\n" + 
			"	  i.singletonList()\n" + 
			"	  false\n" + 
			"	}\n" + 
			"}");
	Iterator<Object> contents = EcoreUtil.getAllContents(file.eResource(), true);
	while(contents.hasNext()) {
		EObject object = (EObject) contents.next();
		if (object instanceof XExpression) {
			XExpression expression = (XExpression) object;
			getReturnType(expression);
		}
	}
}
 
Example 8
Source File: SemanticHighlightingCalculator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void provideHighlightingFor(final XtextResource resource, final IHighlightedPositionAcceptor acceptor, final CancelIndicator cancelIndicator) {
  if (resource == null) {
    return;
  }
  Iterator<EObject> iter = EcoreUtil.getAllContents(resource, true);
  while (iter.hasNext()) {
    EObject current = iter.next();

    if (current instanceof ConfiguredCheck && ((ConfiguredCheck) current).getSeverity().equals(SeverityKind.IGNORE)) {
      INode node = getFirstParseTreeNode(current, CheckcfgPackage.Literals.CONFIGURED_CHECK__CHECK);
      highlightNode(node, SemanticHighlightingConfiguration.DISABLED_VALUE_ID, acceptor);
    }
  }
}
 
Example 9
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private Map<String, EPackage> findAllUsedEPackages(final List<EPackage> generatedPackages) {
  final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
  final TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
  while (packageContentIterator.hasNext()) {
    {
      final EObject current = packageContentIterator.next();
      EList<EObject> _eCrossReferences = current.eCrossReferences();
      for (final EObject referenced : _eCrossReferences) {
        {
          boolean _eIsProxy = referenced.eIsProxy();
          if (_eIsProxy) {
            throw new RuntimeException(((("Unresolved proxy: " + referenced) + " in ") + current));
          }
          if ((referenced instanceof EClassifier)) {
            final EPackage referencedPackage = ((EClassifier)referenced).getEPackage();
            boolean _contains = generatedPackages.contains(referencedPackage);
            boolean _not = (!_contains);
            if (_not) {
              result.put(referencedPackage.getNsURI(), referencedPackage);
            }
          }
        }
      }
    }
  }
  return result;
}
 
Example 10
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) {
	final IExtraLanguageGeneratorContext generatorContext = createGeneratorContext(fsa, context, input);
	final EList<EObject> contents = input.getContents();
	for (final EObject obj : contents) {
		if (canGenerateFor(obj)) {
			before(obj, generatorContext);
			final Iterator<EObject> iterator = EcoreUtil.getAllContents(obj, false);
			while (iterator.hasNext()) {
				final EObject subobj = iterator.next();
				before(subobj, generatorContext);
			}
		}
	}
}
 
Example 11
Source File: N4JSHierarchicalDocumentSymbolService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Iterator<Object> getAllContents(Resource resource) {
	if (resource instanceof N4JSResource) {
		N4JSResource n4jsResource = (N4JSResource) resource;
		EList<EObject> contents = n4jsResource.getContents();
		if (contents.size() > 1) {
			EObject tModule = contents.get(1);
			return EcoreUtil.getAllContents(tModule, true);
		}
	}
	return super.getAllContents(resource);
}
 
Example 12
Source File: TypeProviderErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoException_07() throws Exception {
	XtendFile file = file("class foo  {\n" + 
						  "		def bar() {" + 
						  "			try catch()" +
	    				  "		}" +
						  "}");
	Iterator<Object> contents = EcoreUtil.getAllContents(file.eResource(), true);
	while(contents.hasNext()) {
		EObject object = (EObject) contents.next();
		if (object instanceof XExpression) {
			XExpression expression = (XExpression) object;
			getReturnType(expression);
		}
	}
}
 
Example 13
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void getAndResolveAllFragments(Resource resource) {
	Iterator<EObject> iter = EcoreUtil.getAllContents(resource, false);
	while (iter.hasNext()) {
		EObject next = iter.next();
		String fragment = resource.getURIFragment(next);
		EObject resolved = resource.getEObject(fragment);
		assertSame(fragment + " / " + next.eClass().getName(), next, resolved);
	}
}
 
Example 14
Source File: AbstractTypeProviderPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLoadTypesAndResolveAllParameterNames() throws Exception {
	for (String name : getClassNamesToLoad()) {
		JvmDeclaredType type = loadAndResolve(name, true, true, true, true, true);
		TreeIterator<Object> iterator = EcoreUtil.getAllContents(type.eResource().getResourceSet(), true);
		while (iterator.hasNext()) {
			Object next = iterator.next();
			if (next instanceof JvmFormalParameter) {
				((JvmFormalParameter) next).getName();
			}
		}
	}
}
 
Example 15
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void afterGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) {
	final IExtraLanguageGeneratorContext generatorContext = createGeneratorContext(fsa, context, input);
	final EList<EObject> contents = input.getContents();
	for (final EObject obj : contents) {
		if (canGenerateFor(obj)) {
			final Iterator<EObject> iterator = EcoreUtil.getAllContents(obj, false);
			while (iterator.hasNext()) {
				final EObject subobj = iterator.next();
				after(subobj, generatorContext);
			}
			after(obj, generatorContext);
		}
	}
}
 
Example 16
Source File: TypeProviderErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoException_04() throws Exception {
	XtendFile file = file("class NoException { dispatch");
	Iterator<Object> contents = EcoreUtil.getAllContents(file.eResource(), true);
	while(contents.hasNext()) {
		EObject object = (EObject) contents.next();
		if (object instanceof JvmIdentifiableElement) {
			JvmIdentifiableElement element = (JvmIdentifiableElement) object;
			getType(element);
		}
	}
}
 
Example 17
Source File: TypeProviderErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoException_05() throws Exception {
	XtendFile file = file("package org.eclipse.xtend.core.tests.typing\n" + 
			"import org.eclipse.emf.ecore.EClass\n" + 
			"import org.eclipse.emf.ecore.EPackage\n" + 
			"import org.eclipse.emf.ecore.EStructuralFeature\n" + 
			"import org.eclipse.emf.ecore.EObject\n" + 
			"class NoException {\n" + 
			"	def dispatchtransform(EClass model) {\n" + 
			"		model.ETypeParameters.map(e|transform(e))\n" + 
			"	}\n" + 
			"	def dispatch transform(EPackage packageDecl) {\n" + 
			"		packageDecl.eContents.map(e|transform(e))\n" + 
			"	}\n" + 
			"	def dispatch transform(EStructuralFeature entity) {\n" + 
			"		val inferredType = null\n" + 
			"		newArrayList(inferredType as EObject) 	 \n" + 
			"	}\n" + 
			"}");
	Iterator<Object> contents = EcoreUtil.getAllContents(file.eResource(), true);
	while(contents.hasNext()) {
		EObject object = (EObject) contents.next();
		if (object instanceof XExpression) {
			XExpression expression = (XExpression) object;
			getExpectedType(expression);
		}
	}
}
 
Example 18
Source File: SmokeTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void checkNoErrorsInTypeProvider(LazyLinkingResource resource) {
	typeResolver.resolveTypes(resource);
	
	Iterator<Object> contents = EcoreUtil.getAllContents(resource, true);
	while(contents.hasNext()) {
		Object object = contents.next();
		if (object instanceof JvmWildcardTypeReference) {
			assertTrue(((JvmWildcardTypeReference) object).eContainer() instanceof JvmTypeReference);
		}
	}
}
 
Example 19
Source File: ImportedNamespaceAwareLocalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ISelectable internalGetAllDescriptions(final Resource resource) {
	Iterable<EObject> allContents = new Iterable<EObject>(){
		@Override
		public Iterator<EObject> iterator() {
			return EcoreUtil.getAllContents(resource, false);
		}
	}; 
	Iterable<IEObjectDescription> allDescriptions = Scopes.scopedElementsFor(allContents, qualifiedNameProvider);
	return new MultimapBasedSelectable(allDescriptions);
}
 
Example 20
Source File: TypeWalker.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void walk ( final EObject start, final TypeVisitor<? super T> visitor ) throws Exception
{
    final TreeIterator<?> iterator = EcoreUtil.getAllContents ( start, true );
    walk ( iterator, visitor );
}