< prev index next >

src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysis.java

Print this page




  57      * @param cursor the current position of the cursors in the given {@code input} text
  58      * @param anchor outgoing parameter - when an option will be completed, the text between
  59      *               the anchor and cursor will be deleted and replaced with the given option
  60      * @return list of candidate continuations of the given input.
  61      */
  62     public abstract List<Suggestion> completionSuggestions(String input, int cursor, int[] anchor);
  63 
  64     /**
  65      * Compute a description/help string for the given user's input.
  66      * @param input the snippet the user wrote so far
  67      * @param cursor the current position of the cursors in the given {@code input} text
  68      * @return description/help string for the given user's input
  69      */
  70     public abstract String documentation(String input, int cursor);
  71 
  72     /**
  73      * Internal only constructor
  74      */
  75     SourceCodeAnalysis() {}
  76 


















  77     /**
  78      * The result of <code>analyzeCompletion(String input)</code>.
  79      * Describes the completeness and position of the first snippet in the given input.
  80      */
  81     public static class CompletionInfo {
  82 
  83         public CompletionInfo(Completeness completeness, int unitEndPos, String source, String remaining) {
  84             this.completeness = completeness;
  85             this.unitEndPos = unitEndPos;
  86             this.source = source;
  87             this.remaining = remaining;
  88         }
  89 
  90         /**
  91          * The analyzed completeness of the input.
  92          */
  93         public final Completeness completeness;
  94 
  95         /**
  96          * The end of the first unit of source.


 181          * @param continuation a candidate continuation of the user's input
 182          * @param isSmart is the candidate "smart"
 183          */
 184         public Suggestion(String continuation, boolean isSmart) {
 185             this.continuation = continuation;
 186             this.isSmart = isSmart;
 187         }
 188 
 189         /**
 190          * The candidate continuation of the given user's input.
 191          */
 192         public final String continuation;
 193 
 194         /**
 195          * Is it an input continuation that matches the target type and is thus more
 196          * likely to be the desired continuation. A smart continuation
 197          * is preferred.
 198          */
 199         public final boolean isSmart;
 200     }




















































 201 }


  57      * @param cursor the current position of the cursors in the given {@code input} text
  58      * @param anchor outgoing parameter - when an option will be completed, the text between
  59      *               the anchor and cursor will be deleted and replaced with the given option
  60      * @return list of candidate continuations of the given input.
  61      */
  62     public abstract List<Suggestion> completionSuggestions(String input, int cursor, int[] anchor);
  63 
  64     /**
  65      * Compute a description/help string for the given user's input.
  66      * @param input the snippet the user wrote so far
  67      * @param cursor the current position of the cursors in the given {@code input} text
  68      * @return description/help string for the given user's input
  69      */
  70     public abstract String documentation(String input, int cursor);
  71 
  72     /**
  73      * Internal only constructor
  74      */
  75     SourceCodeAnalysis() {}
  76 
  77     /**Infer the type of the given expression. Returns null if the type of the expression cannot
  78      * be inferred.
  79      *
  80      * @param code the expression for which the type should be inferred
  81      * @param cursor current cursor position in the given code
  82      * @return the inferred type, or null if it cannot be inferred
  83      */
  84     public abstract String analyzeType(String code, int cursor);
  85 
  86     /**List the possible FQNs for an identifier in the given code immediately
  87      * to the right of the given cursor position.
  88      *
  89      * @param code the expression for which the candidate FQNs should be computed
  90      * @param cursor current cursor position in the given code
  91      * @return the gathered FQNs
  92      */
  93     public abstract IndexResult getDeclaredSymbols(String code, int cursor);
  94 
  95     /**
  96      * The result of <code>analyzeCompletion(String input)</code>.
  97      * Describes the completeness and position of the first snippet in the given input.
  98      */
  99     public static class CompletionInfo {
 100 
 101         public CompletionInfo(Completeness completeness, int unitEndPos, String source, String remaining) {
 102             this.completeness = completeness;
 103             this.unitEndPos = unitEndPos;
 104             this.source = source;
 105             this.remaining = remaining;
 106         }
 107 
 108         /**
 109          * The analyzed completeness of the input.
 110          */
 111         public final Completeness completeness;
 112 
 113         /**
 114          * The end of the first unit of source.


 199          * @param continuation a candidate continuation of the user's input
 200          * @param isSmart is the candidate "smart"
 201          */
 202         public Suggestion(String continuation, boolean isSmart) {
 203             this.continuation = continuation;
 204             this.isSmart = isSmart;
 205         }
 206 
 207         /**
 208          * The candidate continuation of the given user's input.
 209          */
 210         public final String continuation;
 211 
 212         /**
 213          * Is it an input continuation that matches the target type and is thus more
 214          * likely to be the desired continuation. A smart continuation
 215          * is preferred.
 216          */
 217         public final boolean isSmart;
 218     }
 219 
 220     /**List of possible qualified names.
 221      */
 222     public static final class IndexResult {
 223 
 224         private final List<String> fqns;
 225         private final int simpleNameLength;
 226         private final boolean upToDate;
 227         private final boolean resolvable;
 228 
 229         public IndexResult(List<String> fqns, int simpleNameLength, boolean upToDate, boolean resolvable) {
 230             this.fqns = fqns;
 231             this.simpleNameLength = simpleNameLength;
 232             this.upToDate = upToDate;
 233             this.resolvable = resolvable;
 234         }
 235 
 236         /**Candidate fully qualified names (FQNs).
 237          *
 238          * @return possible fully qualified names
 239          */
 240         public List<String> getFqns() {
 241             return fqns;
 242         }
 243 
 244         /**The length of the unresolvable simple name in the original code for which the
 245          * FQNs where computed.
 246          *
 247          * @return the length of the simple name; -1 if there is no name right left to the cursor for
 248          *         which the candidates could be computed
 249          */
 250         public int getSimpleNameLength() {
 251             return simpleNameLength;
 252         }
 253 
 254         /**Whether the result is based on up to date data.
 255          *
 256          * @return true iff the results is based on up-to-date data
 257          */
 258         public boolean isUpToDate() {
 259             return upToDate;
 260         }
 261 
 262         /**The given identifier refers to a resolvable element.
 263          *
 264          * @return true iff the given identifier refers to a resolvable element
 265          */
 266         public boolean isResolvable() {
 267             return resolvable;
 268         }
 269 
 270     }
 271 }
< prev index next >