use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class LazyLinker method globalFindInstantiableCompatible.
protected EClass globalFindInstantiableCompatible(EClass eType) {
Set<String> visitedPackages = Sets.newHashSet(eType.getEPackage().getNsURI());
for (AbstractMetamodelDeclaration metamodel : GrammarUtil.allMetamodelDeclarations(grammarAccess.getGrammar())) {
if (visitedPackages.add(metamodel.getEPackage().getNsURI())) {
EClass result = findSubTypeInEPackage(metamodel.getEPackage(), eType);
if (result != null)
return result;
}
}
log.warn("Traversing EPackage registry to find instantiable subtype for '" + eType.getName() + "'");
log.warn("You may override LazyLinker#globalFindInstantiableCompatible(..) to prevent this.");
for (String nsURI : getRegisteredNsUris()) {
if (visitedPackages.add(nsURI)) {
try {
EClass result = findSubTypeInEPackage(getRegistry().getEPackage(nsURI), eType);
if (result != null)
return result;
} catch (WrappedException ex) {
log.error("Error when loading EPackage '" + nsURI + "'");
log.error("You may override LazyLinker#globalFindInstantiableCompatible(..) to prevent this.");
log.error("Error when loading EPackage '" + nsURI + "'", ex);
}
}
}
throw new IllegalStateException("Could not find an instantiable subtype for type: '" + eType.getName() + "' (" + eType.getEPackage().getNsURI() + ").");
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class LazyLinker method getProxyType.
/**
* @since 2.7
*/
protected EClass getProxyType(EObject obj, EReference eRef) {
EClass referenceType = ecoreGenericsUtil.getReferenceType(eRef, obj.eClass());
EClass instantiableType = instantiableSubTypes.get(referenceType);
return instantiableType;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class EcoreUtil2 method getCompatibleType.
/**
* @since 2.1
*/
public static EClassifier getCompatibleType(EClassifier typeA, EClassifier typeB, EObject grammarContext) {
if (typeA.equals(typeB))
return typeA;
if (typeA instanceof EDataType && typeB instanceof EDataType) {
Class<?> instanceClassA = typeA.getInstanceClass();
Class<?> instanceClassB = typeB.getInstanceClass();
if (instanceClassA != null && instanceClassB != null) {
if (instanceClassA.isAssignableFrom(instanceClassB))
return typeA;
if (instanceClassB.isAssignableFrom(instanceClassA))
return typeB;
}
}
// no common type for simple datatypes available
if (!(typeA instanceof EClass && typeB instanceof EClass))
return null;
List<EClass> sortedCandidates = getSortedCommonCompatibleTypeCandidates((EClass) typeA, (EClass) typeB);
for (EClass candidate : sortedCandidates) if (isCommonCompatibleType(candidate, sortedCandidates))
return candidate;
EClass result = GrammarUtil.findEObject(GrammarUtil.getGrammar(grammarContext));
return result;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class EcoreUtil2 method toExternalForm.
/**
* creates an external form of the given EReference. Use
* {@link #getEReferenceFromExternalForm(org.eclipse.emf.ecore.EPackage.Registry, String)} to retrieve the
* {@link EReference} back.
*/
public static String toExternalForm(EReference ref) {
if (ref == null)
return null;
String result = exernalFormCache.get(ref);
if (result == null) {
EClass class1 = ref.getEContainingClass();
if (// some references may be contained in an EAnnotation
class1 == null)
result = EcoreUtil.getURI(ref).toString();
else {
StringBuilder buff = new StringBuilder(class1.getEPackage().getNsURI());
buff.append(delim).append(class1.getName());
buff.append(delim).append(class1.getFeatureID(ref));
result = buff.toString();
}
exernalFormCache.put(ref, result);
}
return result;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class EcoreUtil2 method getEReferenceFromExternalForm.
/**
* looks up the EReference in the passed registry, given the external form. if registry == null this
*/
public static EReference getEReferenceFromExternalForm(EPackage.Registry registry, String externalForm) {
if (externalForm == null)
return null;
List<String> split = Strings.split(externalForm, delim);
if (split.size() != 3) {
URI uri = URI.createURI(externalForm);
URI packURI = uri.trimFragment();
EPackage ePackage = registry.getEPackage(packURI.toString());
if (ePackage == null)
return null;
EReference result = (EReference) ePackage.eResource().getEObject(uri.fragment());
return result;
}
EPackage ePackage = registry.getEPackage(split.get(0));
if (ePackage == null)
return null;
EClass clazz = (EClass) ePackage.getEClassifier(split.get(1));
if (clazz == null)
return null;
return (EReference) clazz.getEStructuralFeature(Integer.valueOf(split.get(2)));
}
Aggregations