Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Invalid equality test on atomic integer
Invalid equality test on atomic integer [message #1773928] Fri, 06 October 2017 16:04 Go to next message
Stephane Galland is currently offline Stephane GallandFriend
Messages: 120
Registered: July 2014
Location: Belfort, France
Senior Member
Dear all.

Consider the AtomicInteger from the Java API.
It does not define the "equals()" function, such that the following Xtend code replies always false for both functions:
def boolean fct1(AtomicInteger a, AtomicInteger b) {
    a == b
}
def boolean fct2(int a, AtomicInteger b) {
    a == b
}
def void main() {
    var int x = 4
    var AtomicInteger y = new AtomicInteger(4)
    var AtomicInteger z = new AtomicInteger(4)
    System.out.println(y + "==" + z + " => " + fct1(y, z))
    System.out.println(x + "==" + y + " => " + fct2(x, y))
}


Indeed the generated Java code looks like:
public boolean fct1(AtomicInteger a, AtomicInteger b) {
    return Objects.equal(a, b);
}
public boolean fct2(int a, AtomicInteger b) {
    return Objects.equal(Integer.valueOf(a), b);
}


I have solved this issue in my own DSL by writing a specific extensions provider that is implicitly imported with my ImplicitlyImportedFeatures.

Nevertheless, I think this is an issue from all the Xbase-based DSLs.
I would like to submit a patch to the Xbase project.
If you think it is relevant, is my method the best one? Or should I explore another method ? Which one?

All the best.
Stéphane.


Prof. Stéphane Galland.
Belfort-Montbéliard University of Technologie, France.

http://www.multiagent.fr/People:Galland_stephane
http://www.sarl.io
http://www.arakhne.org
Re: Invalid equality test on atomic integer [message #1773929 is a reply to message #1773928] Fri, 06 October 2017 16:10 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12111
Registered: July 2009
Senior Member
atomicinteger is from java. if it has no equals it seems to be intended to return false.
what do you expect. what direction do you want to fix? add a own equal?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Invalid equality test on atomic integer [message #1773930 is a reply to message #1773929] Fri, 06 October 2017 16:13 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12111
Registered: July 2009
Senior Member
could you open a ticket at xtext-extras in github so we can discuss.
a change would at least break existing code


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Invalid equality test on atomic integer [message #1773934 is a reply to message #1773930] Fri, 06 October 2017 17:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5977
Registered: July 2009
Senior Member
Most Java primitives are immutable so two instances can have the same value.

AtomicInteger is mutable, so it can change.

Just imagine if you used an AtomicInteger as a Map index, then modified the AtomicInteger and then attempted to use the modified AtomicInteger to access the map. What is the lookup? of the value or the instance. Without equals() it is sensibly the instnace.

Regards

Ed Willink
Re: Invalid equality test on atomic integer [message #1773938 is a reply to message #1773934] Fri, 06 October 2017 18:04 Go to previous messageGo to next message
Stephane Galland is currently offline Stephane GallandFriend
Messages: 120
Registered: July 2014
Location: Belfort, France
Senior Member
I would like to have a consistent equality test notation for all types of Number.
My first idea is to provide the operator_equals() for the Number types.

Now, the case of the Map is verify specific, and should be handled by the developer from my point of view. It is similar to the case when we want to use any mutable object as a map key, that is a very bad practice, and should be avoiding (a warning may be added into your DSL validator for that. I have added one in my own).

As suggested by Christian, a discussion is open on https://github.com/eclipse/xtext-extras/issues/186https://github.com/eclipse/xtext-extras/issues/186


Prof. Stéphane Galland.
Belfort-Montbéliard University of Technologie, France.

http://www.multiagent.fr/People:Galland_stephane
http://www.sarl.io
http://www.arakhne.org
Re: Invalid equality test on atomic integer [message #1773939 is a reply to message #1773938] Fri, 06 October 2017 19:27 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5977
Registered: July 2009
Senior Member
Hi

No. Arguably the prime use case for equals() is Set equality. It is fundamental to the Java Collections Library.

Regards

Ed Willink
Previous Topic:Unordered group separator
Next Topic:Build triggered when opening file in language implemented by Xtext
Goto Forum:
  


Current Time: Fri Jul 20 10:42:22 GMT 2018

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

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

Back to the top