Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Disable some commands from Xbase library
Disable some commands from Xbase library [message #1422800] Sat, 13 September 2014 11:47 Go to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
Hi,

I would like to know if is there the possibility to exclude some inherited command from xbase?
For example i would like to gain the possibility to user to use only System.out.println instead of println (from InputOutput library). Or for example to avoid use of var and val.
I'm thinking to write some validation rule for displaying an alert. I don't like this way because with the Eclipse's autocompletion i have always this possibility. Others ways?

Moreover, when i translate my method main (from my grammar) into the java main with "inferr", i have this output:

public static void main(final String... args) {
}


I would like some like this:

public static void main(String[] args) {
}


Is it possible? I'm using this code:
members += elem.toMethod(elem.name, elem.type ?: inferredType) [
								parameters += elem.toParameter("args",  model.newTypeRef(typeof(String)).addArrayTypeDimension())
								static = true
        						varArgs = true													
								body = elem.body
							]

Thanks in advance
Re: Disable some commands from Xbase library [message #1423543 is a reply to message #1422800] Sun, 14 September 2014 16:26 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Daniele,

please find the answers inline.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 13.09.14 13:47, schrieb Daniele P.:
> Hi,
>
> I would like to know if is there the possibility to exclude some
> inherited command from xbase? For example i would like to gain the
> possibility to user to use only System.out.println instead of println
> (from InputOutput library). Or for example to avoid use of var and val.
> I'm thinking to write some validation rule for displaying an alert. I
> don't like this way because with the Eclipse's autocompletion i have
> always this possibility. Others ways?

Override ImplicitlyImportedFeatures and return only a subset from
getStaticImportClasses.

>
> Moreover, when i translate my method main (from my grammar) into the
> java main with "inferr", i have this output:
>
>
> public static void main(final String... args) {
> }
>
>
> I would like some like this:
>
>
> public static void main(String[] args) {
> }
>
>
> Is it possible? I'm using this code:
> members += elem.toMethod(elem.name, elem.type ?: inferredType) [
> parameters += elem.toParameter("args",
> model.newTypeRef(typeof(String)).addArrayTypeDimension())
> static = true
> varArgs = true
> body = elem.body
> ]

you can use varArgs = false instead of true and it'll yield a method
without vararg support.

> Thanks in advance
Re: Disable some commands from Xbase library [message #1425753 is a reply to message #1423543] Wed, 17 September 2014 19:57 Go to previous messageGo to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
Thanks for your answer.

"Override ImplicitlyImportedFeatures and return only a subset from getStaticImportClasses"

Can you make me an example? I didn't find anyone tutorial about it and i don't know how to start or proceed.


Moreover i have a problem with variable declaration. In JVM Inferr, when i translate my grammar in a java code, how can i create an array?

I would like convert my variables declaration (from my grammar) in a correct java array.
At the moment i use this grammar:

Variabili:
type = JvmTypeReference name=ID ((array ?='[' (lenght=INT)? ']')?)|(('=' init=XExpression)?) ';'
;

If i use init i don't have problem, but if i use array i don't know how to convert into the java code
Thanks in advance
Re: Disable some commands from Xbase library [message #1426064 is a reply to message #1425753] Thu, 18 September 2014 07:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Daniele,

please refer to the documentation on dependency injection in Xtext for
details on how to override the ImplicitlyImportedFeatures.
Basically you'll have to create a subtype of ImplicitlyImportedFeatures
and override the methods as you like. This subtype has to be registered
in the runtime module of your language.

I guess I don't understand the second question 'How to create an array'.
Did you try to set the body / initializer of your infered field / method
to something like this:

jvmField.initializer = '''new «v.type»[«v.length»];'''

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 17.09.14 21:57, schrieb Daniele P.:
> Thanks for your answer.
>
> "Override ImplicitlyImportedFeatures and return only a subset from
> getStaticImportClasses"
>
> Can you make me an example? I didn't find anyone tutorial about it and i
> don't know how to start or proceed.
>
>
> Moreover i have a problem with variable declaration. In JVM Inferr, when
> i translate my grammar in a java code, how can i create an array?
>
> I would like convert my variables declaration (from my grammar) in a
> correct java array.
> At the moment i use this grammar:
>
> Variabili:
> type = JvmTypeReference name=ID ((array ?='[' (lenght=INT)?
> ']')?)|(('=' init=XExpression)?) ';'
> ;
>
> If i use init i don't have problem, but if i use array i don't know how
> to convert into the java code
> Thanks in advance
Re: Disable some commands from Xbase library [message #1426377 is a reply to message #1426064] Thu, 18 September 2014 17:00 Go to previous messageGo to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
Thank you very much.
Now the array declaration its work.
I extended "ImplicitlyImportedFeatures" with this code but it doesn't work:

@Override
public List<JvmType> getExtensionClasses(Resource context) 
{		
	List<Class<?>> classes = getExtensionClasses();
	for(int i = 0; i < classes.size(); i++)
	{
		if(classes.get(i).toString().compareTo("var") == 0)
		{
			classes.remove(i);
		}
	}
	return getTypes(classes, context);
}


How can debug this code? Breakpoint seems not to work.

Moreover, i would like to implement a sort of get(int i) for my array. How can i do that?
Re: Disable some commands from Xbase library [message #1426389 is a reply to message #1426377] Thu, 18 September 2014 17:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

the var keyword cannot be disabled that way


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable some commands from Xbase library [message #1428175 is a reply to message #1426389] Sun, 21 September 2014 11:42 Go to previous messageGo to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
Hi, i would like to insert in "XBlockExpression" the possibility to define variable in a java-like form.
I have defined the variables declaration, in my grammar in this way:

Variable:
	type = JvmTypeReference name=ID  ((array ?='[' (lenght=INT)? ']')?)|(('=' init=XExpression)?) ';'	
;


After this, i have defined the JvmInferr for transcoding into a java class and the validation plan to avoid error.

I would like to remove the var and val declaration, but i don't know how. Moreover i would like to inject my variable declaration in a XBlockExpression.
Can you help me to understand how resolve this problems?
Re: Disable some commands from Xbase library [message #1428260 is a reply to message #1428175] Sun, 21 September 2014 14:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
hi,

you can always override rules from the superclass to add or remove things (e.g. like other rule calls)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to add XText editor in an RCP application
Next Topic:How to make DSL editor distinguish between EAttribute and EReference
Goto Forum:
  


Current Time: Fri Sep 20 14:38:33 GMT 2024

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

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

Back to the top