001: /*
002: * Helma License Notice
003: *
004: * The contents of this file are subject to the Helma License
005: * Version 2.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://adele.helma.org/download/helma/license.txt
008: *
009: * Copyright 1998-2003 Helma Software. All Rights Reserved.
010: *
011: * $RCSfile$
012: * $Author: root $
013: * $Revision: 8604 $
014: * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
015: */
016:
017: package helma.doc;
018:
019: import java.util.*;
020:
021: /**
022: *
023: */
024: public final class DocTag {
025:
026: // the tag name
027: private String type;
028:
029: // the name of the parameter
030: private String name;
031:
032: // the actual comment
033: private String text;
034:
035: private DocTag(String type, String name, String text) {
036: this .type = type;
037: this .name = (name != null) ? name.trim() : "";
038: this .text = (text != null) ? text.trim() : "";
039: }
040:
041: /**
042: *
043: *
044: * @param rawTag ...
045: *
046: * @return ...
047: *
048: * @throws DocException ...
049: */
050: public static DocTag parse(String rawTag) throws DocException {
051: StringTokenizer tok = new StringTokenizer(rawTag.trim());
052: String name = "";
053: String type = "";
054: StringBuffer comment = new StringBuffer();
055: try {
056: type = matchTagName(tok.nextToken().substring(1));
057: } catch (NoSuchElementException nsee) {
058: throw new DocException("invalid tag: " + rawTag);
059: }
060: try {
061: if (isTagWithName(type)) {
062: name = tok.nextToken();
063: }
064: while (tok.hasMoreTokens()) {
065: comment.append(" ").append(tok.nextToken());
066: }
067: } catch (NoSuchElementException nsee) { // ignore
068: }
069: return new DocTag(type, name, comment.toString());
070: }
071:
072: /**
073: * @param rawTag a line from a helmadoc comment
074: * @return true if the line represents a tag
075: */
076: public static boolean isTagStart(String rawTag) {
077: if (rawTag.trim().startsWith("@"))
078: return true;
079: else
080: return false;
081: }
082:
083: /**
084: * match tags where we want different names to be valid
085: * as one and the same tag
086: * @param tagName original name
087: * @return modified name if tag was matched
088: */
089: public static String matchTagName(String tagName) {
090: if ("returns".equals(tagName)) {
091: return "return";
092: } else if ("arg".equals(tagName)) {
093: return "param";
094: } else {
095: return tagName;
096: }
097: }
098:
099: public static boolean isTagWithName(String tagName) {
100: if ("param".equals(tagName))
101: return true;
102: else
103: return false;
104: }
105:
106: /**
107: *
108: *
109: * @return ...
110: */
111: public String getType() {
112: return type;
113: }
114:
115: /**
116: *
117: *
118: * @return ...
119: */
120: public String getName() {
121: return name;
122: }
123:
124: /**
125: *
126: *
127: * @return ...
128: */
129: public String getText() {
130: return text;
131: }
132:
133: /**
134: *
135: *
136: * @return ...
137: */
138: public String toString() {
139: StringBuffer buf = new StringBuffer("[@" + type);
140: if (name != null && !"".equals(name))
141: buf.append(" ").append(name);
142: if (text != null && !"".equals(text))
143: buf.append(" ").append(text);
144: return buf.toString() + "]";
145: }
146: }
|