Bug 202293 - [model] SourceField.getConstant() should return constant value for all compile-time known values
Summary: [model] SourceField.getConstant() should return constant value for all compil...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 85382
  Show dependency tree
 
Reported: 2007-09-05 12:17 EDT by Genady Beryozkin CLA
Modified: 2008-08-22 12:27 EDT (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 Genady Beryozkin CLA 2007-09-05 12:17:00 EDT
Currently SourceField uses simple source code parsing to return the constant value.

For example it does not account for:
1. Characters with unicode values (e.g, '\u05D0')
2. Is wrong for Strings that contain unicode values
3. Simple arithmetic expressions (1+1)

All these constants appear as constants in the .class file. It would be nice to have them as constant values at the source file level too.
Comment 1 Olivier Thomann CLA 2007-09-14 10:46:32 EDT
If you can use the AST nodes instead, you might be able to get the constant value through the binding of the corresponding variable fragment.
Comment 2 Genady Beryozkin CLA 2007-09-14 13:44:02 EDT
I can use the AST Expression to retrieve the constant. But wouldn't it be simpler to just record it at compile time instead of parsing it in SourceField?

It's just a small enhancement. I don't think it blocks bug 85382 because AST is being used when the source code is available.
Comment 3 Jerome Lanneluc CLA 2007-09-19 09:40:26 EDT
(In reply to comment #0)
> Currently SourceField uses simple source code parsing to return the constant
> value.
> 
> For example it does not account for:
> 1. Characters with unicode values (e.g, '\u05D0')
We would need to do the parsing ourselves as I believe there is no support from java.lang.Character to convert a String into a char. We might need to use the compiler's parser for that.

> 2. Is wrong for Strings that contain unicode values
Could you please elaborate ?

> 3. Simple arithmetic expressions (1+1)
and all other constant expressions (see http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#5313).
This would require to compile the source initializer. I'm not sure we have enough context. This needs to be investigated.
Comment 4 Genady Beryozkin CLA 2007-09-19 10:23:09 EDT
2. Suppose the string initializer is "This is \u05D0". The current implementation would return the string as is, while it should 
return "This is א" (the unicode character number 0x05D0).

Again, for me this is *not* a top priority issue...