private void addToStringMethod ( boolean keyOnly ) { TypeDesc stringBuilder = TypeDesc . forClass ( StringBuilder . class ) ; Modifiers modifiers = Modifiers . PUBLIC . toSynchronized ( true ) ; MethodInfo mi = addMethodIfNotFinal ( modifiers , keyOnly ? TO_STRING_KEY_ONLY_METHOD_NAME : TO_STRING_METHOD_NAME , TypeDesc . STRING , null ) ; if ( mi == null ) { return ; } CodeBuilder b = new CodeBuilder ( mi ) ; b . newObject ( stringBuilder ) ; b . dup ( ) ; b . invokeConstructor ( stringBuilder , null ) ; b . loadConstant ( mStorableType . getName ( ) ) ; invokeAppend ( b , TypeDesc . STRING ) ; String detail ; if ( keyOnly ) { detail = " (key only) {" ; } else { detail = " {" ; } b . loadConstant ( detail ) ; invokeAppend ( b , TypeDesc . STRING ) ; // First pass, just print primary keys. LocalVariable commaCountVar = b . createLocalVariable ( null , TypeDesc . INT ) ; b . loadConstant ( - 1 ) ; b . storeLocal ( commaCountVar ) ; for ( StorableProperty property : mInfo . getPrimaryKeyProperties ( ) . values ( ) ) { addPropertyAppendCall ( b , property , commaCountVar ) ; } // Second pass, print non-primary keys. if ( ! keyOnly ) { for ( StorableProperty property : mAllProperties . values ( ) ) { // Don't print any derived or join properties since they may throw an exception. if ( ! property . isPrimaryKeyMember ( ) && ( ! property . isDerived ( ) ) && ( ! property . isJoin ( ) ) ) { addPropertyAppendCall ( b , property , commaCountVar ) ; } } } b . loadConstant ( ' ' ) ; invokeAppend ( b , TypeDesc . CHAR ) ; // For key string, also show all the alternate keys. This makes the // FetchNoneException message more helpful. if ( keyOnly ) { int altKeyCount = mInfo . getAlternateKeyCount ( ) ; for ( int i = 0 ; i < altKeyCount ; i ++ ) { b . loadConstant ( - 1 ) ; b . storeLocal ( commaCountVar ) ; b . loadConstant ( ", {" ) ; invokeAppend ( b , TypeDesc . STRING ) ; StorableKey < S > key = mInfo . getAlternateKey ( i ) ; for ( OrderedProperty < S > op : key . getProperties ( ) ) { StorableProperty < S > property = op . getChainedProperty ( ) . getPrimeProperty ( ) ; addPropertyAppendCall ( b , property , commaCountVar ) ; } b . loadConstant ( ' ' ) ; invokeAppend ( b , TypeDesc . CHAR ) ; } } b . invokeVirtual ( stringBuilder , TO_STRING_METHOD_NAME , TypeDesc . STRING , null ) ; b . returnValue ( TypeDesc . STRING ) ; }
Defines a toString method which assumes that the ClassFile is targeting version 1 . 5 of Java .