nashorn/samples/classes.js
author bchristi
Fri, 08 Jan 2016 13:14:30 -0800
changeset 34934 7fbff68dbc12
parent 32314 8f7d23d3b1ad
permissions -rw-r--r--
8144552: java/lang/StackWalker/LocalsAndOperands.java fails with java.lang.NullPointerException Summary: Update test case to expect null Reviewed-by: mchung, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32314
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     1
// Usage: jjs classes.js [ -- <java_package_name > ]
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     2
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     3
/*
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     4
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     5
 *
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     6
 * Redistribution and use in source and binary forms, with or without
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     7
 * modification, are permitted provided that the following conditions
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     8
 * are met:
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
     9
 *
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    10
 *   - Redistributions of source code must retain the above copyright
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    11
 *     notice, this list of conditions and the following disclaimer.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    12
 *
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    13
 *   - Redistributions in binary form must reproduce the above copyright
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    14
 *     notice, this list of conditions and the following disclaimer in the
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    15
 *     documentation and/or other materials provided with the distribution.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    16
 *
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    17
 *   - Neither the name of Oracle nor the names of its
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    18
 *     contributors may be used to endorse or promote products derived
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    19
 *     from this software without specific prior written permission.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    20
 *
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    22
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    24
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    28
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    29
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    30
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    31
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    32
 */
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    33
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    34
// print all Java classes of the given package and its subpackages.
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    35
var pkg = arguments.length > 0? arguments[0] : "java.lang";
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    36
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    37
with (new JavaImporter(javax.tools, java.util)) {
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    38
    var compiler = ToolProvider.systemJavaCompiler;
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    39
    var fm = compiler.getStandardFileManager(null, null, null);
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    40
    var kinds = EnumSet.of(JavaFileObject.Kind.CLASS);
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    41
    var loc = StandardLocation.PLATFORM_CLASS_PATH;
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    42
    var itr = fm.list(loc, pkg, kinds, true).iterator();
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    43
    while(itr.hasNext()) {
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    44
        print(fm.inferBinaryName(loc, itr.next()));
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    45
    }
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    46
    fm.close();
8f7d23d3b1ad 8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
diff changeset
    47
}