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));
}
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));
}
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;
}
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;
}
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;
}
Aggregations