<commit_before>/*******************************************************************************
 * Copyright (c) 2009 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.impl;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceDescription;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

/**
 * Abstract container implementation. Minimal clients have to implement
 * {@link #getResourceDescriptions()}.
 * 
 * @author <NAME> - Initial contribution and API
 */
public abstract class AbstractContainer extends AbstractCompoundSelectable implements IContainer {
	
	@Override
	protected Iterable<IResourceDescription> getSelectables() {
		return getResourceDescriptions();
	}
	
	public int getResourceDescriptionCount() {
		return Iterables.size(getResourceDescriptions());
	}
	
	public boolean hasResourceDescription(URI uri) {
		return getResourceDescription(uri) != null;
	}
	
	public IResourceDescription getResourceDescription(final URI uri) {
		return Iterables.find(getResourceDescriptions(), new Predicate<IResourceDescription>() {
			public boolean apply(IResourceDescription input) {
				return uri.equals(input.getURI());
			}
		});
	}
	
	@Override
	public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
		URI resourceURI = EcoreUtil2.getNormalizedResourceURI(object);
		IResourceDescription description = getResourceDescription(resourceURI);
		if (description == null)
			return Collections.emptyList();
		return description.getExportedObjectsByObject(object);
	}
	
}
<commit_msg>AbstractContainer has/getResourceDescription throws unwanted exceptions see https://bugs.eclipse.org/bugs/show_bug.cgi?id=372041<commit_after>/*******************************************************************************
 * Copyright (c) 2009 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.impl;

import java.util.Collections;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceDescription;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

/**
 * Abstract container implementation. Minimal clients have to implement
 * {@link #getResourceDescriptions()}.
 * 
 * @author <NAME> - Initial contribution and API
 */
public abstract class AbstractContainer extends AbstractCompoundSelectable implements IContainer {
	
	@Override
	protected Iterable<IResourceDescription> getSelectables() {
		return getResourceDescriptions();
	}
	
	public int getResourceDescriptionCount() {
		return Iterables.size(getResourceDescriptions());
	}
	
	public boolean hasResourceDescription(URI uri) {
		return getResourceDescription(uri) != null;
	}
	
	public IResourceDescription getResourceDescription(final URI uri) {
		return Iterables.find(getResourceDescriptions(), new Predicate<IResourceDescription>() {
			public boolean apply(IResourceDescription input) {
				return uri.equals(input.getURI());
			}
		}, null);
	}
	
	@Override
	public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
		URI resourceURI = EcoreUtil2.getNormalizedResourceURI(object);
		IResourceDescription description = getResourceDescription(resourceURI);
		if (description == null)
			return Collections.emptyList();
		return description.getExportedObjectsByObject(object);
	}
	
}

{'fraction_non_alphanumeric': 0.15873731679819617, 'fraction_numerical': 0.005862457722660654, 'mean_word_length': 6.063694267515924, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673888', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1121, 'n_words': 277}