Community
Participate
Working Groups
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.
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.
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.
(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.
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...