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