Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing properties through JVM model
Accessing properties through JVM model [message #1721903] Mon, 01 February 2016 15:13 Go to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
Hello Christian,

As a follow-up of last week's discussions, I have decided to augment my DSL to support property access like in your post : https://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-expressions/

The approach presented there is quite straightforward and understandable, but I don't think it can apply to my case for 2 reasons. The first is that I need to access the referenced properties through specific methods (so no direct Model/EMF representation) and also because a large part of the model will be shipped as a Java library with no model to generate from / link to.

As you may recall, my properties generate instances of Property containers that have different attributes (PropertyAttribute). I would like to write a DSL that allows me to chain access as such:

top.child.subchild = literalvalue

that generates code like:

top.value.get.child.value.get.subchild.value = literalvalue

The "value" returns an optional, thus the added call at each step.

How do you think I should do this? There is some issues of typing, auto completion etc.
It doesn't seem to me like the scoping as you have done on your blog post is a good strategy, as a large part of the model is not available and thus needs to go through JVM class analysis.

Any suggestion will be greatly appreciated.

Daniel
Re: Accessing properties through JVM model [message #1721916 is a reply to message #1721903] Mon, 01 February 2016 16:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi,

i dont get that Point. you dont Need to do this in a jvmmodel based envionment at all. in a jvmmodel envionment this should work with xexpressions automatically


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721919 is a reply to message #1721916] Mon, 01 February 2016 16:51 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
The XExpressions are much too complex for my taste.

property.getValue().get().subProperty.getValue().get()

i would much rather write

property.subProperty = false

I don't really care to modify xbase. I don't need to express that kind of thing in an XBlockExpression for example.
I'm fine doing things like:

init {
a.b.c = 10
a.b.d = false
etc.
}

You see ?
Re: Accessing properties through JVM model [message #1721921 is a reply to message #1721919] Mon, 01 February 2016 16:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Did you consider to use null values and optional chaining ?. Operator

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721927 is a reply to message #1721921] Mon, 01 February 2016 17:13 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
Yes, and that will be part of my expression DSL as well..
but 1) how do I remove the extra code, like getValue() and get()
2) how do I get the list of 'fields', if they are coming only from java classes and not from an EMF model ?
Re: Accessing properties through JVM model [message #1721928 is a reply to message #1721927] Mon, 01 February 2016 17:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Daniel Cardin <forums-noreply@xxxxxxxx> wrote:
> Yes, and that will be part of my expression DSL as well..
> but 1) how do I remove the extra code, like getValue() and get()
> 2) how do I get the list of 'fields', if they are coming only from java
> classes and not from an EMF model ?
>

I don't get that. I am talking about pure xbase and not using optionals.
Give it a try with xtend


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721929 is a reply to message #1721928] Mon, 01 February 2016 17:29 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
I'm way more familiar with xtend than xtext Smile and I am trying to go one step above.
If xtend had default accessors or the equivalent of the "apply" method in Scala, it would work. But I am not introducing Optionals for the fun of it, it's because they are needed. Plus, how do I abstract away the "value()" call ?
Re: Accessing properties through JVM model [message #1721931 is a reply to message #1721929] Mon, 01 February 2016 17:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Can you share some example pojos and client code that help me to reproduce
and understand your problem


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721939 is a reply to message #1721931] Mon, 01 February 2016 18:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
p.s: back to my blog post: the jvm stuff is emf objects as well: but doing the scoping right is pain as hell.
thus my idea to have a api (maybe wrapped arround your api) that is more close to what xbase can currently understand


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721940 is a reply to message #1721931] Mon, 01 February 2016 18:12 Go to previous messageGo to next message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
public class Dimension extends Configurable {
  public final ValueProperty<Measure<Area>> area = new ValueProperty<Measure<Area>>("area");
  public final ValueProperty<Measure<Length>> perimeter = new ValueProperty<Measure<Length>>("perimeter");
  public final ValueProperty<Measure<Length>> height = new ValueProperty<Measure<Length>>("height");
 


public class Horizontal extends SomethingUsingDimension {
  public final ValueProperty<Boolean> hasBox = new ValueProperty<Boolean>("hasBox");
  
  private final void init_hasBox() {
    hasBox.setAttribute(PropertyAttribute.VISIBLE,Boolean.valueOf(true));    
  }
  
  protected void init() {
    super.init();
    registerProperty("hasBox", hasBox);
    init_hasBox();
    
    // this line I want to write :   dimension.height = 100 mm
    dimension.getValue().get().height.setValue(Measure.valueOf(100d, SI.MILLI(SI.METER)));
  }
}


Like I said, I don't need it to be XBase based. It can be expressions as part of the DSL.

Re: Accessing properties through JVM model [message #1721943 is a reply to message #1721940] Mon, 01 February 2016 18:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
sounds like this can be only done with a bigger adoption. unfortunately i dont have the time to support that deeply.
what i dont understand is: is the libary user provided or is it yours? ( i mean the dimension class?)
if it is yours you could use a (static) wrapper class instead? maybe provided by an extension?
this would offer a

package org.xtext.example.mydsl

import java.util.Optional

class Dimension {
	 public val ValueProperty<Measure<Area>> area = new ValueProperty<Measure<Area>>("area");
  public val ValueProperty<Measure<Length>> perimeter = new ValueProperty<Measure<Length>>("perimeter");
  public val  ValueProperty<Measure<Length>> height = new ValueProperty<Measure<Length>>("height");
	
}

class Main {
	
	def static void handle(Dimension dimension) {
		dimension.height = 10
	}
	
	def static setHeight(Dimension d, int height) {
		//TODO
	}
	
	def static int getHeight(Dimension d) {
		//TODO
		0
	}
}

class ValueProperty<T> {
	
	new(String s)  {
		
	}

	def Optional<T> getValue() {
		return null;
	}
}

class Area {
	
}

class Length {
	
}

class Measure<T> {
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Accessing properties through JVM model [message #1721945 is a reply to message #1721943] Mon, 01 February 2016 18:36 Go to previous message
Daniel Cardin is currently offline Daniel CardinFriend
Messages: 109
Registered: July 2009
Senior Member
There are way too many possibilities in the runtime model for that kind of integration.
I'll have to think about it. worst case, it will be ID + ('.' ID)* with no content assist. But I was hoping for context Smile
Thanks anyway Christian Smile
Previous Topic:Find annotated model element from other file in Inferrer
Next Topic:Auto -Complete for intellij , based web editor
Goto Forum:
  


Current Time: Mon Sep 20 11:29:17 GMT 2021

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

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

Back to the top