01: /*
02: * Tagger.java
03: *
04: * Copyright (C) 1998-2003 Peter Graves
05: * $Id: Tagger.java,v 1.6 2003/10/11 17:26:32 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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;
25: import java.io.IOException;
26: import java.io.Writer;
27: import java.util.List;
28:
29: public abstract class Tagger implements Constants, Runnable {
30: public static final char separatorChar = 0;
31:
32: protected SystemBuffer buffer;
33:
34: protected Tagger(SystemBuffer buffer) {
35: this .buffer = buffer;
36: }
37:
38: public void writeTags(Writer writer) {
39: if (buffer == null)
40: return;
41: List tags = buffer.getTags();
42: if (tags == null)
43: return;
44: File file = buffer.getFile();
45: if (file == null)
46: return;
47: final String canonicalPath = file.canonicalPath();
48: try {
49: for (int i = 0, limit = tags.size(); i < limit; i++) {
50: LocalTag localTag = (LocalTag) tags.get(i);
51: if (localTag != null) {
52: switch (localTag.getType()) {
53: case TAG_INTERFACE:
54: case TAG_CLASS:
55: case TAG_METHOD:
56: case TAG_EXPLICIT:
57: case TAG_DEFUN: // Lisp.
58: case TAG_GENERIC_FUNCTION: // Lisp.
59: case TAG_MACRO: // Lisp.
60: case TAG_STRUCT: // Lisp.
61: writer.write(localTag.getName());
62: writer.write(separatorChar);
63: writer.write(canonicalPath);
64: writer.write(separatorChar);
65: writer.write(localTag.getLine().getText());
66: final String canonicalSignature = localTag
67: .getCanonicalSignature();
68: if (canonicalSignature != null) {
69: writer.write(separatorChar);
70: writer.write(canonicalSignature);
71: }
72: writer.write('\n');
73: break;
74: default:
75: break;
76: }
77: }
78: }
79: writer.flush();
80: } catch (IOException e) {
81: Log.error(e);
82: }
83: }
84:
85: public abstract void run();
86: }
|