Search in sources :

Example 1 with EClassInfo

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) URI(org.eclipse.emf.common.util.URI)

Example 2 with EClassInfo

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);
                    }
                }
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 3 with EClassInfo

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 4 with EClassInfo

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()));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) EcorePackage(org.eclipse.emf.ecore.EcorePackage) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with EClassInfo

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()));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Test(org.junit.Test)

Aggregations

EClassInfo (org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo)16 Test (org.junit.Test)10 EClass (org.eclipse.emf.ecore.EClass)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 EcorePackage (org.eclipse.emf.ecore.EcorePackage)3 EReference (org.eclipse.emf.ecore.EReference)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 URI (org.eclipse.emf.common.util.URI)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)1