<commit_before>package org.eclipse.xtext.crossref.impl;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.crossref.IFragmentProvider;

public class XtextBuiltinFragmentProvider implements IFragmentProvider {

	public String getFragment(EObject obj) {
		EClass eclass = obj.eClass();
		EList<EAttribute> attributes = eclass.getEAllAttributes();
		for (EAttribute a : attributes) {
			if (a.getName().equals("name")) {
				Object name = obj.eGet(a);
				if (name instanceof String)
					return (String) name;
			}
		}
		return null;
	}

}<commit_msg>Improved performance for URI fragment construction.<commit_after>/*******************************************************************************
 * Copyright (c) 2008 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.crossref.impl;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtext.crossref.IFragmentProvider;

/**
 * @author <NAME> - Initial contribution and API
 * @author <NAME>
 */
public class XtextBuiltinFragmentProvider implements IFragmentProvider {

	public String getFragment(EObject obj) {
		EClass eclass = obj.eClass();
		
		EStructuralFeature structuralFeature = eclass.getEStructuralFeature("name");
		if (structuralFeature != null) {
			if (structuralFeature instanceof EAttribute) {
				EAttribute attribute = (EAttribute) structuralFeature;
				Object name = obj.eGet(attribute);
				if (name instanceof String) {
					return (String) name;
				}
			}
		}
		return null;
	}

}
{'fraction_non_alphanumeric': 0.17408123791102514, 'fraction_numerical': 0.0038684719535783366, 'mean_word_length': 4.877840909090909, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7155709', 'n_tokens_mistral': 656, 'n_tokens_neox': 587, 'n_words': 147}