KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > java > LineMapWriter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

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 JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 /**
39  * LineMapWriter writes the *.map files.
40  */

41 public class LineMapWriter {
42   private WriteStream _os;
43   private String JavaDoc _sourceType = "JSP";
44
45   /**
46    * Creates the writer.
47    */

48   public LineMapWriter(WriteStream os)
49   {
50     _os = os;
51   }
52
53   /**
54    * Sets the source-type, e.g. JSP
55    */

56   public void setSourceType(String JavaDoc type)
57   {
58     _sourceType = type;
59   }
60
61   /**
62    * Writes the line map
63    */

64   public void write(LineMap lineMap)
65     throws IOException JavaDoc
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 JavaDoc<LineMap.Line> iter = lineMap.iterator();
76     while (iter.hasNext()) {
77       LineMap.Line line = iter.next();
78
79       String JavaDoc 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           // XXX: _os.println(filename);
90

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 JavaDoc filename = line.getSourceFilename();
108       int index = fileMap.get(filename);
109
110       String JavaDoc 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