Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » String == operator overload(Wrong translation on java of the == string operator)
String == operator overload [message #1065540] Wed, 26 June 2013 12:18 Go to next message
claudio rosati is currently offline claudio rosatiFriend
Messages: 5
Registered: June 2013
Junior Member
Hi everybody, I'm just a beginner on xtext and I'm trying to develop a really easy DSL for "rule editing".

I've a lot of questions, but googling around I'm answering them one at a time.
At the moment I've a problem I'm getting stuck with (and google doesn't seem to have an answer): the overloading of the '==' operator of strings.

Given this code:
if ( riskClass == 'RK1' ) c12 = 0.9000
	else if ( riskClass > 'RK2' ) c12 = 0.1000


the engine generates this java output via model inferrer:
  public void op_0() {
    boolean _equals = void.equal(this.riskClass, "RK1");
    if (_equals) {
      this.c12 = 0.9000;
    } else {
      boolean _greaterThan = (this.riskClass.compareTo("RK2") > 0);
      if (_greaterThan) {
        this.c12 = 0.1000;
      }
    }
  }


It seems that the engine manages without problems the overloading of ">" and ">" or "<="... but the engine misses the overloading of "==" and refers to void.equal(this.riskClass, "RK1").

For clarity here is the inferrer code:
var method = toMethod("op_" + i, newTypeRef(Void::TYPE)) [					    			
  body = operazione.op
]

where operazione.op is an XExpression

The grammar is the following:
grammar com.armundia.quotr.QtrDsl with org.eclipse.xtext.xbase.Xbase
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
generate qtrDsl "..."

Model:
rules+=Rule*;

Rule:
'rule' name=ID 
dichiarazioni+=Dichiarazione*		
operazioni+=Operazione*	
'end rule';

Dichiarazione:
Variabile|VariabileInput;

Variabile:	
'outputvar' name=ValidID (':' type=JvmTypeReference)? ('=' right=XExpression)?;

VariabileInput:
'inputvar' name=ValidID (':' type=JvmTypeReference)? ('=' right=XExpression)?;

Operazione:
op=XExpression;

Result:
ret=XReturnExpression;


I've included on the runtime eclipse the library:
org.eclipse.xtext.xbase.lib_2.4.1.v201304180855.jar


Waiting to be more helpful on the list, thanks for the help

Claudio

Re: String == operator overload [message #1065590 is a reply to message #1065540] Wed, 26 June 2013 15:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

i dont get this it is intended todo an equals.

/**
* The <code>equals</code> operator. This is the equivalent to a null-safe invocation of
* {@link Object#equals(Object)}.
*
* @param a
* an object.
* @param b
* another object.
* @return <code>true</code> if {@code a} and {@code b} are equal.
*/
@Pure
@Inline(value="$3.equal($1, $2)", imported=Objects.class)
public static boolean operator_equals(Object a, Object b) {
return Objects.equal(a, b);
}


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

[Updated on: Wed, 26 June 2013 15:31]

Report message to a moderator

Re: String == operator overload [message #1065594 is a reply to message #1065590] Wed, 26 June 2013 15:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S => Looks like a bug to me (or your classpath is insufficient)

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

[Updated on: Wed, 26 June 2013 15:35]

Report message to a moderator

Re: String == operator overload [message #1065596 is a reply to message #1065594] Wed, 26 June 2013 15:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.P.S:

com.google.common.base.Objects.equal(Object, Object) should be called.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: String == operator overload [message #1065598 is a reply to message #1065596] Wed, 26 June 2013 15:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Here a starting point for debugging: org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.appendInlineFeatureCall(XAbstractFeatureCall, ITreeAppendable)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: String == operator overload [message #1065608 is a reply to message #1065598] Wed, 26 June 2013 16:06 Go to previous messageGo to next message
claudio rosati is currently offline claudio rosatiFriend
Messages: 5
Registered: June 2013
Junior Member
Thanks.... I'm going to dive into a long debug session and hopefully find a solution.... I hope to write the answer here.
Re: String == operator overload [message #1065617 is a reply to message #1065608] Wed, 26 June 2013 17:18 Go to previous message
claudio rosati is currently offline claudio rosatiFriend
Messages: 5
Registered: June 2013
Junior Member
Problem resolved, thanks for the hints.

As you thought it was a problem of classpath, I had to add the com.google.guava jar becouse the

return Objects.equal(a, b);
in the ObjectExtensions was referencing to a class of this package.

I'm starting to understand a bit more of this new world.
Previous Topic:How customize tooltips
Next Topic:Disabling ID Terminal Uniqueness ?
Goto Forum:
  


Current Time: Tue Apr 23 08:37:29 GMT 2024

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

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

Back to the top