JDK 17 jdk.jshell.jmod - JShell Tool

JDK 17 jdk.jshell.jmod is the JMOD file for JDK 17 JShell tool, which can be invoked by the "jshell" command.

JDK 17 JShell tool compiled class files are stored in \fyicenter\jdk-17.0.5\jmods\jdk.jshell.jmod.

JDK 17 JShell tool compiled class files are also linked and stored in the \fyicenter\jdk-17.0.5\lib\modules JImage file.

JDK 17 JShell tool source code files are stored in \fyicenter\jdk-17.0.5\lib\src.zip\jdk.jshell.

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

✍: FYIcenter

jdk/jshell/SnippetMaps.java

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

package jdk.jshell;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.stream.Stream;

import static jdk.jshell.Util.PREFIX_PATTERN;
import static jdk.jshell.Util.REPL_PACKAGE;
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_DEP;

/**
 * Maintain relationships between the significant entities: Snippets,
 * internal snippet index, Keys, etc.
 * @author Robert Field
 */
final class SnippetMaps {

    private final List<Snippet> keyIndexToSnippet = new ArrayList<>();
    private final Set<Snippet> snippets = new LinkedHashSet<>();
    private final Map<String, Set<Integer>> dependencies = new HashMap<>();
    private final JShell state;

    SnippetMaps(JShell proc) {
        this.state = proc;
    }

    void installSnippet(Snippet sn) {
        if (sn != null && snippets.add(sn)) {
            if (sn.key() != null) {
                sn.setId((state.idGenerator != null)
                        ? state.idGenerator.apply(sn, sn.key().index())
                        : "" + sn.key().index());
                setSnippet(sn.key().index(), sn);
            }
        }
    }

    private void setSnippet(int ki, Snippet snip) {
        while (ki >= keyIndexToSnippet.size()) {
            keyIndexToSnippet.add(null);
        }
        keyIndexToSnippet.set(ki, snip);
    }

    Snippet getSnippet(Key key) {
        return getSnippet(key.index());
    }

    Snippet getSnippet(int ki) {
        Snippet sn = getSnippetDeadOrAlive(ki);
        return (sn != null && !sn.status().isActive())
                ? null
                : sn;
    }

    Snippet getSnippetDeadOrAlive(int ki) {
        if (ki >= keyIndexToSnippet.size()) {
            return null;
        }
        return keyIndexToSnippet.get(ki);
    }

    List<Snippet> snippetList() {
        return new ArrayList<>(snippets);
    }

    String packageAndImportsExcept(Set<Key> except, Collection<Snippet> plus) {
        StringBuilder sb = new StringBuilder();
        sb.append("package ").append(REPL_PACKAGE).append(";\n");
        for (Snippet si : keyIndexToSnippet) {
            if (si != null && si.status().isDefined() && (except == null || !except.contains(si.key()))) {
                sb.append(si.importLine(state));
            }
        }
        if (plus != null) {
            plus.forEach(psi -> sb.append(psi.importLine(state)));
        }
        return sb.toString();
    }

    List<Snippet> getDependents(Snippet snip) {
        if (!snip.kind().isPersistent()) {
            return Collections.emptyList();
        }
        Set<Integer> depset;
        if (snip.unitName.equals("*")) {
            // star import
            depset = new HashSet<>();
            for (Set<Integer> as : dependencies.values()) {
                depset.addAll(as);
            }
        } else {
            depset = dependencies.get(snip.name());
        }
        if (depset == null) {
            return Collections.emptyList();
        }
        List<Snippet> deps = new ArrayList<>();
        for (Integer dss : depset) {
            Snippet dep = getSnippetDeadOrAlive(dss);
            if (dep != null) {
                deps.add(dep);
                state.debug(DBG_DEP, "Found dependency %s -> %s\n", snip.name(), dep.name());
            }
        }
        return deps;
    }

    void mapDependencies(Snippet snip) {
        addDependencies(snip.declareReferences(), snip);
        addDependencies(snip.bodyReferences(),    snip);
    }

    private void addDependencies(Collection<String> refs, Snippet snip) {
        if (refs == null) return;
        for (String ref : refs) {
            dependencies.computeIfAbsent(ref, k -> new HashSet<>())
                        .add(snip.key().index());
            state.debug(DBG_DEP, "Added dependency %s -> %s\n", ref, snip.name());
        }
    }

    String fullClassNameAndPackageToClass(String full, String pkg) {
        Matcher mat = PREFIX_PATTERN.matcher(full);
        if (mat.lookingAt()) {
            return full.substring(mat.end());
        }
        state.debug(DBG_DEP, "SM %s %s\n", full, pkg);
        List<String> klasses = importSnippets()
                               .filter(isi -> !isi.isStar)
                               .map(isi -> isi.fullname)
                               .toList();
        for (String k : klasses) {
            if (k.equals(full)) {
                return full.substring(full.lastIndexOf(".")+1);
            }
        }
        if (pkg.isEmpty()) {
            return full;
        }
        Stream<String> pkgs = importSnippets()
                               .filter(isi -> isi.isStar)
                               .map(isi -> isi.fullname.substring(0, isi.fullname.lastIndexOf(".")));
        if (Stream.concat(Stream.of("java.lang"), pkgs).anyMatch(pkg::equals)) {
            return full.substring(pkg.length() + 1);
        }
        return full;
    }

    /**
     * Compute the set of imports to prepend to a snippet
     * @return a stream of the import needed
     */
    private Stream<ImportSnippet> importSnippets() {
        return state.keyMap.importKeys()
                .map(key -> (ImportSnippet)getSnippet(key))
                .filter(sn -> sn != null && state.status(sn).isDefined());
    }
}

jdk/jshell/SnippetMaps.java

 

Or download all of them as a single archive file:

File name: jdk.jshell-17.0.5-src.zip
File size: 302589 bytes
Release date: 2022-09-13
Download 

 

JDK 17 jdk.jsobject.jmod - JS Object Module

JDK 17 jdk.jpackage.jmod - JPackage Tool

JDK 17 JMod/Module Files

⇑⇑ FAQ for JDK (Java Development Kit) 17

2023-08-03, 5878👍, 0💬