KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > Tagger


1 /*
2  * Tagger.java
3  *
4  * Copyright (C) 1998-2003 Peter Graves
5  * $Id: Tagger.java,v 1.6 2003/10/11 17:26:32 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.io.BufferedWriter JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Writer JavaDoc;
27 import java.util.List JavaDoc;
28
29 public abstract class Tagger implements Constants, Runnable JavaDoc
30 {
31     public static final char separatorChar = 0;
32
33     protected SystemBuffer buffer;
34
35     protected Tagger(SystemBuffer buffer)
36     {
37         this.buffer = buffer;
38     }
39
40     public void writeTags(Writer JavaDoc writer)
41     {
42         if (buffer == null)
43             return;
44         List JavaDoc tags = buffer.getTags();
45         if (tags == null)
46             return;
47         File file = buffer.getFile();
48         if (file == null)
49             return;
50         final String JavaDoc canonicalPath = file.canonicalPath();
51         try {
52             for (int i = 0, limit = tags.size(); i < limit; i++) {
53                 LocalTag localTag = (LocalTag) tags.get(i);
54                 if (localTag != null) {
55                     switch (localTag.getType()) {
56                         case TAG_INTERFACE:
57                         case TAG_CLASS:
58                         case TAG_METHOD:
59                         case TAG_EXPLICIT:
60                         case TAG_DEFUN: // Lisp.
61
case TAG_GENERIC_FUNCTION: // Lisp.
62
case TAG_MACRO: // Lisp.
63
case TAG_STRUCT: // Lisp.
64
writer.write(localTag.getName());
65                             writer.write(separatorChar);
66                             writer.write(canonicalPath);
67                             writer.write(separatorChar);
68                             writer.write(localTag.getLine().getText());
69                             final String JavaDoc canonicalSignature =
70                                 localTag.getCanonicalSignature();
71                             if (canonicalSignature != null) {
72                                 writer.write(separatorChar);
73                                 writer.write(canonicalSignature);
74                             }
75                             writer.write('\n');
76                             break;
77                         default:
78                             break;
79                     }
80                 }
81             }
82             writer.flush();
83         }
84         catch (IOException JavaDoc e) {
85             Log.error(e);
86         }
87     }
88
89     public abstract void run();
90 }
91
Popular Tags