use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class GrammarAccessExtensions method getSingleElementDescription.
private List<String> getSingleElementDescription(final AbstractElement ele) {
final ArrayList<String> r = new ArrayList<String>(2);
boolean _matched = false;
if (ele instanceof Keyword) {
_matched = true;
String _value = ((Keyword) ele).getValue();
r.add(_value);
}
if (!_matched) {
if (ele instanceof Assignment) {
_matched = true;
String _feature = ((Assignment) ele).getFeature();
r.add(_feature);
}
}
if (!_matched) {
if (ele instanceof RuleCall) {
_matched = true;
String _name = ((RuleCall) ele).getRule().getName();
r.add(_name);
}
}
if (!_matched) {
if (ele instanceof Action) {
_matched = true;
TypeRef _type = ((Action) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((Action) ele).getType().getClassifier().getName();
r.add(_name);
}
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
boolean _not = (!_isNullOrEmpty);
if (_not) {
String _feature = ((Action) ele).getFeature();
r.add(_feature);
}
}
}
if (!_matched) {
if (ele instanceof CrossReference) {
_matched = true;
TypeRef _type = ((CrossReference) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((CrossReference) ele).getType().getClassifier().getName();
r.add(_name);
}
}
}
if (!_matched) {
if (ele instanceof EnumLiteralDeclaration) {
_matched = true;
String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
r.add(_name);
}
}
return r;
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method collectClassInfosOf.
private void collectClassInfosOf(EClassifierInfos target, EPackage referencedEPackage, AbstractMetamodelDeclaration metaModel, boolean generated) {
for (EClassifier eClassifier : referencedEPackage.getEClassifiers()) {
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClassifierInfo info = EClassifierInfo.createEClassInfo(eClass, generated, getGeneratedEPackageURIs(), GrammarUtil.getGrammar(metaModel));
target.addInfo(metaModel, eClassifier.getName(), info);
} else if (eClassifier instanceof EDataType) {
EDataType eDataType = (EDataType) eClassifier;
EClassifierInfo info = EClassifierInfo.createEDataTypeInfo(eDataType, generated);
target.addInfo(metaModel, eClassifier.getName(), info);
}
}
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method addSuperType.
private void addSuperType(ParserRule rule, TypeRef subTypeRef, EClassifierInfo superTypeInfo) throws TransformationException {
final EClassifier subType = subTypeRef.getClassifier();
final EClassifierInfo subTypeInfo = subType == null ? findOrCreateEClassifierInfo(subTypeRef, null, true) : eClassifierInfos.getInfoOrNull(subType);
if (subTypeInfo == null)
throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Type '" + superTypeInfo.getEClassifier().getName() + "' is not available.", rule.getType());
if (superTypeInfo.isAssignableFrom(subTypeInfo))
return;
if (subTypeInfo.getEClassifier() instanceof EDataType)
throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot add supertype '" + superTypeInfo.getEClassifier().getName() + "' to simple datatype '" + subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
if (!subTypeInfo.isGenerated())
throw new TransformationException(TransformationErrorCode.CannotCreateTypeInSealedMetamodel, "Cannot add supertype '" + superTypeInfo.getEClassifier().getName() + "' to sealed type '" + subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
subTypeInfo.addSupertype(superTypeInfo);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method clearPackage.
protected void clearPackage(Resource resource, EPackage pack) {
Map<InternalEObject, URI> uris = Maps.newHashMap();
for (EClassifier classifier : pack.getEClassifiers()) {
InternalEObject internalEObject = (InternalEObject) classifier;
URI appendFragment = resource.getURI().appendFragment(resource.getURIFragment(internalEObject));
uris.put(internalEObject, appendFragment);
}
pack.getEClassifiers().clear();
for (Map.Entry<InternalEObject, URI> entry : uris.entrySet()) {
entry.getKey().eSetProxyURI(entry.getValue());
}
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class TypeHierarchyHelper method pushFeaturesUp.
private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
EClass eClass = info.getEClass();
if (info.isGenerated()) {
if (traversedClasses.add(eClass)) {
if (eClass.getESuperTypes().isEmpty())
return;
for (EClass superType : eClass.getESuperTypes()) {
EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
pushFeaturesUp(superInfo, traversedClasses);
}
Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
Set<String> skippedNames = Sets.newLinkedHashSet();
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
if (feature.getEContainingClass() != eClass) {
if (allFeatures.containsKey(feature.getName())) {
allFeatures.remove(feature.getName());
} else if (skippedNames.add(feature.getName())) {
allFeatures.put(feature.getName(), feature);
}
}
}
Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
while (iter.hasNext()) {
EStructuralFeature declared = iter.next();
EStructuralFeature existing = allFeatures.get(declared.getName());
if (existing != null) {
EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
if (compatibleType != null) {
iter.remove();
existing.setEType(compatibleType);
}
}
}
}
}
}
Aggregations