# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

names.jobjRef <- function( o ){
        cl <- if (inherits(o, "jobjRef") || inherits(o, "jarrayRef")){
                .jcall(o, "Ljava/lang/Class;", "getClass")
        } else {
                .jfindClass(as.character(o))
        }
        fields <- .jcall(cl, "[Ljava/lang/reflect/Field;", "getFields")
        fieldnames <- sapply( fields, function(f){
                .jcall( f, "Ljava/lang/String;", "getName")
        } )

        methodz <- .jcall(cl, "[Ljava/lang/reflect/Method;", "getMethods")
        methodnames <- sapply( methodz, function(m){
                .jcall( m, "Ljava/lang/String;", "getName")
        } )
        nargs  <- sapply( methodz, function(m){
                length( .jcall( m, "[Ljava/lang/Class;", "getParameterTypes" ) )
        } )
        methodnames <- paste(
                methodnames,
                ifelse( nargs == 0 , "()", "( " ), sep = "" )
        c( fieldnames, methodnames )
}