01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.pretty;
10:
11: import net.sourceforge.jrefactory.ast.ModifierHolder;
12: import org.acm.seguin.util.FileSettings;
13: import org.acm.seguin.util.SettingNotFoundException;
14:
15: /**
16: * Forces javadoc comments only for a certain level of source code. The level
17: * is based on the permissions associated with the file.
18: *
19: *@author Chris Seguin
20: *@created December 20, 1999
21: */
22: public class ForceJavadocComments {
23: /**
24: * Determines if the java doc comment is required for the particular method
25: * or field
26: *
27: *@param type the type (method or field)
28: *@param mods the modifiers associated with this object
29: *@return true if they are required
30: */
31: public boolean isJavaDocRequired(String type, ModifierHolder mods) {
32: // Get the resource bundle
33: FileSettings bundle = FileSettings.getRefactoryPrettySettings();
34:
35: // Determine the minimum acceptable level
36: String minimumLevel = "none";
37: try {
38: minimumLevel = bundle.getString(type + ".minimum");
39: } catch (SettingNotFoundException snfe) {
40: // Use default value
41: }
42:
43: // Check the level
44: return isAll(minimumLevel) || isPackage(minimumLevel, mods)
45: || isProtected(minimumLevel, mods)
46: || isPublic(minimumLevel, mods);
47: }
48:
49: /**
50: * Gets the All attribute of the ForceJavadocComments object
51: *
52: *@param level Description of Parameter
53: *@return The All value
54: */
55: private boolean isAll(String level) {
56: return level.equalsIgnoreCase("all")
57: || level.equalsIgnoreCase("private");
58: }
59:
60: /**
61: * Gets the Package attribute of the ForceJavadocComments object
62: *
63: *@param level Description of Parameter
64: *@param mods Description of Parameter
65: *@return The Package value
66: */
67: private boolean isPackage(String level, ModifierHolder mods) {
68: return (level.equalsIgnoreCase("package") || level
69: .equalsIgnoreCase("default"))
70: && !mods.isPrivate();
71: }
72:
73: /**
74: * Gets the Protected attribute of the ForceJavadocComments object
75: *
76: *@param level Description of Parameter
77: *@param mods Description of Parameter
78: *@return The Protected value
79: */
80: private boolean isProtected(String level, ModifierHolder mods) {
81: return level.equalsIgnoreCase("protected")
82: && (mods.isProtected() || mods.isPublic());
83: }
84:
85: /**
86: * Gets the Public attribute of the ForceJavadocComments object
87: *
88: *@param level Description of Parameter
89: *@param mods Description of Parameter
90: *@return The Public value
91: */
92: private boolean isPublic(String level, ModifierHolder mods) {
93: return level.equalsIgnoreCase("public") && mods.isPublic();
94: }
95:
96: }
|