use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class ConcreteSyntaxConstraintProvider method createElement.
protected ISyntaxConstraint createElement(EObject obj) {
if (!(obj instanceof AbstractElement))
return null;
AbstractElement ele = (AbstractElement) obj;
boolean multiple = false;
boolean optional = false;
EClass semanticType = null;
while (true) {
multiple = multiple || isMultipleCardinality(ele);
optional = optional || isOptionalCardinality(ele);
if (ele.eContainer() instanceof ParserRule && ((ParserRule) ele.eContainer()).getType().getClassifier() instanceof EClass)
semanticType = (EClass) ((ParserRule) ele.eContainer()).getType().getClassifier();
if (ele instanceof Assignment) {
return createElement(ConstraintType.ASSIGNMENT, ele, semanticType, multiple, optional);
} else if (ele instanceof Group || ele instanceof UnorderedGroup) {
CompoundElement comp = (CompoundElement) ele;
AbstractElement lastChild = null;
for (AbstractElement o : comp.getElements()) if (containsRelevantElement(o)) {
if (lastChild == null)
lastChild = o;
else {
List<AbstractElement> c = new ArrayList<AbstractElement>(comp.getElements());
List<ISyntaxConstraint> e = createSummarizedAssignments(comp, c, semanticType, optional);
if (e.size() == 1 && c.size() == 0)
return e.get(0);
return createElement(ConstraintType.GROUP, ele, c, e, semanticType, multiple, optional);
}
}
if (lastChild == null)
return null;
ele = lastChild;
continue;
} else if (ele instanceof Alternatives) {
int relevantChildren = 0;
AbstractElement lastChild = null;
for (AbstractElement o : ((CompoundElement) ele).getElements()) if (containsRelevantElement(o)) {
relevantChildren++;
lastChild = o;
}
if (relevantChildren < ((CompoundElement) ele).getElements().size())
optional = true;
if (relevantChildren > 1)
return createElement(ConstraintType.ALTERNATIVE, ele, semanticType, multiple, optional);
if (lastChild == null)
return null;
ele = lastChild;
continue;
} else if (ele instanceof Action) {
semanticType = (EClass) ((Action) ele).getType().getClassifier();
return createElement(ConstraintType.ACTION, ele, semanticType, multiple, optional);
} else if (ele instanceof RuleCall) {
AbstractRule rule = ((RuleCall) ele).getRule();
if (rule.getType().getClassifier() instanceof EClass) {
ele = rule.getAlternatives();
continue;
}
}
return null;
}
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class EClassifierInfos method getSuperTypeInfos.
public List<EClassInfo> getSuperTypeInfos(EClassInfo subTypeInfo) throws UnexpectedClassInfoException {
List<EClassInfo> result = new ArrayList<EClassInfo>();
List<EClass> superTypes = subTypeInfo.getEClass().getESuperTypes();
for (int i = 0; i < superTypes.size(); i++) {
EClass superType = superTypes.get(i);
if (superType.eIsProxy()) {
URI proxyURI = EcoreUtil.getURI(superType);
if (proxyURI.isPlatformResource()) {
String platformString = proxyURI.toPlatformString(true);
URI platformPluginURI = URI.createPlatformPluginURI(platformString, true).appendFragment(proxyURI.fragment());
EObject secondAttempt = subTypeInfo.getEClass().eResource().getResourceSet().getEObject(platformPluginURI, true);
if (secondAttempt instanceof EClass) {
superType = (EClass) secondAttempt;
superTypes.set(i, superType);
}
}
}
EClassifierInfo info = getInfoOrNull(superType);
if (info != null) {
if (info instanceof EClassInfo) {
result.add((EClassInfo) info);
} else {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, info, null);
}
} else {
if (superType.eIsProxy()) {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, null, "Cannot load all supertypes of '" + subTypeInfo.getEClass().getName() + "'");
} else if (isPackageKnown(superType.getEPackage().getNsURI())) {
throw new UnexpectedClassInfoException(TransformationErrorCode.InvalidSupertype, subTypeInfo, null, "Cannot find info for type '" + superType.getName() + "'");
}
}
}
return result;
}
use of org.eclipse.emf.ecore.EClass 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);
}
}
}
}
}
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class TypeHierarchyHelper method getCommonDirectFeatures.
private Collection<EStructuralFeature> getCommonDirectFeatures(Collection<EClassInfo> infos) {
Collection<EStructuralFeature> result = Sets.newLinkedHashSet();
Iterator<EClassInfo> iterator = infos.iterator();
if (iterator.hasNext()) {
EClass eClass = iterator.next().getEClass();
result.addAll(eClass.getEStructuralFeatures());
}
while (iterator.hasNext()) result = getCommonFeatures(iterator.next(), result);
return result;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class OnChangeEvictingCacheAdapterTest method testAdapterIsCleared.
@Test
public void testAdapterIsCleared() throws Exception {
EcoreFactory factory = EcoreFactory.eINSTANCE;
EClass eClass = factory.createEClass();
Resource resource = new ResourceImpl();
resource.getContents().add(eClass);
CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
setValue(ca);
EAttribute attribute = factory.createEAttribute();
assertIsSet(ca);
eClass.getEStructuralFeatures().add(attribute);
assertIsNull(ca);
setValue(ca);
attribute.setName("Foo");
assertIsNull(ca);
setValue(ca);
}
Aggregations