[foreign] RFR: Add a toString method to struct impl classes.
    Jorn Vernee 
    jbvernee at xs4all.nl
       
    Fri Dec 14 14:27:58 UTC 2018
    
    
  
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