Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xbase] Extension functions, inlining and arrays
[xbase] Extension functions, inlining and arrays [message #947142] Tue, 16 October 2012 21:19
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member

I've defined a new index operator (# symbol) that is used for accessing
elements of a collection based on a key. The operator is mapped to an
overloaded extension function, similar to how the built-in operators
work. I'm now struggling with two issues: inlining and supporting arrays.

I use the @Inline annotation and it seems to work, but the imported
attribute doesn't seem to have any effect. E.g. the following function
is used, but Iterables isn't imported as I think it should. I have to
use @Inline(value="$1, $2)"
instead, which results in more verbose code.

@Inline(value="Iterables.get($1, $2)", imported=Iterables.class,
public static <T> T operator_index(Iterable<T> iterable, int pos) {
return Iterables.get(iterable, pos);

The second (and more important) problem is that I'm not able to support
arrays. I define the following extension function (and similar for other
array types), but it never seems to be noticed:

public static int operator_index(int [] array, int pos) {
return array[pos];

E.g. in a method where i is declared as an int[], i # 0 is translated to
Iterables.get(((Iterable<Integer>)Conversions.doWrapArray(i)), 0) and
not to i[0] as I want.

Is it possible to support arrays like this?

Previous Topic:Modifying the default grammar
Next Topic:Is it possible to generate nested classes/interfaces from IJvmModelInferrer?
Goto Forum:

Current Time: Fri May 07 19:14:51 GMT 2021

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

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

Back to the top