[foreign] RFR: Add a toString method to struct impl classes.

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Sat Dec 15 21:41:47 UTC 2018


Looks good to me.

P.S. I see from here [1] that you should now be a committer, so you can 
try push yourself and see how that goes?

Cheers
Maurizio

[1] - http://openjdk.java.net/census#jvernee

On 14/12/2018 17:03, Jorn Vernee wrote:
> Updated webrev: 
> http://cr.openjdk.java.net/~jvernee/panama/webrevs/structtostring/webrev.02/
>
> * Added static toString method to java.foreign.memory.Struct that 
> reflectively walks getters declared in the struct's layout annotation 
> to create a string representation.
>
> Jorn
>
> Jorn Vernee schreef op 2018-12-14 15:27:
>> Hi,
>>
>> During porting the binder to Windows I wrote a bunch of debugging
>> code. I thought this might be useful to have in the future, and I'd
>> like to handle these so I can remove them from my other local changes
>> (less stuff to maintain), so I'm creating this RFR. There are 3
>> subjects that I've split into 3 patches; This is the first one.
>>
>> 1.) toString method generation for Structs. This adds generation of a
>> toString method to StructImplGenerator, which uses the struct's
>> getters to output the values of the struct e.g.
>>
>>
>> @NativeStruct("[i32(get=one$get)(set=one$set)i32(get=two$get)(set=two$set)]") 
>>
>>     public interface MyStruct extends Struct<MyStruct> {
>>         int one$get();
>>         void one$set(int i);
>>
>>         int two$get();
>>         void two$set(int i);
>>     }
>>
>>     public static void main(String[] args) throws 
>> IllegalAccessException {
>>         try(var scope = Scope.newNativeScope()) {
>>             MyStruct s = scope.allocateStruct(MyStruct.class);
>>
>>             s.one$set(10);
>>             s.two$set(20);
>>
>>             System.out.println(s);
>>         }
>>     }
>>
>> Will output:
>>
>>     Main$MyStruct{ one$get=10, two$get=20 }
>>
>> Webrev:
>> http://cr.openjdk.java.net/~jvernee/panama/webrevs/structtostring/webrev.01/ 
>>
>>
>> Please let me know what you think and if you want to have this in the
>> repo, otherwise I will just throw it away.
>>
>> Cheers,
>> Jorn


More information about the panama-dev mailing list