Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Working with array with Xtext pre-defined Java types
[Xtext] Working with array with Xtext pre-defined Java types [message #666648] Thu, 21 April 2011 13:06 Go to next message
Andrea Santi is currently offline Andrea SantiFriend
Messages: 12
Registered: April 2011
Junior Member
Hi all,

in my grammar I would like to re-use the Java types, so I'm following the istruction reported here . This solution seems not to work with arrays (ex. int[] java.util.Date[]).

I would like to have also support to array types, what is the best way for doing this suing the type support provided by xtext (I have to parse the '[]' and then handle the new type as an array?)?

Even good links to existing documentation will be fine. Indeed I'm having a look also here where it seems that different production are used and not only JvmType... the standard xtext documentation is really poor, a more comprehensive explanation will be really helpfull.

Many thanks.


EDIT: Same things witìh the generics.... are they supported by xtext?

[Updated on: Thu, 21 April 2011 13:21]

Report message to a moderator

Re: [Xtext] Working with array with Xtext pre-defined Java types [message #666659 is a reply to message #666648] Thu, 21 April 2011 13:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

isn't the cardinality something you should specify in your grammar? I'd do something like

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	elements+=Element*;
	
Element:
	'element' name=ID 'mapsto' ref=TypeRef;
	
TypeRef:
	type=[types::JvmType|FQN] (isArray?="[]")?
;

FQN: ID ("." ID)*;



~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext] Working with array with Xtext pre-defined Java types [message #666668 is a reply to message #666659] Thu, 21 April 2011 13:59 Go to previous messageGo to next message
Andrea Santi is currently offline Andrea SantiFriend
Messages: 12
Registered: April 2011
Junior Member
Hi, yes I can do in that way. So I will have the information about the type, plus the flag that says if that type is an array or not. But what about JvmArrayType that I just found in the xtext JavaVMTypes? What is this, when is supposed to be used?


PS. what about generics? Even for them you use a "trick" like the one used for the array? I was expecting that both arrays and generic were handled by the JavaVMTypes grammar, but maybe that is not the case.

Many thanks for the help.

EDIT: Probably are just problems related to my lack of knowledge about the use of JavaVMTypes. Does exists any good document/example that explains how to use it?

[Updated on: Thu, 21 April 2011 14:11]

Report message to a moderator

Re: [Xtext] Working with array with Xtext pre-defined Java types [message #666674 is a reply to message #666668] Thu, 21 April 2011 14:20 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

The Problem is that these arrays do not exist as "declared" types but just live e.g. in the deeps of a class. this is why the ArrayTypes are not visible from the outside. (by default)

e.g. if you have
package model;

import java.util.List;

public class Test {
	
	public List<String>[] test;

}


then test has a member of type JvmField that has a type of JvmGenericArrayTypeReference that has a Type of JvmArrayType.

~Christian


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

[Updated on: Thu, 21 April 2011 14:40]

Report message to a moderator

Previous Topic:preferences Initialization
Next Topic:[xtext 2] Problem with QualifiedNames
Goto Forum:
  


Current Time: Fri Apr 26 13:30:56 GMT 2024

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

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

Back to the top