Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Custom Types(How to create built in types)
Custom Types [message #882117] Tue, 05 June 2012 18:10 Go to next message
Eclipse UserFriend
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 01:48 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Custom Types [message #882251 is a reply to message #882247] Wed, 06 June 2012 01:54 Go to previous messageGo to next message
Eclipse UserFriend
P.S: may http://www.eclipse.org/forums/index.php/mv/msg/351930/872243/#msg_872243 helps too
Re: Custom Types [message #883104 is a reply to message #882251] Thu, 07 June 2012 17:19 Go to previous messageGo to next message
Eclipse UserFriend
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 17:41 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Thu, 07 June 2012 17:44] by Moderator

Re: Custom Types [message #883124 is a reply to message #883114] Thu, 07 June 2012 17:56 Go to previous messageGo to next message
Eclipse UserFriend
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 14:02] by Moderator

Re: Custom Types [message #883528 is a reply to message #883124] Fri, 08 June 2012 14:03 Go to previous messageGo to next message
Eclipse UserFriend
I updated my previous message.
Re: Custom Types [message #883534 is a reply to message #883528] Fri, 08 June 2012 14:17 Go to previous messageGo to next message
Eclipse UserFriend
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)

[Updated on: Fri, 08 June 2012 14:24] by Moderator

Re: Custom Types [message #883550 is a reply to message #883534] Fri, 08 June 2012 15:12 Go to previous messageGo to next message
Eclipse UserFriend
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 15:22] by Moderator

Re: Custom Types [message #883554 is a reply to message #883550] Fri, 08 June 2012 15:24 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Fri, 08 June 2012 15:36] by Moderator

Re: Custom Types [message #883556 is a reply to message #883554] Fri, 08 June 2012 15:29 Go to previous messageGo to next message
Eclipse UserFriend
P.S: the error you posted is not at all Xtext related
Re: Custom Types [message #883701 is a reply to message #883554] Sat, 09 June 2012 01:40 Go to previous messageGo to next message
Eclipse UserFriend
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 01:52 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Custom Types [message #883807 is a reply to message #883704] Sat, 09 June 2012 08:49 Go to previous messageGo to next message
Eclipse UserFriend
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 09:32 Go to previous messageGo to next message
Eclipse UserFriend
And did you add the builtin lib to the classpath of the model file?
Re: Custom Types [message #884295 is a reply to message #883816] Sun, 10 June 2012 14:42 Go to previous messageGo to next message
Eclipse UserFriend
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 144 times)

[Updated on: Sun, 10 June 2012 14:52] by Moderator

Re: Custom Types [message #884298 is a reply to message #884295] Sun, 10 June 2012 14:52 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Custom Types [message #884350 is a reply to message #884298] Sun, 10 June 2012 18:17 Go to previous messageGo to next message
Eclipse UserFriend
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 18:17] by Moderator

Re: Custom Types [message #884714 is a reply to message #884350] Mon, 11 June 2012 12:50 Go to previous message
Eclipse UserFriend
see the other forum topic i mentioned earlier
Previous Topic:Naming and Containment Hierarchy Issue
Next Topic:Problems with referencing ecore's
Goto Forum:
  


Current Time: Fri Jul 04 17:24:53 EDT 2025

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

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

Back to the top