JDK 11 jdk.scripting.nashorn.shell.jmod - Scripting Nashorn Shell Module

JDK 11 jdk.scripting.nashorn.shell.jmod is the JMOD file for JDK 11 Scripting Nashorn Shell module.

JDK 11 Scripting Nashorn Shell module compiled class files are stored in \fyicenter\jdk-11.0.1\jmods\jdk.scripting.nashorn.shell.jmod.

JDK 11 Scripting Nashorn Shell module compiled class files are also linked and stored in the \fyicenter\jdk-11.0.1\lib\modules JImage file.

JDK 11 Scripting Nashorn Shell module source code files are stored in \fyicenter\jdk-11.0.1\lib\src.zip\jdk.scripting.nashorn.shell.

You can click and view the content of each source code file in the list below.

✍: FYIcenter

jdk/nashorn/tools/jjs/PropertiesHelper.java

/*
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

package jdk.nashorn.tools.jjs;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.WeakHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.NativeJavaPackage;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.objects.NativeJava;

/*
 * A helper class to get properties of a given object for source code completion.
 */
final class PropertiesHelper {
    // Java package properties helper, may be null
    private PackagesHelper pkgsHelper;
    // cached properties list
    private final WeakHashMap<Object, List<String>> propsCache = new WeakHashMap<>();

    /**
     * Construct a new PropertiesHelper.
     *
     * @param context the current nashorn Context
     */
    PropertiesHelper(final Context context) {
        try {
            this.pkgsHelper = PackagesHelper.create(context);
        } catch (final IOException exp) {
            if (Main.DEBUG) {
                exp.printStackTrace();
            }
            this.pkgsHelper = null;
        }
    }

    void close() throws Exception {
        propsCache.clear();
        pkgsHelper.close();
    }

    /**
     * returns the list of properties of the given object.
     *
     * @param obj object whose property list is returned
     * @return the list of properties of the given object
     */
    List<String> getProperties(final Object obj) {
        assert obj != null && obj != ScriptRuntime.UNDEFINED;

        // wrap JS primitives as objects before gettting properties
        if (JSType.isPrimitive(obj)) {
            return getProperties(JSType.toScriptObject(obj));
        }

        // Handle Java package prefix case first. Should do it before checking
        // for its super class ScriptObject!
        if (obj instanceof NativeJavaPackage) {
            if (pkgsHelper != null) {
                return pkgsHelper.getPackageProperties(((NativeJavaPackage)obj).getName());
            } else {
                return Collections.<String>emptyList();
            }
        }

        // script object - all inherited and non-enumerable, non-index properties
        if (obj instanceof ScriptObject) {
            final ScriptObject sobj = (ScriptObject)obj;
            final PropertyMap pmap = sobj.getMap();
            if (propsCache.containsKey(pmap)) {
                return propsCache.get(pmap);
            }
            final String[] keys = sobj.getAllKeys();
            List<String> props = Arrays.asList(keys);
            props = props.stream()
                         .filter(s -> Character.isJavaIdentifierStart(s.charAt(0)))
                         .collect(Collectors.toList());
            Collections.sort(props);
            // cache properties against the PropertyMap
            propsCache.put(pmap, props);
            return props;
        }

        // java class case - don't refer to StaticClass directly
        if (NativeJava.isType(ScriptRuntime.UNDEFINED, obj)) {
            if (propsCache.containsKey(obj)) {
                return propsCache.get(obj);
            }
            final List<String> props = NativeJava.getProperties(obj);
            Collections.sort(props);
            // cache properties against the StaticClass representing the class
            propsCache.put(obj, props);
            return props;
        }

        // any other Java object
        final Class<?> clazz = obj.getClass();
        if (propsCache.containsKey(clazz)) {
            return propsCache.get(clazz);
        }

        final List<String> props = NativeJava.getProperties(obj);
        Collections.sort(props);
        // cache properties against the Class object
        propsCache.put(clazz, props);
        return props;
    }

    // This method creates a regex Pattern to use to do CamelCase
    // matching. The pattern is derived from user supplied string
    // containing one or more upper case characters in it.
    private static Pattern makeCamelCasePattern(final String str) {
        assert !str.isEmpty();

        final char[] chars = str.toCharArray();
        final StringBuilder buf = new StringBuilder();
        boolean seenUpperCase = false;

        // Skip first char for case check. Even if it is upper case,
        // we do not want to put lower case matching pattern before
        // the first letter!
        buf.append(chars[0]);

        for (int idx = 1; idx < chars.length; idx++) {
            final char ch = chars[idx];
            if (ch >= 'A' && ch <= 'Z') {
                seenUpperCase = true;
                buf.append("[^A-Z]*");
            }
            buf.append(ch);
        }

        if (seenUpperCase) {
            // match anything at the end!
            buf.append(".*");
            try {
                return Pattern.compile(buf.toString());
            } catch (Exception exp) {
            }
        }

        return null;
    }

    /**
     * Returns the list of properties of the given object that start with the given prefix.
     *
     * @param obj object whose property list is returned
     * @param prefix property prefix to be matched
     * @return the list of properties of the given object
     */
    List<String> getProperties(final Object obj, final String prefix) {
        assert prefix != null && !prefix.isEmpty();
        List<String> allProps = getProperties(obj);
        List<String> props = allProps.stream()
                   .filter(s -> s.startsWith(prefix))
                   .collect(Collectors.toList());

        // If no match, try CamelCase completion..
        if (props.isEmpty()) {
            final Pattern pat = makeCamelCasePattern(prefix);
            if (pat != null) {
                return allProps.stream()
                    .filter(s -> pat.matcher(s).matches())
                    .collect(Collectors.toList());
            }
        }

        return props;
    }
}

jdk/nashorn/tools/jjs/PropertiesHelper.java

 

Or download all of them as a single archive file:

File name: jdk.scripting.nashorn.shell-11.0.1-src.zip
File size: 22002 bytes
Release date: 2018-11-04
Download 

 

JDK 11 jdk.sctp.jmod - SCTP Module

JDK 11 jdk.scripting.nashorn.jmod - Scripting Nashorn Module

Download and Use JDK 11

⇑⇑ FAQ for JDK (Java Development Kit)

2019-12-02, 5942👍, 0💬