How to generate a serialVersionUID field and add to AST [message #258842] |
Mon, 23 February 2009 11:00  |
Eclipse User |
|
|
|
Originally posted by: myawn.ebay.com
Hi all,
I'm generating some Java classes from scratch using the AST. A few of
these need to be serializable, and I'd like to have a good
serialVersionUID field inserted into the class at generation time. (That
is, not a value like 0L or 1L, but a value actually calculated from
class members in accordance with the serialization specification).
The only code I've been able to find to do this is the
ObjectStreamClass.lookup() method, which requires a .class as input. I
don't have a .class file at this point, and I think (from other threads
I've read) that trying to force a build and then load the .class file
from my plug-in might cause problems.
Has anyone else come up with a better solution for this? The ideal
solution would be if there was a callable API that had the logic to
calculate the serialVersionUID value from an AST root node or
ICompilationUnit. Does anything like this exist in an internal JDT class?
Thanks,
Mike
|
|
|
Re: How to generate a serialVersionUID field and add to AST [message #258862 is a reply to message #258842] |
Mon, 23 February 2009 18:33   |
Eclipse User |
|
|
|
Originally posted by: myawn.ebay.com
I wrote:
> Hi all,
>
> I'm generating some Java classes from scratch using the AST. A few of
> these need to be serializable, and I'd like to have a good
> serialVersionUID field inserted into the class at generation time. (That
> is, not a value like 0L or 1L, but a value actually calculated from
> class members in accordance with the serialization specification).
>
> The only code I've been able to find to do this is the
> ObjectStreamClass.lookup() method, which requires a .class as input. I
> don't have a .class file at this point, and I think (from other threads
> I've read) that trying to force a build and then load the .class file
> from my plug-in might cause problems.
>
> Has anyone else come up with a better solution for this? The ideal
> solution would be if there was a callable API that had the logic to
> calculate the serialVersionUID value from an AST root node or
> ICompilationUnit. Does anything like this exist in an internal JDT
> class?
>
> Thanks,
> Mike
Following up after more time digging on this -- I found
org.eclipse.jdt.internal.ui.text.correction.SerialVersionHas hOperation,
which has a method calculateSerialVersionIds() that looked like it would
do what I need. However, when I call this I'm getting back a zero
result -- so if that is in fact the correct method to use, then I'm
missing something in the prerequisites. (I've tried rewriting the AST,
and when that wasn't sufficient, triggering an incremental build, but
I'm still getting a zero svuid back).
Mike
|
|
|
Re: How to generate a serialVersionUID field and add to AST [message #258869 is a reply to message #258862] |
Tue, 24 February 2009 08:46  |
Eclipse User |
|
|
|
Mike Yawn wrote:
> I wrote:
>> Hi all,
>>
>> I'm generating some Java classes from scratch using the AST. A few
>> of these need to be serializable, and I'd like to have a good
>> serialVersionUID field inserted into the class at generation time.
>> (That is, not a value like 0L or 1L, but a value actually calculated
>> from class members in accordance with the serialization specification).
>>
>> The only code I've been able to find to do this is the
>> ObjectStreamClass.lookup() method, which requires a .class as
>> input. I don't have a .class file at this point, and I think (from
>> other threads I've read) that trying to force a build and then load
>> the .class file from my plug-in might cause problems.
>>
>> Has anyone else come up with a better solution for this? The ideal
>> solution would be if there was a callable API that had the logic to
>> calculate the serialVersionUID value from an AST root node or
>> ICompilationUnit. Does anything like this exist in an internal JDT
>> class?
>>
>> Thanks,
>> Mike
>
> Following up after more time digging on this -- I found
> org.eclipse.jdt.internal.ui.text.correction.SerialVersionHas hOperation,
> which has a method calculateSerialVersionIds() that looked like it
> would do what I need. However, when I call this I'm getting back a
> zero result -- so if that is in fact the correct method to use, then
> I'm missing something in the prerequisites. (I've tried rewriting the
> AST, and when that wasn't sufficient, triggering an incremental build,
> but I'm still getting a zero svuid back).
Take a look at
org.eclipse.jdt.internal.ui.text.correction.SerialVersionSub Processor.SerialVersionProposal
Dani
>
> Mike
>
|
|
|
Powered by
FUDForum. Page generated in 0.04437 seconds