Java Code Examples for org.eclipse.emf.ecore.resource.ResourceSet#getAllContents()

The following examples show how to use org.eclipse.emf.ecore.resource.ResourceSet#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: ResourceSetBasedSlotEntry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected List<EObject> findEObjectsOfType(Set<EClass> eClasses, IResourceDescriptions resourceDescriptions,
		ResourceSet resourceSet) {
	List<EObject> result = Lists.newArrayList();
	for (Resource resource : resourceSet.getResources()) {
		if (!resource.isLoaded()) {
			try {
				resource.load(null);
			} catch (IOException e) {
				throw new WrappedException(e);
			}
		}
	}
	for (Iterator<Notifier> i = resourceSet.getAllContents(); i.hasNext();) {
		Notifier next = i.next();
		if (next instanceof EObject && matches(eClasses, (EObject) next)) {
			result.add((EObject) next);
		}
	}
	return result;
}
 
Example 2
Source File: GenconfUtils.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes the {@link Generation#getDefinitions() variable definitions} from the given {@link Generation} with the given
 * {@link ResourceSet}.
 * 
 * @param generation
 *            the {@link Generation} to initialize
 * @param queryEnvironment
 *            the {@link IReadOnlyQueryEnvironment}
 * @param properties
 *            the {@link TemplateCustomProperties}
 * @param resourceSetForModels
 *            the {@link ResourceSet} to get values from
 */
public static void initializeVariableDefinition(Generation generation, IReadOnlyQueryEnvironment queryEnvironment,
        TemplateCustomProperties properties, ResourceSet resourceSetForModels) {
    final AstValidator validator = new AstValidator(new ValidationServices(queryEnvironment));
    final Map<ModelDefinition, Set<IType>> toInitialilize = new HashMap<ModelDefinition, Set<IType>>();
    for (Definition definition : generation.getDefinitions()) {
        if (definition instanceof ModelDefinition && ((ModelDefinition) definition).getValue() == null) {
            final ModelDefinition modelDefinition = (ModelDefinition) definition;
            final Set<IType> possibleTypes = properties.getVariableTypes(validator, queryEnvironment,
                    properties.getVariables().get(modelDefinition.getKey()));
            toInitialilize.put(modelDefinition, possibleTypes);
        }
    }

    final Iterator<Notifier> it = resourceSetForModels.getAllContents();
    while (!toInitialilize.isEmpty() && it.hasNext()) {
        final Notifier notifier = it.next();
        if (notifier instanceof EObject) {
            EObject element = (EObject) notifier;
            final EClassifierType elementType = new EClassifierType(queryEnvironment, element.eClass());
            ModelDefinition initialized = null;
            for (Entry<ModelDefinition, Set<IType>> entry : toInitialilize.entrySet()) {
                for (IType definitionType : entry.getValue()) {
                    if (definitionType.isAssignableFrom(elementType)) {
                        initialized = entry.getKey();
                        initialized.setValue(element);
                    }
                }
            }
            if (initialized != null) {
                toInitialilize.remove(initialized);
            }
        }
    }
}