Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtend and java classes for ScopeProvider and error generated code
xtend and java classes for ScopeProvider and error generated code [message #1763472] Tue, 16 May 2017 13:44 Go to next message
Fa Za is currently offline Fa ZaFriend
Messages: 245
Registered: March 2010
Senior Member
I reproduce the MyDsl grammar.
I update the the mwe workflow (see below)
After the generation I obtain two kind of errors
1- the org.xtext.example.mydsl.scoping package in src folder contains MyDslScopeProvider.java and MyDslScopeProvider.xtend. Is it normal?
2- the MyDslStandaloneSetupGenerated contains errors (see below) because Duplicate local variable resourceFactory and serviceProvider is it normal?

module org.xtext.example.mydsl.GenerateMyDsl

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.mydsl"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				eclipsePlugin = {
					enabled = true
				}
				eclipsePluginTest = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "UTF-8"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "org.xtext.example.mydsl.MyDsl"
			fileExtensions = "mydsl"

			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
			fragment = grammarAccess.GrammarAccessFragment2 auto-inject {}
			
			fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
  			 fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {}
			}
			fragment = scoping.ImportNamespacesScopingFragment2 {
    			generateStub = false
 			}
 			fragment = resourceFactory.ResourceFactoryFragment2 auto-inject {}
			
		}
	}
}



public class MyDslStandaloneSetupGenerated implements ISetup {

	@Override
	public Injector createInjectorAndDoEMFRegistration() {
		TerminalsStandaloneSetup.doSetup();

		Injector injector = createInjector();
		register(injector);
		return injector;
	}
	
	public Injector createInjector() {
		return Guice.createInjector(new MyDslRuntimeModule());
	}
	
	public void register(Injector injector) {
		if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/example/mydsl/MyDsl")) {
			EPackage.Registry.INSTANCE.put("http://www.xtext.org/example/mydsl/MyDsl", MyDslPackage.eINSTANCE);
		}
		IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
		IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
		
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mydsl", resourceFactory);
		IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("mydsl", serviceProvider);
		IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
		IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
		
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mydsl", resourceFactory);
		IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("mydsl", serviceProvider);
	}
}

[Updated on: Tue, 16 May 2017 13:46]

Report message to a moderator

Re: xtend and java classes for ScopeProvider and error generated code [message #1763474 is a reply to message #1763472] Tue, 16 May 2017 13:49 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 748
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Did you generate the DSL previously with another Xtext version? The Xtend based scope provider might be newer than your Java one. Please check timestamps.

Further i'm not sure why you configured additional fragments in the workflow. They might cuase the duplicate fields.
Re: xtend and java classes for ScopeProvider and error generated code [message #1763475 is a reply to message #1763472] Tue, 16 May 2017 13:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14078
Registered: July 2009
Senior Member
fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter {
fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {
generateXtendStub = true
}
}



There is a implicit

scopeProvider = {
generateStub = true
}

you miss (and that might interfer with bindings)

i recomment you to no to do the adapty thingy but simply
add/override the bindings manually


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtend and java classes for ScopeProvider and error generated code [message #1763477 is a reply to message #1763474] Tue, 16 May 2017 13:58 Go to previous messageGo to next message
Fa Za is currently offline Fa ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Declaring fragments isn't required to profit features like scoping, validator, etc.
Or they become configured by default?
Re: xtend and java classes for ScopeProvider and error generated code [message #1763478 is a reply to message #1763477] Tue, 16 May 2017 14:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14078
Registered: July 2009
Senior Member
no they dont but you can bind the stuff manually without any problems

e.g

override bindIGlobalScopeProvider() {
importuriglobalscopeprovider
}

override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
.to(SimpleLocalScopeProvider);

}

(as composite in wf: org.eclipse.xtext.validation.ImportUriValidator)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Issue with cyclic project dependencies
Next Topic:Problems running Maven "install" after updating Xtext to v2.11.0
Goto Forum:
  


Current Time: Mon Oct 25 18:15:36 GMT 2021

Powered by FUDForum. Page generated in 0.02201 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top