Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348642 - IntegerLiteral.getIntValue and setIntValue only work with Integers
Summary: IntegerLiteral.getIntValue and setIntValue only work with Integers
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Paul Harmon CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-07 16:49 EDT by Matt Heitz CLA
Modified: 2017-02-23 14:17 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Heitz CLA 2011-06-07 16:49:27 EDT
IntegerLiteral has getIntValue and setIntValue methods.  They operate with an Integer.  But an integer literal in EGL can be up to 32 digits long, much too big for a puny Integer.

I see no calls of setIntValue anywhere, and two methods that call getIntValue in the JS generator.  (Scott: the condition where you call getIntValue in IntTypeTemplate is either going to be true, or it'll die due to a NumberFormatException if the integer is too big for an int.)

I suggest that we remove getIntValue and setIntValue, but add methods to tell us about the size of the literal: 


public boolean fitsInInt()
{
	return new BigInteger( getValue() ).bitLength() < 32;
}

public boolean fitsInSmallint()
{
	return new BigInteger( getValue() ).bitLength() < 16;
}

public boolean fitsInBigint()
{
	return new BigInteger( getValue() ).bitLength() < 64;
}



Paul & Scott: I'd like your feedback on this suggestion.
Comment 1 Scott Greer CLA 2011-06-10 18:51:58 EDT
I agree with both of Matt's points:  clearly, we need the IntegerLiteral to support as many digits as the language allows and we also need convenience routines that characterize the size of a given literal.  

However, I'm not sure the suggested fitsIn<type> methods result in the best design;  I can see generator code cascading thru the different sizes trying to find the one that fits best, which with the suggested logic will repeatedly construct temporary BigIntegers.
Comment 2 Paul Harmon CLA 2011-06-14 14:11:33 EDT
I have updated IntegerLiteral.getType() as per bug 384644. I have not removed the getIntValue and setIntValue methods, because JS generation is still using the getter.

Scott, please let me know when you have removed the references to this method from your code and i will delete the methods from the mof class.
Comment 3 Matt Heitz CLA 2011-06-14 20:17:17 EDT
Changing the owner to Paul since he started doing the work.
Comment 4 Matt Heitz CLA 2011-07-14 11:03:55 EDT
The setter was removed, and nobody was calling the getter anymore, so I removed it too.

While doing this, I noticed that PrimitiveTypeLiteral has
   public void getObjectValue();  
A getter that returns void!  Now that's thinking outside the box!  I changed it to return Object, and added a reasonable implementation in all the PrimitiveTypeLiterals.  It returns getValue() in most cases.
Comment 5 Matt Heitz CLA 2011-08-30 14:00:53 EDT
Closing.