All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.xtext.resource.containers.DescriptionAddingContainer Maven / Gradle / Ivy

There is a newer version: 2.4.3
Show newest version
/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.resource.containers;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.impl.AbstractContainer;

import com.google.common.collect.Iterables;

/**
 * A container implementation that ensures that a given resource description
 * is part of the container. Delegates any other requests to another container.
 * 
 * @author Sebastian Zarnekow - Initial contribution and API
 */
public class DescriptionAddingContainer extends AbstractContainer {

	private final IResourceDescription description;
	private final IContainer delegate;

	/**
	 * @param addMe the description to be merged into this container. May not be contained in the given delegate.
	 * @param delegate the backing container.
	 */
	public DescriptionAddingContainer(IResourceDescription addMe, IContainer delegate) {
		this.description = addMe;
		this.delegate = delegate;
	}
	
	public Iterable getResourceDescriptions() {
		return Iterables.concat(Collections.singleton(description), delegate.getResourceDescriptions());
	}
	
	@Override
	public int getResourceDescriptionCount() {
		return delegate.getResourceDescriptionCount() + 1;
	}
	
	@Override
	public boolean hasResourceDescription(URI uri) {
		if (uri.equals(description.getURI()))
			return true;
		return delegate.hasResourceDescription(uri);
	}
	
	@Override
	public boolean isEmpty() {
		return false;
	}
	
	@Override
	public Iterable getExportedObjects(EClass type, QualifiedName qualifiedName, boolean ignoreCase) {
		Iterable added = description.getExportedObjects(type, qualifiedName, ignoreCase);
		Iterable delegated = delegate.getExportedObjects(type, qualifiedName, ignoreCase);
		return Iterables.concat(added, delegated);
	}

	@Override
	public Iterable getExportedObjectsByType(EClass type) {
		Iterable added = description.getExportedObjectsByType(type);
		Iterable delegated = delegate.getExportedObjectsByType(type);
		return Iterables.concat(added, delegated);
	}

	@Override
	public IResourceDescription getResourceDescription(URI uri) {
		if (description.getURI().equals(uri))
			return description;
		return delegate.getResourceDescription(uri);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy