Error When Serializing CrossReference [message #1764212] |
Fri, 26 May 2017 17:16 |
Greg Lusk Messages: 36 Registered: February 2017 Location: USA |
Member |
|
|
I am trying to add model elements manually in a unit test. Our grammar references another grammar, which I load using a global scope provider:
private IScope getScopeWithLibrary(Resource resource, EReference reference) {
if (resourceDescriptionData == null) {
synchronized (semaphore) {
ResourceSet resourceSet = resourceSetProvider.get();
URI uri = URI.createURI("classpath:/stdlib.stext");
Resource stdlib = resourceSet.getResource(uri, true);
IResourceDescription stdlibDescription = descriptionManager.getResourceDescription(stdlib);
resourceDescriptionData = new ResourceDescriptionsData(Collections.singletonList(stdlibDescription));
}
}
return SelectableBasedScope.createScope(super.getScope(resource, reference, null), resourceDescriptionData, reference.getEReferenceType(), false);
}
Our unit test looks like this:
def void testSerialization1() {
StructuredTextFactoryImpl.init
val model = createStructuredTextModel => [
function = createFunctionBlock => [
name = "F1"
inputs = createInputsList => [
items += createVarDeclarationInit => [
typeName = Type_Name.NUMERIC
variables += createPrimaryVariable => [
name = "X"
]
]
]
outputs = createOutputsList => [
items += createVarDeclarationInit => [
typeName = Type_Name.BOOL
variables += createPrimaryVariable => [
name = "Y"
]
]
]
val var_X = inputs.items.map[variables].flatten.head
val var_Y = outputs.items.map[variables].flatten.head
statements += createAssignmentStatement => [
variables += var_Y
expression = createCall => [
func = createIntrinsicFunction => [
name = "COS"
]
args += createVariableReference => [
variable = var_X
]
]
]
]
]
val resourceSet = resourceSetProvider.get
val resource = resourceSet.createResource(URI.createURI("dummy.stext"))
resource.contents += model
val actual = resource.contents.head.serialize(SaveOptions.newBuilder().format.options)
}
But the Scope for IntrinsicFunction cross references can't be resolved when we run the test, and we get the following exception:
java.lang.RuntimeException: No EObjectDescription could be found in Scope Call.func for IntrinsicFunction'COS'
Semantic Object: StructuredTextModel.function->FunctionBlock'F1'.statements[0]->AssignmentStatement.expression->Call
URI: dummy.stext
EStructuralFeature: structuredText::Call.func
So my question is this: how to we provide the Scope for the Intrinsic Functions to the CrossReferenceSerializer? (I hope I am asking the right question here, and using the correct terminology).
This appears to be a resource description problem, but we have the following custom ResourceDescriptionStrategy in our project:
class StructuredTextResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy {
@Inject StructuredTextPackage pck
override boolean createEObjectDescriptions(EObject object, IAcceptor<IEObjectDescription> acceptor) {
switch (object.eClass) {
case pck.structuredTextModel : { return true }
case pck.intrinsicFunction : {
super.createEObjectDescriptions(object, acceptor)
return false
}
case pck.functionBlock : {
super.createEObjectDescriptions(object, acceptor)
return true
}
case pck.varDeclarationInit: {
if (object.eContainer instanceof InputsList) {
super.createEObjectDescriptions(object, acceptor)
return true
} else {
return false
}
}
case pck.unit : {
super.createEObjectDescriptions(object, acceptor)
return false
}
default: return true
}
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04534 seconds