Search in sources :

Example 61 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class Xtext2EcoreInterpretationContext method addFeature.

public void addFeature(Assignment assignment) throws TransformationException {
    final String featureName = assignment.getFeature();
    boolean isMultivalue = GrammarUtil.isMultipleAssignment(assignment);
    boolean isContainment = true;
    EClassifierInfoAccess featureTypeInfo;
    if (GrammarUtil.isBooleanAssignment(assignment)) {
        checkNoFragmentRuleCall(assignment.getTerminal());
        EDataType eBoolean = GrammarUtil.findEBoolean(GrammarUtil.getGrammar(assignment));
        EClassifierInfo classifierInfo = getEClassifierInfoOrThrowException(eBoolean, assignment);
        featureTypeInfo = () -> classifierInfo;
        isMultivalue = false;
    } else {
        AbstractElement terminal = assignment.getTerminal();
        if (terminal == null) {
            throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot derive type from incomplete assignment.", assignment);
        }
        checkNoFragmentRuleCall(terminal);
        List<EClassifierInfo> classifierInfos = new ArrayList<>();
        for (EClassifier type : getTerminalTypes(terminal)) {
            classifierInfos.add(getEClassifierInfoOrThrowException(type, assignment));
        }
        isContainment = isContainmentAssignment(assignment);
        featureTypeInfo = new EClassifierInfoAccess() {

            @Override
            public Collection<EClassifierInfo> getCurrentTypes() {
                return classifierInfos;
            }

            @Override
            public EClassifierInfo getCurrentCompatibleType() {
                try {
                    return eClassifierInfos.getCompatibleTypeOf(classifierInfos);
                } catch (IllegalArgumentException e) {
                    return null;
                }
            }
        };
    }
    addFeature(featureName, featureTypeInfo, isMultivalue, isContainment, assignment);
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EDataType(org.eclipse.emf.ecore.EDataType) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) Collection(java.util.Collection)

Example 62 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testScopeByType2.

@SuppressWarnings("unused")
@Test
public void testScopeByType2() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 63 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testScopeByReference.

@SuppressWarnings("unused")
@Test
public void testScopeByReference() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(a, provider.getScope(details, details));
    assertEquals(a, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 64 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testPolymorphic.

@SuppressWarnings("unused")
@Test
public void testPolymorphic() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass(EClass clazz, EReference ref) {
            return c;
        }

        private IScope scope_EClass(EReference ctx, EReference ref) {
            return b;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(b, provider.getScope(details, details));
    assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 65 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class DeclarativeScopeProviderTest method testScopeByReference2.

@SuppressWarnings("unused")
@Test
public void testScopeByReference2() throws Exception {
    final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
    AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {

        private IScope scope_EClass_eSuperTypes(EClassifier clazz, EReference ref) {
            return a;
        }

        private IScope scope_EClass_eSuperTypes(EClass clazz, EReference ref) {
            return b;
        }

        private IScope scope_EClass_eSuperTypes(EReference ctx, EReference ref) {
            return c;
        }
    };
    EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
    assertEquals(a, provider.getScope(EcorePackage.eINSTANCE.getEShort(), details));
    assertEquals(b, provider.getScope(details.getEContainingClass(), details));
    assertEquals(c, provider.getScope(details, details));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IScope(org.eclipse.xtext.scoping.IScope) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)153 EClass (org.eclipse.emf.ecore.EClass)94 Test (org.junit.Test)36 EPackage (org.eclipse.emf.ecore.EPackage)32 EReference (org.eclipse.emf.ecore.EReference)22 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)16 AbstractRule (org.eclipse.xtext.AbstractRule)14 EDataType (org.eclipse.emf.ecore.EDataType)13 EObject (org.eclipse.emf.ecore.EObject)13 XtextResource (org.eclipse.xtext.resource.XtextResource)10 EAttribute (org.eclipse.emf.ecore.EAttribute)8 EEnum (org.eclipse.emf.ecore.EEnum)8 Grammar (org.eclipse.xtext.Grammar)8 ParserRule (org.eclipse.xtext.ParserRule)8 ArrayList (java.util.ArrayList)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Assignment (org.eclipse.xtext.Assignment)7 IScope (org.eclipse.xtext.scoping.IScope)6 HashSet (java.util.HashSet)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5