Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
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/Corraller.java
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package jdk.jshell;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.JCTree.Visitor;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import static com.sun.tools.javac.code.Flags.FINAL;
import static com.sun.tools.javac.code.Flags.PUBLIC;
import static com.sun.tools.javac.code.Flags.STATIC;
import static com.sun.tools.javac.code.Flags.INTERFACE;
import static com.sun.tools.javac.code.Flags.ENUM;
import static com.sun.tools.javac.code.Flags.RECORD;
import static com.sun.tools.javac.code.Flags.SYNTHETIC;
import com.sun.tools.javac.tree.JCTree.Tag;
import com.sun.tools.javac.tree.TreeInfo;
import jdk.jshell.Wrap.CompoundWrap;
import jdk.jshell.Wrap.Range;
import jdk.jshell.Wrap.RangeWrap;
import java.util.Set;
/**
* Produce a corralled version of the Wrap for a snippet.
*/
class Corraller extends Visitor {
/** Visitor result field: a Wrap
*/
protected Wrap result;
private final TreeDissector dis;
private final String resolutionExceptionBlock;
private final String source;
public Corraller(TreeDissector dis, int keyIndex, String source) {
this.dis = dis;
this.resolutionExceptionBlock = "\n { throw new jdk.jshell.spi.SPIResolutionException(" + keyIndex + "); }";
this.source = source;
}
public Wrap corralType(ClassTree tree) {
return corralToWrap(tree);
}
public Wrap corralMethod(MethodTree tree) {
return corralToWrap(tree);
}
private Wrap corralToWrap(Tree tree) {
try {
JCTree jct = (JCTree) tree;
Wrap w = new CompoundWrap(
" public static\n ",
corral(jct));
debugWrap("corralToWrap SUCCESS source: %s -- wrap:\n %s\n", tree, w.wrapped());
return w;
} catch (Exception ex) {
debugWrap("corralToWrap FAIL: %s - %s\n", tree, ex);
//ex.printStackTrace(System.err);
return null;
}
}
// Corral a single node.
// @SuppressWarnings("unchecked")
private <T extends JCTree> Wrap corral(T tree) {
if (tree == null) {
return null;
} else {
tree.accept(this);
Wrap tmpResult = this.result;
this.result = null;
return tmpResult;
}
}
private String defaultConstructor(JCClassDecl tree) {
return " public " + tree.name.toString() + "() " +
resolutionExceptionBlock;
}
/* ***************************************************************************
* Visitor methods
****************************************************************************/
@Override
public void visitClassDef(JCClassDecl tree) {
boolean isEnum = (tree.mods.flags & ENUM) != 0;
boolean isInterface = (tree.mods.flags & INTERFACE ) != 0;
boolean isRecord = (tree.mods.flags & RECORD ) != 0;
int classBegin = dis.getStartPosition(tree);
int classEnd = dis.getEndPosition(tree);
//debugWrap("visitClassDef: %d-%d = %s\n", classBegin, classEnd, source.substring(classBegin, classEnd));
ListBuffer<Object> wrappedDefs = new ListBuffer<>();
int bodyBegin = -1;
if (tree.defs != null && !tree.defs.isEmpty()) {
if (isEnum) {
// copy the enum constants verbatim
int enumBegin = dis.getStartPosition(tree.defs.head);
JCTree t = null; // null to shut-up compiler, always set because non-empty
List<? extends JCTree> l = tree.defs;
for (; l.nonEmpty(); l = l.tail) {
t = l.head;
if (t.getKind() == Kind.VARIABLE) {
if ((((JCVariableDecl)t).mods.flags & (PUBLIC | STATIC | FINAL)) != (PUBLIC | STATIC | FINAL)) {
// non-enum constant, process normally
break;
}
} else {
// non-variable, process normally
break;
}
}
int constEnd = l.nonEmpty() // end of constants
? dis.getStartPosition(l.head) - 1 // is one before next defs, if there is one
: dis.getEndPosition(t); // and otherwise end of the last constant
wrappedDefs.append(new RangeWrap(source, new Range(enumBegin, constEnd)));
// handle any other defs
for (; l.nonEmpty(); l = l.tail) {
wrappedDefs.append("\n");
t = l.head;
wrappedDefs.append(corral(t));
}
} else {
// non-enum
boolean constructorSeen = false;
for (List<? extends JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
JCTree t = l.head;
if (isRecord && t.hasTag(Tag.VARDEF) && (TreeInfo.flags(t) & RECORD) != 0) {
//record parameters are part of the record's header
continue;
}
wrappedDefs.append("\n ");
switch (t.getKind()) {
case METHOD:
constructorSeen = constructorSeen || ((MethodTree)t).getName() == tree.name.table.names.init;
break;
case BLOCK:
// throw exception in instance initializer too -- inline because String not Wrap
wrappedDefs.append((((JCBlock)t).flags & STATIC) != 0
? new RangeWrap(source, dis.treeToRange(t))
: resolutionExceptionBlock);
continue; // already appended, skip append below
}
wrappedDefs.append(corral(t));
}
if (!constructorSeen && isRecord) {
// Generate a default constructor, since
// this is a regular record and there are no constructors
if (wrappedDefs.length() > 0) {
wrappedDefs.append("\n ");
}
wrappedDefs.append(" public " + tree.name.toString() + " " + resolutionExceptionBlock);
} else if (!constructorSeen && !isInterface && !isEnum) {
// Generate a default constructor, since
// this is a regular class and there are no constructors
if (wrappedDefs.length() > 0) {
wrappedDefs.append("\n ");
}
wrappedDefs.append(defaultConstructor(tree));
}
}
if (!isRecord) {
bodyBegin = dis.getStartPosition(tree.defs.head);
}
}
Object defs = wrappedDefs.length() == 1
? wrappedDefs.first()
: new CompoundWrap(wrappedDefs.toArray());
if (bodyBegin < 0) {
int brace = source.indexOf('{', classBegin);
if (brace < 0 || brace >= classEnd) {
throw new IllegalArgumentException("No brace found: " + source.substring(classBegin, classEnd));
}
bodyBegin = brace + 1;
}
// body includes openning brace
result = new CompoundWrap(
new RangeWrap(source, new Range(classBegin, bodyBegin)),
defs,
"\n}"
);
}
// Corral the body
@Override
public void visitMethodDef(JCMethodDecl tree) {
int methodBegin = dis.getStartPosition(tree);
int methodEnd = dis.getEndPosition(tree);
//debugWrap("+visitMethodDef: %d-%d = %s\n", methodBegin, methodEnd,
// source.substring(methodBegin, methodEnd));
int bodyBegin = dis.getStartPosition(tree.getBody());
if (bodyBegin < 0) {
bodyBegin = source.indexOf('{', methodBegin);
if (bodyBegin > methodEnd) {
bodyBegin = -1;
}
}
String adjustedSource;
if (bodyBegin < 0) {
adjustedSource = new MaskCommentsAndModifiers(source, Set.of("abstract")).cleared();
bodyBegin = adjustedSource.charAt(methodEnd - 1) == ';'
? methodEnd - 1
: methodEnd;
} else {
adjustedSource = source;
}
debugWrap("-visitMethodDef BEGIN: %d = '%s'\n", bodyBegin,
adjustedSource.substring(methodBegin, bodyBegin));
Range noBodyRange = new Range(methodBegin, bodyBegin);
result = new CompoundWrap(
new RangeWrap(adjustedSource, noBodyRange),
resolutionExceptionBlock);
}
// Remove initializer, if present
@Override
public void visitVarDef(JCVariableDecl tree) {
int begin = dis.getStartPosition(tree);
int end = dis.getEndPosition(tree);
if (tree.init == null) {
result = new RangeWrap(source, new Range(begin, end));
} else {
int sinit = dis.getStartPosition(tree.init);
int eq = source.lastIndexOf('=', sinit);
if (eq < begin) {
throw new IllegalArgumentException("Equals not found before init: " + source + " @" + sinit);
}
result = new CompoundWrap(new RangeWrap(source, new Range(begin, eq - 1)), ";");
}
}
@Override
public void visitTree(JCTree tree) {
throw new IllegalArgumentException("Unexpected tree: " + tree);
}
void debugWrap(String format, Object... args) {
//state.debug(this, InternalDebugControl.DBG_WRAP, format, args);
}
}
⏎ jdk/jshell/Corraller.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
2023-08-03, ≈16🔥, 0💬
Popular Posts:
How to show the XML parsing flow with sax\DocumentTracer.java provided in the Apache Xerces package?...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
What Is ojdbc7.jar for Oracle 12c R1? ojdbc7.jar for Oracle 12c R1 is the JAR files of ojdbc.jar, JD...
What Is poi-3.5.jar - Part 2? poi-3.5.jar is one of the JAR files for Apache POI 3.5, which provides...