I have used Xtext for many years, and have always been able to cross-reference from one grammar to another grammar. But today, on Eclipse Photon, the usual method no longer works.
In the same workspace, I create two Xtext projects, using default options, org.xtext.example.adsl.ADsl
grammar org.xtext.example.adsl.ADsl with org.eclipse.xtext.common.Terminals
generate aDsl "http://www.xtext.org/example/adsl/ADsl"
AModel:
agreetings+=AGreeting*;
AGreeting:
'AHello' name=ID '!';
and org.xtext.example.bdsl.BDsl
,
grammar org.xtext.example.bdsl.BDsl with org.eclipse.xtext.common.Terminals
generate bDsl "http://www.xtext.org/example/bdsl/BDsl"
//import "http://www.xtext.org/example/adsl/ADsl" as adsl
ModelB:
bgreetings+=BGreeting*;
BGreeting:
'BHello' name=ID '!';
where BDsl
would like to import ADsl
via the commented-out import statement import "http://www.xtext.org/example/adsl/ADsl" as adsl
for use in cross-referencing.
In the past, before uncommenting that import, I would have to add a resource reference referencedResource = "../org.xtext.example.adsl/model/generated/ADsl.genmodel"
to GenerateBDsl.mwe2
.
module org.xtext.example.bdsl.GenerateBDsl
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "org.xtext.example.bdsl"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "UTF-8"
lineDelimiter = "\n"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "org.xtext.example.bdsl.BDsl"
referencedResource = "../org.xtext.example.adsl/model/generated/ADsl.genmodel"
fileExtensions = "bdsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}
But when I generate the Xtext artifacts for BDsl
, I now get the following error (the import still commented out).
434 [main] ERROR xt.generator.XtextGeneratorLanguage - Error loading 'ADsl.ecore'
The genmodel is certainly being found, since a completely different error is generated if the file cannot be found.
What is going on?
[... I am aware that the example contains no actual cross-references. I have purposely induced the error in the simplest possible manner. ...]
make sure you refer to the referenced genmodel in a way that it actually can be insolved. the ususal reference would look like platform:/resource/project/model/Some.genmodel
so in your case referencedResource = "platform:/resource/org.xtext.example.adsl/model/generated/ADsl.genmodel"