2

For our master project at university we created multiple DSLs using Xtext. One of the DSLs is a model entity DSL which allows the user to create a class with properties and methods.

We reuse Xbase because, of course, we want the methods to have a real programming language without reinventing the wheel:

grammar … with org.eclipse.xtext.xbase.Xbase

generate …

EntityModel:
    'package' importedNamespace=QualifiedName
    …
    implementation=Entity;

Entity:
    'entity' name=ValidID '{'
        features+=Feature*
    '}';

Feature:
    LocalVariable | …;

LocalVariable:
    'var' (isStatic?='static')? name=ValidID ':' type=JvmTypeReference;

For some reason, even though the type of the LocalVariable is set to JvmTypeReference, when using String (in an actual implementation), it will always show the error

Xtext: Couldn't resolve reference to JvmType 'String'

package com.example
Entity foo {
    var bar: String
}

We already tried using a ImportedNamespaceAwareLocalScopeProvider which in getImportedNamespaceResolvers adds java.lang.* like that:

List<ImportNormalizer> implicitImports = super.getImportedNamespaceResolvers(context, ignoreCase);
List<ImportNormalizer> javaLangImports = singletonList(new ImportNormalizer(QualifiedName.create("java", "lang"), true, ignoreCase));
implicitImports.addAll(javaLangImports);
return implicitImports;

Even thought that method is called a lot of times, the imports still don't work. When inspecting the EObject context parameter, it sometimes returns java.lang.String (which I guess is for the JvmTypeReference but it still displays an error.

In the RuntimeModule the new scope provider is configured like that:

public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
    binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(MasterDSLImportedNamespaceAwareLocalScopeProvider.class);
}

In the Workflow we configured

fragment = scoping.ImportNamespacesScopingFragment {}
fragment = exporting.QualifiedNamesFragment {}
fragment = builder.BuilderIntegrationFragment {}

The rest of the project is quite complex already (4 Xtext DSLs in one project and multiple generators). But except for completely different DSLs, they use almost the same workflow and RuntimeModule configuration. Another DSL also uses JvmTypeReference and also doesn't find e.g. boolean or anything else.

The question of course is: are we doing something wrong or is there something else we have to do. It used to work when we had a significantly smaller project but after some major changes suddenly this stopped working.

thSoft
  • 21,755
  • 5
  • 88
  • 103
dst
  • 1,770
  • 13
  • 26
  • Did you put the model file into a source folder of a Java-Project? Do you use the XbaseGeneratorFragment? – Sebastian Zarnekow Feb 19 '13 at 16:28
  • The model file is in the src folder and highlighting and everything works. Also, ```fragment = xbase.XbaseGeneratorFragment {}``` and ```fragment = types.TypesGeneratorFragment {}``` is configured (I hope I didn't overwrite it somewhere?!) – dst Feb 19 '13 at 17:24
  • Did you try to use the import normalizer without the ignore-case option? – Sebastian Zarnekow Feb 21 '13 at 22:25
  • I just tried that and using ignoreCase=true makes no difference :( I guess I will have to re-create all projects and incrementally add all the features and try to find out when the problem occurs for the first time… Thanks for your help! If you have some more suggestions I would appreciate it if you could post them! – dst Feb 22 '13 at 16:50
  • I take from you comment that you tried ignoreCase = false, too? Unfortunately I cannot provide other hints without a reproducable test case. – Sebastian Zarnekow Feb 23 '13 at 14:10
  • I tried both (false was the default anyways). – dst Feb 24 '13 at 09:25
  • Did you added xtend/xbase runtime to the classpath of your dsl project? – Boris Brodski Mar 17 '13 at 19:11
  • 3
    I did. I found the problem elsewhere. Will answer the question as soon as I have time. – dst Mar 17 '13 at 19:17
  • 4
    pls do let us know how you solved it – HaveAGuess May 30 '13 at 13:31
  • @alopix in case you're still alive, could you tell us how you fixed it? – Kirill Rakhman Jul 25 '15 at 12:06
  • @cypressious I'm sorry, haven't worked on this after finishing the master project 2 years ago. Don't really remember what we chanced in order to get it working again – dst Jul 29 '15 at 11:39

0 Answers0