langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java
changeset 42827 36468b5fa7f4
parent 42258 a1aafd5ea6ec
child 42843 a8d83044a192
equal deleted inserted replaced
42826:563b42fc70ba 42827:36468b5fa7f4
   123                 if (!Objects.equals(lastTest, test) || lastCursor != cursor)
   123                 if (!Objects.equals(lastTest, test) || lastCursor != cursor)
   124                     allowSmart = true;
   124                     allowSmart = true;
   125 
   125 
   126                 boolean smart = allowSmart &&
   126                 boolean smart = allowSmart &&
   127                                 suggestions.stream()
   127                                 suggestions.stream()
   128                                            .anyMatch(s -> s.matchesType());
   128                                            .anyMatch(Suggestion::matchesType);
   129 
   129 
   130                 lastTest = test;
   130                 lastTest = test;
   131                 lastCursor = cursor;
   131                 lastCursor = cursor;
   132                 allowSmart = !allowSmart;
   132                 allowSmart = !allowSmart;
   133 
   133 
   134                 suggestions.stream()
   134                 suggestions.stream()
   135                            .filter(s -> !smart || s.matchesType())
   135                            .filter(s -> !smart || s.matchesType())
   136                            .map(s -> s.continuation())
   136                            .map(Suggestion::continuation)
   137                            .forEach(result::add);
   137                            .forEach(result::add);
   138 
   138 
   139                 boolean onlySmart = suggestions.stream()
   139                 boolean onlySmart = suggestions.stream()
   140                                                .allMatch(s -> s.matchesType());
   140                                                .allMatch(Suggestion::matchesType);
   141 
   141 
   142                 if (smart && !onlySmart) {
   142                 if (smart && !onlySmart) {
   143                     Optional<String> prefix =
   143                     Optional<String> prefix =
   144                             suggestions.stream()
   144                             suggestions.stream()
   145                                        .map(s -> s.continuation())
   145                                        .map(Suggestion::continuation)
   146                                        .reduce(ConsoleIOContext::commonPrefix);
   146                                        .reduce(ConsoleIOContext::commonPrefix);
   147 
   147 
   148                     String prefixStr = prefix.orElse("").substring(cursor - anchor[0]);
   148                     String prefixStr = prefix.orElse("").substring(cursor - anchor[0]);
   149                     try {
   149                     try {
   150                         in.putString(prefixStr);
   150                         in.putString(prefixStr);
   279         } else {
   279         } else {
   280             JavadocFormatter formatter = new JavadocFormatter(term.getWidth(),
   280             JavadocFormatter formatter = new JavadocFormatter(term.getWidth(),
   281                                                               term.isAnsiSupported());
   281                                                               term.isAnsiSupported());
   282             Function<Documentation, String> convertor;
   282             Function<Documentation, String> convertor;
   283             if (firstInvocation) {
   283             if (firstInvocation) {
   284                 convertor = d -> d.signature();
   284                 convertor = Documentation::signature;
   285             } else {
   285             } else {
   286                 convertor = d -> formatter.formatJavadoc(d.signature(), d.javadoc()) +
   286                 convertor = d -> formatter.formatJavadoc(d.signature(), d.javadoc()) +
   287                                  (d.javadoc() == null ? repl.messageFormat("jshell.console.no.javadoc")
   287                                  (d.javadoc() == null ? repl.messageFormat("jshell.console.no.javadoc")
   288                                                       : "");
   288                                                       : "");
   289             }
   289             }