samples/javahelp.js

Mon, 29 Feb 2016 10:33:44 -0800

author
asaha
date
Mon, 29 Feb 2016 10:33:44 -0800
changeset 1798
e35e96663a90
parent 1404
271aceb4b3f0
permissions
-rw-r--r--

Added tag jdk8u75-b10 for changeset bab68ab3df71

sundar@1404 1 /*
sundar@1404 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
sundar@1404 3 *
sundar@1404 4 * Redistribution and use in source and binary forms, with or without
sundar@1404 5 * modification, are permitted provided that the following conditions
sundar@1404 6 * are met:
sundar@1404 7 *
sundar@1404 8 * - Redistributions of source code must retain the above copyright
sundar@1404 9 * notice, this list of conditions and the following disclaimer.
sundar@1404 10 *
sundar@1404 11 * - Redistributions in binary form must reproduce the above copyright
sundar@1404 12 * notice, this list of conditions and the following disclaimer in the
sundar@1404 13 * documentation and/or other materials provided with the distribution.
sundar@1404 14 *
sundar@1404 15 * - Neither the name of Oracle nor the names of its
sundar@1404 16 * contributors may be used to endorse or promote products derived
sundar@1404 17 * from this software without specific prior written permission.
sundar@1404 18 *
sundar@1404 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
sundar@1404 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
sundar@1404 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
sundar@1404 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
sundar@1404 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sundar@1404 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
sundar@1404 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
sundar@1404 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
sundar@1404 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
sundar@1404 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sundar@1404 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sundar@1404 30 */
sundar@1404 31
sundar@1404 32 // script helpers to print meta info on Java instances and classes
sundar@1404 33
sundar@1404 34 // print instance methods info on a Java object or static methods info of a Java class
sundar@1404 35 function methods(jobj) {
sundar@1404 36 if (! Java.isJavaObject(jobj)) {
sundar@1404 37 throw new TypeError("not a Java object");
sundar@1404 38 }
sundar@1404 39
sundar@1404 40 var isStatic = Java.isType(jobj);
sundar@1404 41 var obj = Object.bindProperties({}, jobj);
sundar@1404 42 for each (var i in obj) {
sundar@1404 43 if (Java.isJavaMethod(i)) {
sundar@1404 44 var str = String(i);
sundar@1404 45 var idx = str.indexOf(' ');
sundar@1404 46 var overloaded = str.substring(0, idx).endsWith("OverloadedDynamicMethod");
sundar@1404 47 var lastIdx = isStatic? str.lastIndexOf('] on') : str.lastIndexOf(']');
sundar@1404 48 print(str.substring(idx + 1, lastIdx) + (overloaded? "*" : ""))
sundar@1404 49 }
sundar@1404 50 }
sundar@1404 51 }
sundar@1404 52
sundar@1404 53 // print instance field names of a Java object or static field names of a Java class
sundar@1404 54 function fields(jobj) {
sundar@1404 55 if (! Java.isJavaObject(jobj)) {
sundar@1404 56 throw new TypeError("not a Java object");
sundar@1404 57 }
sundar@1404 58
sundar@1404 59 var obj = Object.bindProperties({}, jobj);
sundar@1404 60 for (var i in obj) {
sundar@1404 61 if (! Java.isJavaMethod(obj[i])) {
sundar@1404 62 print(i);
sundar@1404 63 }
sundar@1404 64 }
sundar@1404 65 }
sundar@1404 66
sundar@1404 67 undefined;

mercurial