< prev index next >

src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java

Print this page




3482         }
3483     }
3484 
3485     /**
3486      * Convert a diagnostic into a list of pretty displayable strings with
3487      * source context.
3488      *
3489      * @param source the source line for the error/warning
3490      * @param diag the diagnostic to convert
3491      * @param toDisplay a list that the displayable strings are added to
3492      */
3493     private void displayableDiagnostic(String source, Diag diag, List<String> toDisplay) {
3494         for (String line : diag.getMessage(null).split("\\r?\\n")) { // TODO: Internationalize
3495             if (!line.trim().startsWith("location:")) {
3496                 toDisplay.add(line);
3497             }
3498         }
3499 
3500         int pstart = (int) diag.getStartPosition();
3501         int pend = (int) diag.getEndPosition();
3502         if (pstart < 0 || pend < 0) {
3503             pstart = 0;
3504             pend = source.length();
3505         }
3506         Matcher m = LINEBREAK.matcher(source);
3507         int pstartl = 0;
3508         int pendl = -2;
3509         while (m.find(pstartl)) {
3510             pendl = m.start();
3511             if (pendl >= pstart) {
3512                 break;
3513             } else {
3514                 pstartl = m.end();
3515             }
3516         }
3517         if (pendl < pstartl) {
3518             pendl = source.length();
3519         }
3520         toDisplay.add(source.substring(pstartl, pendl));
3521 
3522         StringBuilder sb = new StringBuilder();
3523         int start = pstart - pstartl;
3524         for (int i = 0; i < start; ++i) {
3525             sb.append(' ');
3526         }
3527         sb.append('^');
3528         boolean multiline = pend > pendl;
3529         int end = (multiline ? pendl : pend) - pstartl - 1;
3530         if (end > start) {
3531             for (int i = start + 1; i < end; ++i) {
3532                 sb.append('-');
3533             }
3534             if (multiline) {
3535                 sb.append("-...");
3536             } else {
3537                 sb.append('^');




3482         }
3483     }
3484 
3485     /**
3486      * Convert a diagnostic into a list of pretty displayable strings with
3487      * source context.
3488      *
3489      * @param source the source line for the error/warning
3490      * @param diag the diagnostic to convert
3491      * @param toDisplay a list that the displayable strings are added to
3492      */
3493     private void displayableDiagnostic(String source, Diag diag, List<String> toDisplay) {
3494         for (String line : diag.getMessage(null).split("\\r?\\n")) { // TODO: Internationalize
3495             if (!line.trim().startsWith("location:")) {
3496                 toDisplay.add(line);
3497             }
3498         }
3499 
3500         int pstart = (int) diag.getStartPosition();
3501         int pend = (int) diag.getEndPosition();




3502         Matcher m = LINEBREAK.matcher(source);
3503         int pstartl = 0;
3504         int pendl = -2;
3505         while (m.find(pstartl)) {
3506             pendl = m.start();
3507             if (pendl >= pstart) {
3508                 break;
3509             } else {
3510                 pstartl = m.end();
3511             }
3512         }
3513         if (pendl < pstart) {
3514             pendl = source.length();
3515         }
3516         toDisplay.add(source.substring(pstartl, pendl));
3517 
3518         StringBuilder sb = new StringBuilder();
3519         int start = pstart - pstartl;
3520         for (int i = 0; i < start; ++i) {
3521             sb.append(' ');
3522         }
3523         sb.append('^');
3524         boolean multiline = pend > pendl;
3525         int end = (multiline ? pendl : pend) - pstartl - 1;
3526         if (end > start) {
3527             for (int i = start + 1; i < end; ++i) {
3528                 sb.append('-');
3529             }
3530             if (multiline) {
3531                 sb.append("-...");
3532             } else {
3533                 sb.append('^');


< prev index next >