01: /*
02: * ObjCTag.java
03: *
04: * Copyright (C) 2003-2004 Peter Graves
05: * $Id: ObjCTag.java,v 1.2 2004/01/04 01:38:00 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: public final class ObjCTag extends LocalTag {
25: public ObjCTag(String name, Position pos) {
26: super (name, pos);
27: canonicalSignature = parseCanonicalSignatureForMethod();
28: }
29:
30: public String getMethodName() {
31: int index = name.indexOf(':');
32: return index >= 0 ? name.substring(0, index) : name;
33: }
34:
35: public String getLongName() {
36: return canonicalSignature;
37: }
38:
39: public String toString() {
40: return name;
41: }
42:
43: public String getSidebarText() {
44: return name;
45: }
46:
47: private String parseCanonicalSignatureForMethod() {
48: FastStringBuffer sb = new FastStringBuffer();
49: Position pos = getPosition().copy();
50: pos.setOffset(0);
51: while (Character.isWhitespace(pos.getChar()))
52: if (!pos.next())
53: return null;
54: char lastChar = 0;
55: char c;
56: while ((c = pos.getChar()) != '{') {
57: if (c == '/') {
58: if (!pos.next())
59: return null;
60: skipComment(pos);
61: if (pos.atEnd())
62: return null;
63: continue;
64: }
65: if (c == '\n' || c == '\t')
66: c = ' ';
67: if (c != ' ' || lastChar != ' ') {
68: sb.append(c);
69: lastChar = c;
70: }
71: if (!pos.next())
72: return null;
73: }
74: return sb.toString().trim();
75: }
76:
77: // On entry, pos points at second char of "//" or "/*" (which might not
78: // actually be '/' or '*').
79: private static void skipComment(Position pos) {
80: char c = pos.getChar();
81: if (!pos.next())
82: return;
83: if (c == '/') {
84: while ((c = pos.getChar()) != '\n')
85: if (!pos.next())
86: return;
87: pos.next();
88: } else if (c == '*') {
89: while (!pos.lookingAt("*/"))
90: if (!pos.next())
91: return;
92: pos.skip(2);
93: }
94: }
95: }
|