use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo 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.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo 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.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo 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.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.
the class EClassInfoTest method testChangeable.
public void testChangeable() {
EcorePackage pack = EcorePackage.eINSTANCE;
EClass eClass = pack.getEClass();
EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
EcoreFactory fac = EcoreFactory.eINSTANCE;
EReference reference = fac.createEReference();
reference.setName("newReference");
reference.setEType(eClass);
reference.setChangeable(true);
reference.setContainment(true);
eClass.getEStructuralFeatures().add(reference);
assertEquals(true, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
reference.setChangeable(false);
assertEquals(false, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
}
use of org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo in project xtext-core by eclipse.
the class EClassInfoTest method testContainsCompatibleFeature_01.
@Test
public void testContainsCompatibleFeature_01() throws Exception {
EcorePackage pack = EcorePackage.eINSTANCE;
EClass eClass = pack.getEClass();
EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
assertEquals(true, objectUnderTest.containsCompatibleFeature("name", false, true, pack.getEString(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEString(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEAnnotation(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("name", true, true, pack.getEShort(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("names", false, true, pack.getEString(), new StringBuilder()));
assertEquals(true, objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEAttribute(), new StringBuilder()));
assertEquals(true, objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEReference(), new StringBuilder()));
assertEquals(true, objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEStructuralFeature(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("eStructuralFeatures", false, true, pack.getEStructuralFeature(), new StringBuilder()));
assertEquals(false, objectUnderTest.containsCompatibleFeature("eStructuralFeatures", true, true, pack.getEAnnotation(), new StringBuilder()));
}
Aggregations