I am currently working on a project where I want to create java classes and map properties from existing java classes. I got the IntelliSense working fine in Eclipse but when i save my dsl file I get an error saying "Couldn't resolve reference to JvmMember". It feels like my scope provider is working fine with the IntelliSence but whenn saving the dsl another scope provider is being used and I do not know how to fix it. I am using Xtext 2.4.2.v201306120542
My grammar looks like this.
grammar org.example.domainmodel.Domainmodel with
org.eclipse.xtext.xbase.Xbase
generate domainmodel "http_://www.example.org/domainmodel/Domainmodel"
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
Domainmodel:
importSection=XImportSection?
elements+=AbstractElement*;
AbstractElement:
PackageDeclaration | Entity ;
PackageDeclaration:
'package' name=QualifiedName '{'
elements+=AbstractElement*
'}';
Entity:
(abstract ?= 'abstract')?
'entity' name=ID ('extends' superType = [Entity])?
from = From
('properties' properties += Property)
('map' mappings += MappingDef+)?
;
From returns xbase::XVariableDeclaration:
{xbase::XVariableDeclaration}
writeable?='from' type=JvmTypeReference name=ValidID;
MappingDef:
Reference
;
Reference:
'virtual' type = [Property] '=' fromRef = [jvmTypes::JvmMember]
;
Property:
name=ValidID ':' type=JvmTypeReference
;
My dsl looks like this
import se.cambio.test.A;
package se.cambio.test.gen
{
entity PatientDto
from A a
properties
description: String
map
virtual description = getDesc
}
Where A is a plain java class with the method .
The scope provider looks like this and is making us of the depricated XbaseScopeProvider.
public class MyScopProvider extends XbaseScopeProvider {
@Override
public IScope getScope(EObject context, EReference reference) {
if (reference != null && context != null) {
if (context instanceof Reference) {
Reference ref = (Reference) context;
EObject a = ref.eContainer();
if (a instanceof Entity) {
Entity entity = (Entity) a;
XVariableDeclaration decl = entity.getFrom();
XMemberFeatureCallImplCustom e = new XMemberFeatureCallImplCustom();
JvmType type = decl.getType().getType();
if (type instanceof JvmGenericType) {
JvmGenericType genericType = (JvmGenericType) type;
EList<JvmMember> members = genericType.getMembers();
IScope s = Scopes.scopeFor(members, QualifiedName
.wrapper(SimpleAttributeResolver.newResolver(
String.class, "simpleName")),
IScope.NULLSCOPE);
return s;
}
}
}
}
return super.getScope(context, reference);
}
}
Finally I bind my scope provider in the runtime module like this
@Override
public Class<? extends IScopeProvider> bindIScopeProvider() {
return MyScopProvider.class;
}
Does anyone have any suggestions of what I am doing wrong?