1 29 30 package com.caucho.java; 31 32 import com.caucho.util.IntMap; 33 import com.caucho.vfs.WriteStream; 34 35 import java.io.IOException ; 36 import java.util.Iterator ; 37 38 41 public class LineMapWriter { 42 private WriteStream _os; 43 private String _sourceType = "JSP"; 44 45 48 public LineMapWriter(WriteStream os) 49 { 50 _os = os; 51 } 52 53 56 public void setSourceType(String type) 57 { 58 _sourceType = type; 59 } 60 61 64 public void write(LineMap lineMap) 65 throws IOException 66 { 67 _os.println("SMAP"); 68 _os.println(lineMap.getDestFilename()); 69 _os.println(_sourceType); 70 _os.println("*S " + _sourceType); 71 72 IntMap fileMap = new IntMap(); 73 74 _os.println("*F"); 75 Iterator <LineMap.Line> iter = lineMap.iterator(); 76 while (iter.hasNext()) { 77 LineMap.Line line = iter.next(); 78 79 String filename = line.getSourceFilename(); 80 int index = fileMap.get(filename); 81 if (index < 0) { 82 index = fileMap.size() + 1; 83 fileMap.put(filename, index); 84 85 if (filename.indexOf('/') >= 0) { 86 int p = filename.lastIndexOf('/'); 87 88 _os.println("+ " + index + " " + filename.substring(p + 1)); 89 91 if (filename.startsWith("/")) 92 _os.println(filename.substring(1)); 93 else 94 _os.println(filename); 95 } 96 else 97 _os.println(index + " " + filename); 98 } 99 } 100 101 _os.println("*L"); 102 int size = lineMap.size(); 103 int lastIndex = 0; 104 for (int i = 0; i < size; i++) { 105 LineMap.Line line = lineMap.get(i); 106 107 String filename = line.getSourceFilename(); 108 int index = fileMap.get(filename); 109 110 String fileMarker = ""; 111 112 _os.print(line.getSourceLine()); 113 _os.print("#" + index); 114 115 if (line.getRepeatCount() > 1) 116 _os.print("," + line.getRepeatCount()); 117 118 _os.print(":"); 119 _os.print(line.getDestinationLine()); 120 if (line.getDestinationIncrement() > 1) 121 _os.print("," + line.getDestinationIncrement()); 122 _os.println(); 123 } 124 125 _os.println("*E"); 126 } 127 } 128 | Popular Tags |