langtools/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java
author rfield
Wed, 16 Aug 2017 18:42:11 -0700
changeset 46185 f4c981fc7818
parent 43770 a321bed02000
child 46921 9ce97d94faa6
permissions -rw-r--r--
8182270: JShell API: Tools need snippet information without evaluating snippet 8166334: jshell tool: shortcut: expression/statement to method Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
package jdk.jshell;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
39370
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
    28
import java.util.Collection;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
/**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
 * Provides analysis utilities for source code input.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
 * Optional functionality that provides for a richer interactive experience.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
 * Includes completion analysis:
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 * Is the input a complete snippet of code?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
 * Do I need to prompt for more input?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
 * Would adding a semicolon make it complete?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
 * Is there more than one snippet?
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
 * etc.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
 * Also includes completion suggestions, as might be used in tab-completion.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
 *
43770
a321bed02000 8174762: JShell: @since tags missing
rfield
parents: 41865
diff changeset
    42
 * @since 9
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
public abstract class SourceCodeAnalysis {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
     * Given an input string, find the first snippet of code (one statement,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
     * definition, import, or expression) and evaluate if it is complete.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
     * @param input the input source string
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
     * @return a CompletionInfo instance with location and completeness info
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
    public abstract CompletionInfo analyzeCompletion(String input);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
     * Compute possible follow-ups for the given input.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
    56
     * Uses information from the current {@code JShell} state, including
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
     * type information, to filter the suggestions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
     * @param input the user input, so far
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
     * @param cursor the current position of the cursors in the given {@code input} text
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
     * @param anchor outgoing parameter - when an option will be completed, the text between
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
     *               the anchor and cursor will be deleted and replaced with the given option
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
     * @return list of candidate continuations of the given input.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
    public abstract List<Suggestion> completionSuggestions(String input, int cursor, int[] anchor);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
    /**
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    67
     * Compute documentation for the given user's input. Multiple {@code Documentation} objects may
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    68
     * be returned when multiple elements match the user's input (like for overloaded methods).
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
     * @param input the snippet the user wrote so far
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
     * @param cursor the current position of the cursors in the given {@code input} text
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    71
     * @param computeJavadoc true if the javadoc for the given input should be computed in
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    72
     *                       addition to the signature
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    73
     * @return the documentations for the given user's input, if multiple elements match the input,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    74
     *         multiple {@code Documentation} objects are returned.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
     */
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
    76
    public abstract List<Documentation> documentation(String input, int cursor, boolean computeJavadoc);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
    /**
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    79
     * Infer the type of the given expression. The expression spans from the beginning of {@code code}
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    80
     * to the given {@code cursor} position. Returns null if the type of the expression cannot
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    81
     * be inferred.
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    82
     *
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    83
     * @param code the expression for which the type should be inferred
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    84
     * @param cursor current cursor position in the given code
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    85
     * @return the inferred type, or null if it cannot be inferred
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    86
     */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    87
    public abstract String analyzeType(String code, int cursor);
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    88
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    89
    /**
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    90
     * List qualified names known for the simple name in the given code immediately
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    91
     * to the left of the given cursor position. The qualified names are gathered by inspecting the
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    92
     * classpath used by eval (see {@link JShell#addToClasspath(java.lang.String)}).
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    93
     *
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    94
     * @param code the expression for which the candidate qualified names should be computed
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    95
     * @param cursor current cursor position in the given code
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    96
     * @return the known qualified names
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    97
     */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    98
    public abstract QualifiedNames listQualifiedNames(String code, int cursor);
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
    99
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   100
    /**
39370
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   101
     * Returns the wrapper information for the {@code Snippet}. The wrapper changes as
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   102
     * the environment changes, so calls to this method at different times may
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   103
     * yield different results.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   104
     *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   105
     * @param snippet the {@code Snippet} from which to retrieve the wrapper
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   106
     * @return information on the wrapper
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   107
     */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   108
    public abstract SnippetWrapper wrapper(Snippet snippet);
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   109
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   110
    /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   111
     * Returns the wrapper information for the snippet within the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   112
     * input source string.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   113
     * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   114
     * Wrapper information for malformed and incomplete
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   115
     * snippets also generate wrappers. The list is in snippet encounter
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   116
     * order. The wrapper changes as the environment changes, so calls to this
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   117
     * method at different times may yield different results.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   118
     * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   119
     * The input should be
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   120
     * exactly one complete snippet of source code, that is, one expression,
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   121
     * statement, variable declaration, method declaration, class declaration,
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   122
     * or import.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   123
     * To break arbitrary input into individual complete snippets, use
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   124
     * {@link SourceCodeAnalysis#analyzeCompletion(String)}.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   125
     * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   126
     * The wrapper may not match that returned by
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   127
     * {@link SourceCodeAnalysis#wrapper(Snippet) wrapper(Snippet)},
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   128
     * were the source converted to a {@code Snippet}.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   129
     *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   130
     * @param input the source input from which to generate wrappers
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   131
     * @return a list of wrapper information
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   132
     */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   133
    public abstract List<SnippetWrapper> wrappers(String input);
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   134
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   135
    /**
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   136
     * Converts the source code of a snippet into a {@link Snippet} object (or
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   137
     * list of {@code Snippet} objects in the case of some var declarations,
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   138
     * e.g.: int x, y, z;).
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   139
     * Does not install the snippets: declarations are not
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   140
     * accessible by other snippets; imports are not added.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   141
     * Does not execute the snippets.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   142
     * <p>
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   143
     * Queries may be done on the {@code Snippet} object. The {@link Snippet#id()}
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   144
     * will be {@code "*UNASSOCIATED*"}.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   145
     * The returned snippets are not associated with the
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   146
     * {@link JShell} instance, so attempts to pass them to {@code JShell}
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   147
     * methods will throw an {@code IllegalArgumentException}.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   148
     * They will not appear in queries for snippets --
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   149
     * for example, {@link JShell#snippets() }.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   150
     * <p>
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   151
     * Restrictions on the input are as in {@link JShell#eval}.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   152
     * <p>
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   153
     * Only preliminary compilation is performed, sufficient to build the
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   154
     * {@code Snippet}.  Snippets known to be erroneous, are returned as
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   155
     * {@link ErroneousSnippet}, other snippets may or may not be in error.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   156
     * <p>
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   157
     * @param input The input String to convert
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   158
     * @return usually a singleton list of Snippet, but may be empty or multiple
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   159
     * @throws IllegalStateException if the {@code JShell} instance is closed.
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   160
     */
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   161
    public abstract List<Snippet> sourceToSnippets(String input);
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   162
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 43770
diff changeset
   163
    /**
39370
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   164
     * Returns a collection of {@code Snippet}s which might need updating if the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   165
     * given {@code Snippet} is updated. The returned collection is designed to
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   166
     * be inclusive and may include many false positives.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   167
     *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   168
     * @param snippet the {@code Snippet} whose dependents are requested
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   169
     * @return the collection of dependents
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   170
     */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   171
    public abstract Collection<Snippet> dependents(Snippet snippet);
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   172
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   173
    /**
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
     * Internal only constructor
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
    SourceCodeAnalysis() {}
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
    /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   179
     * The result of {@code analyzeCompletion(String input)}.
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   180
     * Describes the completeness of the first snippet in the given input.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
     */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   182
    public interface CompletionInfo {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
         * The analyzed completeness of the input.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   186
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   187
         * @return an enum describing the completeness of the input string.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
         */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   189
        Completeness completeness();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   192
         * Input remaining after the complete part of the source.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   193
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   194
         * @return the portion of the input string that remains after the
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   195
         * complete Snippet
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
         */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   197
        String remaining();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   200
         * Source code for the first Snippet of code input. For example, first
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   201
         * statement, or first method declaration. Trailing semicolons will be
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   202
         * added, as needed.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   203
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   204
         * @return the source of the first encountered Snippet
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
         */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   206
        String source();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
     * Describes the completeness of the given input.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
    public enum Completeness {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
         * The input is a complete source snippet (declaration or statement) as is.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        COMPLETE(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
         * With this addition of a semicolon the input is a complete source snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
         * This will only be returned when the end of input is encountered.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        COMPLETE_WITH_SEMI(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
         * There must be further source beyond the given input in order for it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
         * to be complete.  A semicolon would not complete it.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
         * This will only be returned when the end of input is encountered.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
        DEFINITELY_INCOMPLETE(false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
         * A statement with a trailing (non-terminated) empty statement.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
         * Though technically it would be a complete statement
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
         * with the addition of a semicolon, it is rare
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
         * that that assumption is the desired behavior.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
         * The input is considered incomplete.  Comments and white-space are
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
         * still considered empty.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
        CONSIDERED_INCOMPLETE(false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
         * An empty input.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
         * The input is considered incomplete.  Comments and white-space are
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
         * still considered empty.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
        EMPTY(false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
         * The completeness of the input could not be determined because it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
         * contains errors. Error detection is not a goal of completeness
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
         * analysis, however errors interfered with determining its completeness.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
         * The input is considered complete because evaluating is the best
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
         * mechanism to get error information.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
        UNKNOWN(true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   258
        private final boolean isComplete;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
        Completeness(boolean isComplete) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   261
            this.isComplete = isComplete;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
        }
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   263
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   264
        /**
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   265
         * Indicates whether the first snippet of source is complete.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   266
         * For example, "{@code x=}" is not
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   267
         * complete, but "{@code x=2}" is complete, even though a subsequent line could
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   268
         * make it "{@code x=2+2}". Already erroneous code is marked complete.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   269
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   270
         * @return {@code true} if the input is or begins a complete Snippet;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   271
         * otherwise {@code false}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   272
         */
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   273
        public boolean isComplete() {
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   274
            return isComplete;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   275
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
     * A candidate for continuation of the given user's input.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
     */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   281
    public interface Suggestion {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   283
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   284
         * The candidate continuation of the given user's input.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   285
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   286
         * @return the continuation string
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
         */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   288
        String continuation();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   289
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   291
         * Indicates whether input continuation matches the target type and is thus
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   292
         * more likely to be the desired continuation. A matching continuation is
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   293
         * preferred.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   294
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   295
         * @return {@code true} if this suggested continuation matches the
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   296
         * target type; otherwise {@code false}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
         */
40498
f54048be4a57 8159027: JShell API: SourceCodeAnalysis.Suggestion has constructor, ...
rfield
parents: 39370
diff changeset
   298
        boolean matchesType();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
    }
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   300
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   301
    /**
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   302
     * A documentation for a candidate for continuation of the given user's input.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   303
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   304
    public interface Documentation {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   305
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   306
        /**
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   307
         * The signature of the given element.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   308
         *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   309
         * @return the signature
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   310
         */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   311
        String signature();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   312
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   313
        /**
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   314
         * The javadoc of the given element.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   315
         *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   316
         * @return the javadoc, or null if not found or not requested
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   317
         */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   318
        String javadoc();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   319
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   320
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 40498
diff changeset
   321
    /**
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   322
     * List of possible qualified names.
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   323
     */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   324
    public static final class QualifiedNames {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   325
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   326
        private final List<String> names;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   327
        private final int simpleNameLength;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   328
        private final boolean upToDate;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   329
        private final boolean resolvable;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   330
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   331
        QualifiedNames(List<String> names, int simpleNameLength, boolean upToDate, boolean resolvable) {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   332
            this.names = names;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   333
            this.simpleNameLength = simpleNameLength;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   334
            this.upToDate = upToDate;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   335
            this.resolvable = resolvable;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   336
        }
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   337
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   338
        /**
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   339
         * Known qualified names for the given simple name in the original code.
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   340
         *
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   341
         * @return known qualified names
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   342
         */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   343
        public List<String> getNames() {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   344
            return names;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   345
        }
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   346
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   347
        /**
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   348
         * The length of the simple name in the original code for which the
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   349
         * qualified names where gathered.
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   350
         *
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   351
         * @return the length of the simple name; -1 if there is no name immediately left to the cursor for
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   352
         *         which the candidates could be computed
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   353
         */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   354
        public int getSimpleNameLength() {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   355
            return simpleNameLength;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   356
        }
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   357
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   358
        /**
39370
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   359
         * Indicates whether the result is based on up-to-date data. The
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   360
         * {@link SourceCodeAnalysis#listQualifiedNames(java.lang.String, int) listQualifiedNames}
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   361
         * method may return before the classpath is fully inspected, in which case this method will
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   362
         * return {@code false}. If the result is based on a fully inspected classpath, this method
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   363
         * will return {@code true}.
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   364
         *
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   365
         * @return {@code true} if the result is based on up-to-date data;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   366
         * otherwise {@code false}
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   367
         */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   368
        public boolean isUpToDate() {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   369
            return upToDate;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   370
        }
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   371
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   372
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   373
         * Indicates whether the given simple name in the original code refers
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   374
         * to a resolvable element.
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   375
         *
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   376
         * @return {@code true} if the given simple name in the original code
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 36160
diff changeset
   377
         * refers to a resolvable element; otherwise {@code false}
36160
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   378
         */
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   379
        public boolean isResolvable() {
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   380
            return resolvable;
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   381
        }
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   382
f42d362d0d17 8131027: JShell API/tool: suggest imports for a class
jlahoda
parents: 33362
diff changeset
   383
    }
39370
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   384
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   385
    /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   386
     * The wrapping of a snippet of Java source into valid top-level Java
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   387
     * source. The wrapping will always either be an import or include a
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   388
     * synthetic class at the top-level. If a synthetic class is generated, it
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   389
     * will be proceeded by the package and import declarations, and may contain
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   390
     * synthetic class members.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   391
     * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   392
     * This interface, in addition to the mapped form, provides the context and
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   393
     * position mapping information.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   394
     */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   395
    public interface SnippetWrapper {
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   396
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   397
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   398
         * Returns the input that is wrapped. For
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   399
         * {@link SourceCodeAnalysis#wrappers(java.lang.String) wrappers(String)},
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   400
         * this is the source of the snippet within the input. A variable
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   401
         * declaration of {@code N} variables will map to {@code N} wrappers
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   402
         * with the source separated.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   403
         * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   404
         * For {@link SourceCodeAnalysis#wrapper(Snippet) wrapper(Snippet)},
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   405
         * this is {@link Snippet#source() }.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   406
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   407
         * @return the input source corresponding to the wrapper.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   408
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   409
        String source();
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   410
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   411
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   412
         * Returns a Java class definition that wraps the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   413
         * {@link SnippetWrapper#source()} or, if an import, the import source.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   414
         * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   415
         * If the input is not a valid Snippet, this will not be a valid
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   416
         * class/import definition.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   417
         * <p>
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   418
         * The source may be divided and mapped to different locations within
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   419
         * the wrapped source.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   420
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   421
         * @return the source wrapped into top-level Java code
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   422
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   423
        String wrapped();
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   424
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   425
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   426
         * Returns the fully qualified class name of the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   427
         * {@link SnippetWrapper#wrapped() } class.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   428
         * For erroneous input, a best guess is returned.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   429
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   430
         * @return the name of the synthetic wrapped class; if an import, the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   431
         * name is not defined
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   432
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   433
        String fullClassName();
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   434
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   435
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   436
         * Returns the {@link Snippet.Kind} of the
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   437
         * {@link SnippetWrapper#source()}.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   438
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   439
         * @return an enum representing the general kind of snippet.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   440
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   441
        Snippet.Kind kind();
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   442
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   443
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   444
         * Maps character position within the source to character position
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   445
         * within the wrapped.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   446
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   447
         * @param pos the position in {@link SnippetWrapper#source()}
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   448
         * @return the corresponding position in
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   449
         * {@link SnippetWrapper#wrapped() }
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   450
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   451
        int sourceToWrappedPosition(int pos);
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   452
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   453
        /**
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   454
         * Maps character position within the wrapped to character position
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   455
         * within the source.
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   456
         *
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   457
         * @param pos the position in {@link SnippetWrapper#wrapped()}
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   458
         * @return the corresponding position in
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   459
         * {@link SnippetWrapper#source() }
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   460
         */
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   461
        int wrappedToSourcePosition(int pos);
437ba9bd2582 8159111: JShell API: Add access to wrappers and dependencies
rfield
parents: 38908
diff changeset
   462
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
}