@@ -72,8 +72,10 @@ def __repr__(self):
7272
7373
7474class JavaObject (object ):
75- classdesc = None
76- annotations = []
75+
76+ def __init__ (self ):
77+ self .classdesc = None
78+ self .annotations = []
7779
7880 def get_class (self ):
7981 return self .classdesc
@@ -314,6 +316,7 @@ def do_object(self, parent=None, ident=0):
314316 # TC_OBJECT classDesc newHandle classdata[] // data for each class
315317 java_object = JavaObject ()
316318 log_debug ("[object]" , ident )
319+ log_debug ("java_object.annotations just after instantination: " + str (java_object .annotations ), ident )
317320
318321 # TODO: what to do with "(ClassDesc)prevObject". (see 3rd line for classDesc:)
319322 opcode , classdesc = self ._read_and_exec_opcode (ident = ident + 1 , expect = [self .TC_CLASSDESC , self .TC_PROXYCLASSDESC , self .TC_NULL , self .TC_REFERENCE ])
@@ -357,11 +360,13 @@ def do_object(self, parent=None, ident=0):
357360
358361 if classdesc .flags & self .SC_SERIALIZABLE and classdesc .flags & self .SC_WRITE_METHOD or classdesc .flags & self .SC_EXTERNALIZABLE and classdesc .flags & self .SC_BLOCK_DATA :
359362 # objectAnnotation
363+ log_debug ("java_object.annotations before: " + str (java_object .annotations ), ident )
360364 while opcode != self .TC_ENDBLOCKDATA :
361365 opcode , obj = self ._read_and_exec_opcode (ident = ident + 1 ) # , expect=[self.TC_ENDBLOCKDATA, self.TC_BLOCKDATA, self.TC_OBJECT, self.TC_NULL, self.TC_REFERENCE])
362366 if opcode != self .TC_ENDBLOCKDATA :
363367 java_object .annotations .append (obj )
364368 log_debug ("objectAnnotation value: " + str (obj ), ident )
369+ log_debug ("java_object.annotations after: " + str (java_object .annotations ), ident )
365370
366371 # Transform object
367372 for transformer in self .object_transformers :
@@ -370,6 +375,7 @@ def do_object(self, parent=None, ident=0):
370375 java_object = tmp_object
371376 break
372377
378+ log_debug (">>> java_object: " + str (java_object ), ident )
373379 return java_object
374380
375381 def do_string (self , parent = None , ident = 0 ):
@@ -534,16 +540,23 @@ class DefaultObjectTransformer(object):
534540 class JavaList (list , JavaObject ):
535541 pass
536542
543+ class JavaMap (dict , JavaObject ):
544+ pass
545+
537546 def transform (self , object ):
538- # if object.get_class().name == "java.util.ArrayList":
539- # print "---"
540- # print "java.util.ArrayList"
541- # print object.annotations
542- # print "---"
543- # new_object = self.JavaList()
544- # object.copy(new_object)
545- # new_object.extend(object.annotations)
546- # return new_object
547+ if object .get_class ().name == "java.util.ArrayList" :
548+ # * @serialData The length of the array backing the <tt>ArrayList</tt>
549+ # * instance is emitted (int), followed by all of its elements
550+ # * (each an <tt>Object</tt>) in the proper order.
551+ print "---"
552+ print "java.util.ArrayList"
553+ print object .annotations
554+ print "---"
555+ new_object = self .JavaList ()
556+ object .copy (new_object )
557+ new_object .extend (object .annotations [1 :])
558+ print ">>> object:" , new_object
559+ return new_object
547560 if object .get_class ().name == "java.util.LinkedList" :
548561 print "---"
549562 print
@@ -552,7 +565,22 @@ def transform(self, object):
552565 print "---"
553566 new_object = self .JavaList ()
554567 object .copy (new_object )
555- new_object .extend (object .annotations )
568+ new_object .extend (object .annotations [1 :])
569+ print ">>> object:" , new_object
570+ return new_object
571+ if object .get_class ().name == "java.util.HashMap" :
572+ print "---"
573+ print
574+ print "java.util.HashMap"
575+ print object .annotations
576+ print "---"
577+ new_object = self .JavaMap ()
578+ object .copy (new_object )
579+
580+ for i in range ((len (object .annotations )- 1 )/ 2 ):
581+ new_object [object .annotations [i * 2 + 1 ]] = object .annotations [i * 2 + 2 ]
582+
583+ print ">>> object:" , new_object
556584 return new_object
557585
558586 return object
0 commit comments