Loads SMAP data for the given class by reading the embedded SourceDebugExtension attribute from the class file or an external .smap resource. @param className the fully qualified class name @param cl the class loader to use for loading the resource @return the parsed SmapStratum, or null if
(String className, ClassLoader cl)
| 683 | * @return the parsed SmapStratum, or {@code null} if no or invalid SMAP data is found |
| 684 | */ |
| 685 | public static SmapStratum loadSmap(String className, ClassLoader cl) { |
| 686 | // Extract SMAP from class file. First line "SMAP" is not included |
| 687 | String smap = getSmap(className, cl); |
| 688 | |
| 689 | if (smap == null) { |
| 690 | return null; |
| 691 | } |
| 692 | |
| 693 | SmapStratum smapStratum = new SmapStratum(); |
| 694 | |
| 695 | String[] lines = smap.split("\n"); |
| 696 | int lineIndex = 0; |
| 697 | |
| 698 | // First line is output file name |
| 699 | smapStratum.setOutputFileName(lines[lineIndex]); |
| 700 | |
| 701 | // There is only one stratum (JSP) so skip to the start of the file |
| 702 | // section |
| 703 | lineIndex = 4; |
| 704 | |
| 705 | while (!lines[lineIndex].equals("*L")) { |
| 706 | int i = lines[lineIndex].lastIndexOf(' '); |
| 707 | String fileName = lines[lineIndex].substring(i + 1); |
| 708 | smapStratum.addFile(fileName, lines[++lineIndex]); |
| 709 | lineIndex++; |
| 710 | if (lineIndex == lines.length) { |
| 711 | return null; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | // Skip *L |
| 716 | lineIndex++; |
| 717 | if (lineIndex == lines.length) { |
| 718 | return null; |
| 719 | } |
| 720 | |
| 721 | while (!lines[lineIndex].equals("*E")) { |
| 722 | LineInfo li = new LineInfo(); |
| 723 | // Split into in and out |
| 724 | String[] inOut = lines[lineIndex].split(":"); |
| 725 | // Split in on comma (might not be one) |
| 726 | String[] in = inOut[0].split(","); |
| 727 | if (in.length == 2) { |
| 728 | // There is a count |
| 729 | li.setInputLineCount(Integer.parseInt(in[1])); |
| 730 | } |
| 731 | // Check for fileID |
| 732 | String[] start = in[0].split("#"); |
| 733 | if (start.length == 2) { |
| 734 | // There is a file ID |
| 735 | li.setLineFileID(Integer.parseInt(start[1])); |
| 736 | } |
| 737 | li.setInputStartLine(Integer.parseInt(start[0])); |
| 738 | // Split out |
| 739 | String[] out = inOut[1].split(","); |
| 740 | if (out.length == 2) { |
| 741 | // There is an increment |
| 742 | li.setOutputLineIncrement(Integer.parseInt(out[1])); |
no test coverage detected