KickJava   Java API By Example, From Geeks To Geeks.

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


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