Search in sources :

Example 16 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_04.

@Test
public void testGetCompatibleType_04() {
    EDataType aString = createEDataType("a", String.class);
    EDataType anotherString = createEDataType("b", String.class);
    assertSame(aString, EcoreUtil2.getCompatibleType(aString, anotherString));
    assertSame(anotherString, EcoreUtil2.getCompatibleType(anotherString, aString));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Example 17 with EDataType

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

the class EcoreUtil2Test method testGetCompatibleType_03.

@Test
public void testGetCompatibleType_03() {
    EDataType aCharSequence = createEDataType("a", CharSequence.class);
    EDataType anAppendable = createEDataType("b", Appendable.class);
    assertSame(null, EcoreUtil2.getCompatibleType(aCharSequence, anAppendable, null));
    assertSame(null, EcoreUtil2.getCompatibleType(anAppendable, aCharSequence, null));
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) Test(org.junit.Test)

Example 18 with EDataType

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

the class EcoreUtil2Test method createEDataType.

private EDataType createEDataType(String name, Class<?> instanceClass) {
    EDataType result = EcoreFactory.eINSTANCE.createEDataType();
    result.setName(name);
    result.setInstanceClass(instanceClass);
    return result;
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType)

Example 19 with EDataType

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

the class NodeModelBasedRegionAccessBuilder method isEObjectRoot.

protected boolean isEObjectRoot(INode node) {
    if (node instanceof ICompositeNode) {
        ICompositeNode parent = node.getParent();
        while (parent != null && GrammarUtil.isEObjectFragmentRuleCall(parent.getGrammarElement())) parent = parent.getParent();
        if (parent == null)
            return true;
        INode root = parent;
        while (root != null && !root.hasDirectSemanticElement()) root = root.getParent();
        if (root == null)
            return false;
        EObject element = node.getGrammarElement();
        if (GrammarUtil.isEObjectRuleCall(element) && !GrammarUtil.isEObjectFragmentRuleCall(element)) {
            if (!parent.hasDirectSemanticElement())
                return false;
            BidiTreeIterator<INode> iterator = node.getAsTreeIterable().iterator();
            iterator.next();
            while (iterator.hasNext()) {
                INode next = iterator.next();
                if (next.hasDirectSemanticElement())
                    return true;
                EObject ge = next.getGrammarElement();
                if (ge instanceof Action)
                    return true;
                if (ge instanceof RuleCall && GrammarUtil.isAssigned(ge) && ((RuleCall) ge).getRule().getType().getClassifier() instanceof EDataType)
                    return true;
                if (ge instanceof CrossReference)
                    return true;
            }
        }
        if (element instanceof Action) {
            return parent.hasDirectSemanticElement();
        }
    }
    return false;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Action(org.eclipse.xtext.Action) EDataType(org.eclipse.emf.ecore.EDataType) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) CrossReference(org.eclipse.xtext.CrossReference) RuleCall(org.eclipse.xtext.RuleCall)

Example 20 with EDataType

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

the class Xtext2EcoreTransformer method deriveTypeHierarchyFromOverridden.

private boolean deriveTypeHierarchyFromOverridden(ParserRule rule, Grammar grammar) throws TransformationException {
    AbstractRule parentRule = GrammarUtil.findRuleForName(grammar, rule.getName());
    if (parentRule != null) {
        if (parentRule != rule && parentRule instanceof ParserRule) {
            ParserRule casted = (ParserRule) parentRule;
            if (casted.isFragment() != rule.isFragment()) {
                if (rule.isFragment()) {
                    throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride, "A fragment rule cannot override a production rule.", rule);
                } else {
                    throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride, "Only fragment rule can override other fragment rules.", rule);
                }
            }
            if (casted.isWildcard() != rule.isWildcard()) {
                if (rule.isWildcard()) {
                    throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride, "A wildcard fragment rule cannot override a typed fragment rule.", rule);
                } else {
                    throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride, "Only wildcard fragment rules can override other wildcard fragments.", rule);
                }
            }
            if (rule.isFragment() && !rule.isWildcard() && parentRule.getType() != null) {
                if (rule.getType().getClassifier() != parentRule.getType().getClassifier()) {
                    throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride, "Overriding fragment rules cannot redeclare their type.", rule.getType());
                }
            }
            checkParameterLists(rule, casted);
        }
        if (parentRule.getType() != null && parentRule != rule) {
            if (parentRule.getType().getClassifier() instanceof EDataType)
                throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot inherit from datatype rule and return another type.", rule.getType());
            EClassifierInfo parentTypeInfo = eClassifierInfos.getInfoOrNull(parentRule.getType());
            if (parentTypeInfo == null)
                throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot determine return type of overridden rule.", rule.getType());
            addSuperType(rule, rule.getType(), parentTypeInfo);
            return true;
        }
    }
    return false;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) EDataType(org.eclipse.emf.ecore.EDataType) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

EDataType (org.eclipse.emf.ecore.EDataType)25 Test (org.junit.Test)10 EObject (org.eclipse.emf.ecore.EObject)8 EClassifier (org.eclipse.emf.ecore.EClassifier)7 EClass (org.eclipse.emf.ecore.EClass)5 EAttribute (org.eclipse.emf.ecore.EAttribute)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 ArrayList (java.util.ArrayList)2 EPackage (org.eclipse.emf.ecore.EPackage)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 Grammar (org.eclipse.xtext.Grammar)2 RuleCall (org.eclipse.xtext.RuleCall)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Collection (java.util.Collection)1 List (java.util.List)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 URI (org.eclipse.emf.common.util.URI)1 EEnum (org.eclipse.emf.ecore.EEnum)1 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)1