sundar@1404: /* sundar@1404: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. sundar@1404: * sundar@1404: * Redistribution and use in source and binary forms, with or without sundar@1404: * modification, are permitted provided that the following conditions sundar@1404: * are met: sundar@1404: * sundar@1404: * - Redistributions of source code must retain the above copyright sundar@1404: * notice, this list of conditions and the following disclaimer. sundar@1404: * sundar@1404: * - Redistributions in binary form must reproduce the above copyright sundar@1404: * notice, this list of conditions and the following disclaimer in the sundar@1404: * documentation and/or other materials provided with the distribution. sundar@1404: * sundar@1404: * - Neither the name of Oracle nor the names of its sundar@1404: * contributors may be used to endorse or promote products derived sundar@1404: * from this software without specific prior written permission. sundar@1404: * sundar@1404: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS sundar@1404: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, sundar@1404: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sundar@1404: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR sundar@1404: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, sundar@1404: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, sundar@1404: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR sundar@1404: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF sundar@1404: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING sundar@1404: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS sundar@1404: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sundar@1404: */ sundar@1404: sundar@1404: // script helpers to print meta info on Java instances and classes sundar@1404: sundar@1404: // print instance methods info on a Java object or static methods info of a Java class sundar@1404: function methods(jobj) { sundar@1404: if (! Java.isJavaObject(jobj)) { sundar@1404: throw new TypeError("not a Java object"); sundar@1404: } sundar@1404: sundar@1404: var isStatic = Java.isType(jobj); sundar@1404: var obj = Object.bindProperties({}, jobj); sundar@1404: for each (var i in obj) { sundar@1404: if (Java.isJavaMethod(i)) { sundar@1404: var str = String(i); sundar@1404: var idx = str.indexOf(' '); sundar@1404: var overloaded = str.substring(0, idx).endsWith("OverloadedDynamicMethod"); sundar@1404: var lastIdx = isStatic? str.lastIndexOf('] on') : str.lastIndexOf(']'); sundar@1404: print(str.substring(idx + 1, lastIdx) + (overloaded? "*" : "")) sundar@1404: } sundar@1404: } sundar@1404: } sundar@1404: sundar@1404: // print instance field names of a Java object or static field names of a Java class sundar@1404: function fields(jobj) { sundar@1404: if (! Java.isJavaObject(jobj)) { sundar@1404: throw new TypeError("not a Java object"); sundar@1404: } sundar@1404: sundar@1404: var obj = Object.bindProperties({}, jobj); sundar@1404: for (var i in obj) { sundar@1404: if (! Java.isJavaMethod(obj[i])) { sundar@1404: print(i); sundar@1404: } sundar@1404: } sundar@1404: } sundar@1404: sundar@1404: undefined;