001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.pretty;
053:
054: import org.acm.seguin.util.FileSettings;
055: import org.acm.seguin.util.MissingSettingsException;
056:
057: /**
058: * Stores all the javadoc tags, rather than getting them directly from the file
059: * settings. This will allow the descriptions to be unit tested.
060: *
061: *@author Chris Seguin
062: *@created November 29, 2001
063: *@since 2.6.32
064: */
065: public class JavadocTags {
066: private boolean debug;
067: private String exceptionDescr;
068: private String exceptionTag;
069: private String paramDescr;
070: private String returnDescr;
071: private String constructorDescr;
072:
073: private static JavadocTags singleton = null;
074:
075: /**
076: * Constructor for the JavadocTags object
077: *
078: *@since 2.6.32
079: */
080: private JavadocTags() {
081: debug = false;
082: paramDescr = "";
083: returnDescr = "";
084: exceptionDescr = "";
085: }
086:
087: /**
088: * Turns debugging on
089: *
090: *@param way The new debug value
091: *@since 2.6.32
092: */
093: public void setDebug(boolean way) {
094: debug = way;
095: }
096:
097: /**
098: * Sets the exceptionDescr attribute of the JavadocTags object
099: *
100: *@param value The new exceptionDescr value
101: *@since 2.6.34
102: */
103: public void setExceptionDescr(String value) {
104: if (value == null)
105: exceptionDescr = "";
106: else
107: exceptionDescr = value;
108: }
109:
110: /**
111: * Sets the exceptionTag attribute of the JavadocTags object
112: *
113: *@param value The new exceptionTag value
114: *@since 2.6.32
115: */
116: public void setExceptionTag(String value) {
117: if ((value == null) || (value.length() == 0)
118: || value.equals("@")) {
119: exceptionTag = "exception";
120: } else if (value.charAt(0) == '@') {
121: exceptionTag = value.substring(1);
122: } else {
123: exceptionTag = value;
124: }
125: }
126:
127: /**
128: * Sets the paramDescr attribute of the JavadocTags object
129: *
130: *@param value The new paramDescr value
131: *@since 2.6.34
132: */
133: public void setParamDescr(String value) {
134: if (value == null) {
135: paramDescr = "";
136: } else {
137: paramDescr = value;
138: }
139: }
140:
141: /**
142: * Sets the returnDescr attribute of the JavadocTags object
143: *
144: *@param value The new returnDescr value
145: *@since 2.6.34
146: */
147: public void setReturnDescr(String value) {
148: if (value == null)
149: returnDescr = "";
150: else
151: returnDescr = value;
152: }
153:
154: /**
155: * Gets the exceptionDescr attribute of the JavadocTags object
156: *
157: *@return The exceptionDescr value
158: *@since 2.6.34
159: */
160: public String getExceptionDescr() {
161: return exceptionDescr;
162: }
163:
164: /**
165: * Gets the exceptionTag attribute of the JavadocTags object
166: *
167: *@return The exceptionTag value
168: *@since 2.6.32
169: */
170: public String getExceptionTag() {
171: return "@" + exceptionTag;
172: }
173:
174: /**
175: * Gets the paramDescr attribute of the JavadocTags object
176: *
177: *@return The paramDescr value
178: *@since 2.6.34
179: */
180: public String getParamDescr() {
181: return paramDescr;
182: }
183:
184: /**
185: * Gets the returnDescr attribute of the JavadocTags object
186: *
187: *@return The returnDescr value
188: *@since 2.6.34
189: */
190: public String getReturnDescr() {
191: return returnDescr;
192: }
193:
194: /**
195: * Gets the exceptionTag attribute of the JavadocTags object
196: *
197: *@param name Description of the Parameter
198: *@return The exceptionTag value
199: *@since 2.6.32
200: */
201: public boolean isExceptionTag(String name) {
202: String temp = name;
203: if (name.charAt(0) == '@') {
204: temp = name.substring(1);
205: }
206:
207: return (exceptionTag.equals(temp) || temp.equals("exception") || temp
208: .equals("throws"));
209: }
210:
211: /**
212: * Gets the debug attribute of the JavadocTags object
213: *
214: *@return The debug value
215: *@since 2.6.32
216: */
217: private boolean isDebug() {
218: return debug;
219: }
220:
221: /**
222: * Reloads from the pretty.settings file
223: *
224: *@since 2.6.32
225: */
226: public void reload() {
227: FileSettings bundle = FileSettings.getRefactoryPrettySettings();
228:
229: try {
230: setExceptionTag(bundle.getString("exception.tag.name"));
231: } catch (MissingSettingsException mse) {
232: setExceptionTag("exception");
233: }
234:
235: try {
236: setExceptionDescr(bundle.getString("exception.descr"));
237: } catch (MissingSettingsException mse) {
238: setExceptionDescr("Description of the exception");
239: }
240:
241: try {
242: setParamDescr(bundle.getString("param.descr"));
243: } catch (MissingSettingsException mse) {
244: setParamDescr("Description of the parameter");
245: }
246:
247: try {
248: setReturnDescr(bundle.getString("return.descr"));
249: } catch (MissingSettingsException mse) {
250: setReturnDescr("Description of the return value");
251: }
252:
253: try {
254: setConstructorDescr(bundle.getString("constructor.descr"));
255: } catch (MissingSettingsException mse) {
256: setConstructorDescr("Constructor for the {0} class");
257: }
258: }
259:
260: /**
261: * Description of the Method
262: *
263: *@return Default description of the Return Value
264: *@since 2.6.32
265: */
266: public static JavadocTags get() {
267: if (singleton == null) {
268: singleton = new JavadocTags();
269: singleton.reload();
270: }
271:
272: return singleton;
273: }
274:
275: public String getConstructorDescr() {
276: return constructorDescr;
277: }
278:
279: public void setConstructorDescr(String value) {
280: if (value == null)
281: constructorDescr = "";
282: else
283: constructorDescr = value;
284: }
285: }
|