Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » UML scope
UML scope [message #635597] Wed, 27 October 2010 13:21 Go to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi,

I've been using Xtext for a short time (almost a month), and now I started dealing with scopes.

I've already took a look at:
http://blog.efftinge.de/2009/07/xtext-scopes-and-emf-index-i n-action.html
http://blog.efftinge.de/2009/01/xtext-scopes-and-emf-index.h tml

I intend to referece a UML model (i.e. using 'import') and use some of the elements within the scope.

Would that be possible if I write my own scope provider?

Thanks for any help,
Roque Pinel.
Re: UML scope [message #635625 is a reply to message #635597] Wed, 27 October 2010 14:41 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
(You can essentially forget about EMF Index, as knowing about scoping is for the moment.)

That would be certainly possible using a custom scope provider, but it should already be possible using the ImportURIScopingFragment: search for that in the User Guide.


Re: UML scope [message #635923 is a reply to message #635625] Thu, 28 October 2010 15:43 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi Meinte.

In order to test the element import, I wrote a small grammar.

Document:
	(imports+=Import)*;

Import:
	'import' model=STRING;


Than I wrote a scope provider for the import.

public class LangScopeProvider extends AbstractDeclarativeScopeProvider {

	IScope scope_Import(Import ctx, EReference ref) {

		System.out.println("Import " + ctx.getModel());

		return null;
	}
}


However, I wasn't able to test the scope provider. Do I need to add the class 'LangScopeProvider' in the Workflow?
Re: UML scope [message #636061 is a reply to message #635923] Fri, 29 October 2010 08:31 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
No, this class should already be bound in the LangRuntimeModule class as the local scope provider. However, it's unlikely that it's going to work in this way: please read the sections in the User Guide pertaining to scoping a little closer to get a good understanding and/or see my blogs for a few tips/tricks.

Re: UML scope [message #636121 is a reply to message #636061] Fri, 29 October 2010 12:09 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi Meinte, thanks for the reply.

I hadn't found your blog in my previous research, but now I'll take a look.

BTW, I found some posts talking about UML and Xtext:

http://chilifreak.wordpress.com/2009/11/06/xtext-using-uml-m odels/
http://www.eclipse.org/forums/index.php?t=tree&th=18269& amp; amp;
http://www.virage-it.be/2010/05/the-definition-and-the-imple mentation-of-the-software-analysis-dsl-using-xtext/

But I still trying to figure out how to adapt to my purpose (It uses a older version of Xtext). It seems that I can import a UML specification into the grammar and use cross-reference for the elements of the model. However, when I try to run the workflow the import doesn't work.

The grammar:
grammar org.reusetool.rdl.RDL with org.eclipse.xtext.common.Terminals

generate rdl "http://www.reusetool.org/rdl/RDL"

import "http://www.eclipse.org/uml2/3.0.0/UML" as uml

Document:
	(imports+=Import)*
	(cookbook+=Element)*;

Import:
	'import' importURI=STRING;

Element:
	'Class' class=[uml::Class];



Have anyone use UML before?

Thanks for any help,
Roque.

[Updated on: Fri, 29 October 2010 12:10]

Report message to a moderator

Re: UML scope [message #636254 is a reply to message #636121] Fri, 29 October 2010 21:18 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Which version of Xtext are you using? With Xtext 1.0.0. it is a little different. You'll need to implement some java classes - I'll blog in a few days about it if you can wait.
Re: UML scope [message #636255 is a reply to message #636254] Fri, 29 October 2010 21:26 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi Andreas,

I'm using the Xtext 1.0.1.

I also reply another post, where you can find more informations about my issue.

http://www.eclipse.org/forums/index.php?t=msg&th=18269&a mp;S=980bea630db4d37259978a91f99a242d#msg_636247

Thanks for the reply/help, I'm looking forward to seeing your post.
Re: UML scope [message #636380 is a reply to message #636255] Sun, 31 October 2010 21:42 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Here it is, hope this helps: http://5ise.quanxinquanyi.de/2010/10/31/xtext-1-0-0-and-uml- xpand-on-top/
Re: UML scope [message #636381 is a reply to message #636380] Sun, 31 October 2010 21:52 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Thanks Andreas! I'll just test and post the results Smile
Re: UML scope [message #636382 is a reply to message #636381] Sun, 31 October 2010 22:07 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
It worked smoothly Smile

Thank you very much for the help.
Re: UML scope [message #642117 is a reply to message #636380] Mon, 29 November 2010 22:25 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi Andreas,

I've gotten another problem... I'd like to reference elements from the UML model and variables defined in my grammar. Something like:

import 'http://www.eclipse.org/uml2/3.0.0/UML' as umlMM

IdClass:
referencedClass=[umlMM::Class] | [Variable];

Assignment:
Variable EQUALS expression=Expression;

Variable:
name=ID;

Expression:
Add_Code;

Add_Code:
'ADD_CODE' '(' varClass=IdClass ')';


Have you had a similar problem?

Thanks for the help
Re: UML scope [message #642167 is a reply to message #642117] Tue, 30 November 2010 08:32 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
I'm not sure what you want to do. Can you provide a mock-up, i.e. a sample DSL exhibiting the behavior you want?

Re: UML scope [message #642341 is a reply to message #642167] Tue, 30 November 2010 20:46 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi Meinte,

The following codes may clarify my intention.

My grammar:
grammar org.reusetool.rdl.RDL with org.eclipse.xtext.common.Terminals

generate rdl "http://www.reusetool.org/rdl/RDL"

import 'http://www.eclipse.org/uml2/3.0.0/UML' as umlMM

Document:
	(imports+=Import)*
	(cookbook+=Cookbook)*;

terminal SEMICOL: ';';
terminal COMMA: ',';
terminal EQUALS: '=';

terminal DOT: '.';

Qualified_ID:
	ID (DOT ID)*;

Import:
	'import' importURI=STRING;

Cookbook:
	'COOKBOOK' name=ID
		(recipes+=Recipe)+
	'END_COOKBOOK';

Recipe:
	'RECIPE' name=ID '{'
		(statements+=Statement)*
	'}';

Statement:
	Assignment SEMICOL |
	Expression SEMICOL;

Assignment:
	var=Variable EQUALS expression=Expression;

Variable:
	name=ID;

MyClass:
	referencedClass=[umlMM::Class] | t=[Variable];

Expression:
	Class_Extension;

Class_Extension:
	'CLASS_EXTENSION' '(' superID=MyClass COMMA subPackID=[umlMM::Package] COMMA sub=STRING ')';


Code sample (what I aim to do):
(1) import "model/shapes.uml"
(2)
(3) COOKBOOK Teste
(4)	RECIPE main {
(5)		req = CLASS_EXTENSION(Shape, figure, "Rectangle");
(6)		sqr = CLASS_EXTENSION(req, figure, "Square");
(7)	}
(8) END_COOKBOOK


The grammar accepts the code in line (5), but not in (6). The goal is to use this code to generate a new model as described by the language.

Do you know if it possible to describe the previous case as suggested?

Thanks for any reply!




Re: UML scope [message #642421 is a reply to message #642341] Wed, 01 December 2010 09:31 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Ah, your grammar is ambiguous in the MyClass rule: both alternatives consume the same token (ID), so the underlying parser generator will complain (those red error messages) about overlapping rules and pick a subset of the alternatives which don't overlap: in this case it picks the reference to a UML class which is why line 6 wasn't accepted as the parser never tries the Variable reference alternative.

The easiest way to fix this is to introduce a convenience super type, like so:
Referable: umlMM::Class | Variable;

And refer directly to this:
MyClass:
	ref=[Referable];



Re: UML scope [message #642427 is a reply to message #642421] Wed, 01 December 2010 09:55 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
I tried a bunch of alternatives, but I skipped this one.

Is it possible to use the "umlMM::Class" without the brackets? I'm getting that errors:

no viable alternative at input 'umlMM'
Couldn't resolve reference to AbstractRule 'Class'


With you, was the grammar parsed successfully?
Re: UML scope [message #642434 is a reply to message #642427] Wed, 01 December 2010 10:36 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Yes, my grammar parsed correctly (obviously, as I wouldn't paste it here otherwise). Having your grammar parsed is not enough: the parser generator also shouldn't produce any errors/warnings -that's what I've been trying to tell you.


Re: UML scope [message #642452 is a reply to message #642434] Wed, 01 December 2010 12:35 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Seriously, I wasn't doubting about your solution. I just had the intention to show a strange behavior. I got those messages through syntax analyzer.

I intend to try harder when I get home. Thank you for the replies.
Re: UML scope [message #642614 is a reply to message #642452] Thu, 02 December 2010 01:08 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
I really don't know the difference betweem ours project.

When I try the following code, I get "umlMM::Class" highlighted in red.

Referable: umlMM::Class | Variable;

MyClass:
	ref=[Referable];


Then I found another post that gave an ideia: http://www.eclipse.org/forums/index.php?t=msg&th=165990

Referable: ref=[umlMM::Class] | ref=[Variable];

MyClass:
	ref=[Referable];


But it also didn't work Sad
Re: UML scope [message #642655 is a reply to message #642614] Thu, 02 December 2010 08:43 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Oh, hang on: I couldn't get the import of the UML mm to work, so I cheated and created a substitute in the grammar itself, so that's why it works with me. Apologies for having caused confusion like that!

The reason it doesn't work with an external type is that "X : ext::A | B" means that X should be made a super type of ext::A which is sealed because it's an import.

The easiest solution would be Sebastian's suggestion in the thread you mention: cross-reference to EObject and use the scope provider (and validation) to limit the possibilities. This should work as both umlMM::Class and Variable are EObjects.


Previous Topic:how to add the xtextEditor in the MultiPageEditor.
Next Topic:Custom Validator
Goto Forum:
  


Current Time: Thu Apr 25 23:49:26 GMT 2024

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

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

Back to the top