View Javadoc

1   package net.sourceforge.pmd.ast;
2   
3   public class SimpleJavaAccessNode extends SimpleJavaNode implements AccessNodeInterface {
4   
5   	private int modifiers;
6   
7   	public SimpleJavaAccessNode(int i) {
8   		super(i);
9   	}
10  
11  	public SimpleJavaAccessNode(JavaParser parser, int i) {
12  		super(parser, i);
13  	}
14  
15  	public int getModifiers() {
16  		return this.modifiers;
17  	}
18  
19  	public void setModifiers(int modifiers) {
20  		this.modifiers = modifiers;
21  	}
22  
23  	public boolean isPublic() {
24  		return isModifier(PUBLIC);
25  	}
26  
27  	public void setPublic() {
28  		setPublic(true);
29  	}
30  
31  	public void setPublic(boolean isPublic) {
32  		setModifier(isPublic, PUBLIC);
33  	}
34  
35  	public boolean isProtected() {
36  		return isModifier(PROTECTED);
37  	}
38  
39  	public void setProtected() {
40  		setProtected(true);
41  	}
42  
43  	public void setProtected(boolean isProtected) {
44  		setModifier(isProtected, PROTECTED);
45  	}
46  
47  	public boolean isPrivate() {
48  		return isModifier(PRIVATE);
49  	}
50  
51  	public void setPrivate() {
52  		setPrivate(true);
53  	}
54  
55  	public void setPrivate(boolean isPrivate) {
56  		setModifier(isPrivate, PRIVATE);
57  	}
58  
59  	public boolean isAbstract() {
60  		return isModifier(ABSTRACT);
61  	}
62  
63  	public void setAbstract() {
64  		setAbstract(true);
65  	}
66  
67  	public void setAbstract(boolean isAbstract) {
68  		setModifier(isAbstract, ABSTRACT);
69  	}
70  
71  	public boolean isStatic() {
72  		return isModifier(STATIC);
73  	}
74  
75  	public void setStatic() {
76  		setStatic(true);
77  	}
78  
79  	public void setStatic(boolean isStatic) {
80  		setModifier(isStatic, STATIC);
81  	}
82  
83  	public boolean isFinal() {
84  		return isModifier(FINAL);
85  	}
86  
87  	public void setFinal() {
88  		setFinal(true);
89  	}
90  
91  	public void setFinal(boolean isFinal) {
92  		setModifier(isFinal, FINAL);
93  	}
94  
95  	public boolean isSynchronized() {
96  		return isModifier(SYNCHRONIZED);
97  	}
98  
99  	public void setSynchronized() {
100 		setSynchronized(true);
101 	}
102 
103 	public void setSynchronized(boolean isSynchronized) {
104 		setModifier(isSynchronized, SYNCHRONIZED);
105 	}
106 
107 	public boolean isNative() {
108 		return isModifier(NATIVE);
109 	}
110 
111 	public void setNative() {
112 		setNative(true);
113 	}
114 
115 	public void setNative(boolean isNative) {
116 		setModifier(isNative, NATIVE);
117 	}
118 
119 	public boolean isTransient() {
120 		return isModifier(TRANSIENT);
121 	}
122 
123 	public void setTransient() {
124 		setTransient(true);
125 	}
126 
127 	public void setTransient(boolean isTransient) {
128 		setModifier(isTransient, TRANSIENT);
129 	}
130 
131 	public boolean isVolatile() {
132 		return isModifier(VOLATILE);
133 	}
134 
135 	public void setVolatile() {
136 		setVolatile(true);
137 	}
138 
139 	public void setVolatile(boolean isVolative) {
140 		setModifier(isVolative, VOLATILE);
141 	}
142 
143 	public boolean isStrictfp() {
144 		return isModifier(STRICTFP);
145 	}
146 
147 	public void setStrictfp() {
148 		setStrictfp(true);
149 	}
150 
151 	public void setStrictfp(boolean isStrictfp) {
152 		setModifier(isStrictfp, STRICTFP);
153 	}
154 
155 	private final boolean isModifier(int mask) {
156 		return (modifiers & mask) == mask;
157 	}
158 
159 	private void setModifier(boolean enable, int mask) {
160 		if (enable) {
161 			this.modifiers |= mask;
162 		} else {
163 			this.modifiers &= ~mask;
164 		}
165 	}
166 
167 	public boolean isPackagePrivate() {
168 		return !isPrivate() && !isPublic() && !isProtected();
169 	}
170 
171 	public String collectDumpedModifiers(String prefix) {
172 		String out = toString(prefix) + ":";
173 		if (isPackagePrivate()) {
174 			out += "(package private)";
175 		}
176 		if (isPrivate()) {
177 			out += "(private)";
178 		}
179 		if (isPublic()) {
180 			out += "(public)";
181 		}
182 		if (isProtected()) {
183 			out += "(protected)";
184 		}
185 		if (isAbstract()) {
186 			out += "(abstract)";
187 		}
188 		if (isStatic()) {
189 			out += "(static)";
190 		}
191 		if (isFinal()) {
192 			out += "(final)";
193 		}
194 		if (isSynchronized()) {
195 			out += "(synchronized)";
196 		}
197 		if (isNative()) {
198 			out += "(native)";
199 		}
200 		if (isStrictfp()) {
201 			out += "(strict)";
202 		}
203 		if (isTransient()) {
204 			out += "(transient)";
205 		}
206 		return out;
207 	}
208 }