Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom Types(How to create built in types)
Custom Types [message #882117] Tue, 05 June 2012 22:10 Go to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
So language I've been implementing needs built-in types like say 'char' type in Java. Where do I add those types and how? Is there a tutorial that explains this in detail? I found some answers on this forum but the links are outdated.
Re: Custom Types [message #882247 is a reply to message #882117] Wed, 06 June 2012 05:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

this depends on how your language works (is the user allowed to define such types himself?). one possibility
is to hardcode them in the grammar e.g. using an enum.
another possibility is to ship a libary model that has the included in the model somehow e.g. by putting
a jar on the classpath see http://blogs.itemis.de/stundzig/archives/795 for some hints.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #882251 is a reply to message #882247] Wed, 06 June 2012 05:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: may http://www.eclipse.org/forums/index.php/mv/msg/351930/872243/#msg_872243 helps too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #883104 is a reply to message #882251] Thu, 07 June 2012 21:19 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
Yeah, sorry about vagueness. Idea is that the DSL has both built in types and user defined. So yeah that helped me a lot, but I'm not sure what adding that project as a dependency means.

Anyway in the old Xtext I have something like this:
create Package p createBuildInTypes():
	p.setName("types") ->
	p.packageElements.add(createString())->
;

create BuildInDataType d createString():d.setName("string");


What would be the Xtext 2 equivalent of that?
Re: Custom Types [message #883114 is a reply to message #883104] Thu, 07 June 2012 21:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

at which place did you use that in the old xtext`
with dependeny i mean e.g. a libary module (jar)
that contains a builtin.yourdsl file.


~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 07 June 2012 21:44]

Report message to a moderator

Re: Custom Types [message #883124 is a reply to message #883114] Thu, 07 June 2012 21:56 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
Ok I tried to use the URI import but it doesn't seem to work.

The ImportUriGlobalScopeProvider I made like this:


import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider;

public class DOMMLiteGlobalScopeProvider extends ImportUriGlobalScopeProvider  {

	@Override
	protected LinkedHashSet<URI> getImportedUris(Resource resource) {
		LinkedHashSet<URI> temp =  super.getImportedUris(resource);
		temp.add(URI.createURI("classpath:/builtin.domm"));
				
		return temp;
	}

	

}

But this doesn't seem to work. That tutorial says to modify AbstractDOMMLiteRuntimeModlue, but that is src-gen, which means it would get overwritten with a change. So I am still unsure how to procede...

[Updated on: Fri, 08 June 2012 18:02]

Report message to a moderator

Re: Custom Types [message #883528 is a reply to message #883124] Fri, 08 June 2012 18:03 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
I updated my previous message.
Re: Custom Types [message #883534 is a reply to message #883528] Fri, 08 June 2012 18:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

do you use import uri based scoping at all?
and which damn tutorial tells to modify the abstract one and not the one subclassing the abstactone (MydslRuntimeModule)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 08 June 2012 18:24]

Report message to a moderator

Re: Custom Types [message #883550 is a reply to message #883534] Fri, 08 June 2012 19:12 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
My model doesn't allow import other than the built in types. However there are also some custom validators and tagTypes that are hard to implement using enums.

I meant this tutorial: blogs.itemis.de/stundzig/archives/795 one you linked in your first response.

So if I understood you correctly. I made a .jar file containing 'builtin.domm' file. I added that file to buildpath (I assume that will make it available for the project I'm building). In it it clearly states:

Quote:
You could make this change known analogous to the way the ImportUriGlobalScopeProvider is bound in the AbstractXRuntimeModule


AbstractXRuntimeModule is src-gen and not src. Just to be sure I tried to add DOMMLiteGlobalScopeProvider to DOMMLiteRuntimeModule like this:
public class DOMMLiteRuntimeModule extends ftn.danielfath.AbstractDOMMLiteRuntimeModule {
	@Override
	public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
	  binder.bind(org.eclipse.xtext.scoping.IGlobalScopeProvider.class).
	  annotatedWith(com.google.inject.name.Names.named(
	  "org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.delegate"
	  )).to(DOMMLiteGlobalScopeProvider.class);}
}


Which caused an error:
!MESSAGE A conflict occurred for CTRL+O:
Binding(CTRL+O,
	ParameterizedCommand(Command(org.eclipse.graphiti.ui.internal.action.SaveImageAction,Export Diagram,
		Export Diagram,
		Category(org.eclipse.graphiti.ui.Graphiti_Category,Edit,Graphiti Diagram Editor,true),
		,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.ui.contexts.window,,,system)
Binding(CTRL+O,
	ParameterizedCommand(Command(org.eclipse.papyrus.sysml.modelexplorer.FlowPort_OutCreateCommand,Create a new FlowPort_Out,
		Create a new FlowPort_Out,
		Category(org.eclipse.papyrus.editor.category,Papyrus Category,this a category of papyrus commands,true),
		org.eclipse.papyrus.sysml.modelexplorer.handler.FlowPort_OutHandler,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.ui.contexts.window,,,system)

but then the editor was all messed up.

[Updated on: Fri, 08 June 2012 19:22]

Report message to a moderator

Re: Custom Types [message #883554 is a reply to message #883550] Fri, 08 June 2012 19:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

Strange Things you do. what the blog post says:

go to the runtime module and create a binding ANALGOUS to the one in the AbstractRuntimememodule.
so what do you have regarding your IGlobalScopeProvider in your abstract runtimemodule?

i have something like

	public Class<? extends org.eclipse.xtext.scoping.IGlobalScopeProvider> bindIGlobalScopeProvider() {
		return org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider.class;
	}

	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(org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.class);
	}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 08 June 2012 19:36]

Report message to a moderator

Re: Custom Types [message #883556 is a reply to message #883554] Fri, 08 June 2012 19:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
P.S: the error you posted is not at all Xtext related

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #883701 is a reply to message #883554] Sat, 09 June 2012 05:40 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
What confused me was that blog says this:

You could make this change known analogous to the way the ImportUriGlobalScopeProvider is bound in the AbstractXRuntimeModule

@Override
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.delegate
  )).to(MyImportUriGlobalScopeProvider.class);
}


Anyway that change removed any compilation problem but the model cannot be imported still. How can I verify it is on the classpath?
Re: Custom Types [message #883704 is a reply to message #883701] Sat, 09 June 2012 05:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Check

(1) did you configure the import uri scoping at all(Post the workflow arround the scoping fragments)
(2) use the debugger
(3) post your special globsl scopeprovider

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #883807 is a reply to message #883704] Sat, 09 June 2012 12:49 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
1. I'm not sure. Check out bitbucket.org/DanielFath/masterthesis there should be an option to view files. I'm not sure what does posting the workflow around the scoping fragments means.

package ftn.danielfath.scoping;

import java.util.LinkedHashSet;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider;

public class DOMMLiteGlobalScopeProvider extends ImportUriGlobalScopeProvider  {

	@Override
	protected LinkedHashSet<URI> getImportedUris(Resource resource) {
		LinkedHashSet<URI> temp =  super.getImportedUris(resource);
		temp.add(URI.createURI("classpath:/builtin.domm"));
				
		return temp;
	}

	

}

Re: Custom Types [message #883816 is a reply to message #883807] Sat, 09 June 2012 13:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
And did you add the builtin lib to the classpath of the model file?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #884295 is a reply to message #883816] Sun, 10 June 2012 18:42 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
Quote:
And did you add the builtin lib to the classpath of the model file?

I think I did, but could you elaborate more on this step. Is the screen that?
  • Attachment: screen.png
    (Size: 87.04KB, Downloaded 125 times)

[Updated on: Sun, 10 June 2012 18:52]

Report message to a moderator

Re: Custom Types [message #884298 is a reply to message #884295] Sun, 10 June 2012 18:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

just make sure the jar containing the builtin.mydsl is contained in the (java) classpath of the project the test.mydsl file is contained.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Custom Types [message #884350 is a reply to message #884298] Sun, 10 June 2012 22:17 Go to previous messageGo to next message
Daniel Fath is currently offline Daniel FathFriend
Messages: 14
Registered: March 2012
Junior Member
Hi and thanks for help.

I figured out a way for it to work. If I comment out the global scope provider and just keep the local one, adding the jar to classpath of my test project will result in correct behavior. It's obvious that the global scope is the cause of problems.

Currently I need to add the mydsl.jar manually. Is there a way to auto-include mydsl.jar into my projects?

[Updated on: Sun, 10 June 2012 22:17]

Report message to a moderator

Re: Custom Types [message #884714 is a reply to message #884350] Mon, 11 June 2012 16:50 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
see the other forum topic i mentioned earlier

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Naming and Containment Hierarchy Issue
Next Topic:Problems with referencing ecore's
Goto Forum:
  


Current Time: Fri Mar 29 06:42:05 GMT 2024

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

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

Back to the top