View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.ast;
5   
6   public abstract class AbstractJavaAccessNode extends AbstractJavaNode implements AccessNode {
7   
8       private int modifiers;
9   
10      public AbstractJavaAccessNode(int i) {
11          super(i);
12      }
13  
14      public AbstractJavaAccessNode(JavaParser parser, int i) {
15          super(parser, i);
16      }
17  
18      public int getModifiers() {
19          return this.modifiers;
20      }
21  
22      public void setModifiers(int modifiers) {
23          this.modifiers = modifiers;
24      }
25  
26      public boolean isPublic() {
27          return isModifier(PUBLIC);
28      }
29  
30      public void setPublic(boolean isPublic) {
31          setModifier(isPublic, PUBLIC);
32      }
33  
34      public boolean isProtected() {
35          return isModifier(PROTECTED);
36      }
37  
38      public void setProtected(boolean isProtected) {
39          setModifier(isProtected, PROTECTED);
40      }
41  
42      public boolean isPrivate() {
43          return isModifier(PRIVATE);
44      }
45  
46      public void setPrivate(boolean isPrivate) {
47          setModifier(isPrivate, PRIVATE);
48      }
49  
50      public boolean isAbstract() {
51          return isModifier(ABSTRACT);
52      }
53  
54      public void setAbstract(boolean isAbstract) {
55          setModifier(isAbstract, ABSTRACT);
56      }
57  
58      public boolean isStatic() {
59          return isModifier(STATIC);
60      }
61  
62      public void setStatic(boolean isStatic) {
63          setModifier(isStatic, STATIC);
64      }
65  
66      public boolean isFinal() {
67          return isModifier(FINAL);
68      }
69  
70      public void setFinal(boolean isFinal) {
71          setModifier(isFinal, FINAL);
72      }
73  
74      public boolean isSynchronized() {
75          return isModifier(SYNCHRONIZED);
76      }
77  
78      public void setSynchronized(boolean isSynchronized) {
79          setModifier(isSynchronized, SYNCHRONIZED);
80      }
81  
82      public boolean isNative() {
83          return isModifier(NATIVE);
84      }
85  
86      public void setNative(boolean isNative) {
87          setModifier(isNative, NATIVE);
88      }
89  
90      public boolean isTransient() {
91          return isModifier(TRANSIENT);
92      }
93  
94      public void setTransient(boolean isTransient) {
95          setModifier(isTransient, TRANSIENT);
96      }
97  
98      public boolean isVolatile() {
99          return isModifier(VOLATILE);
100     }
101 
102     public void setVolatile(boolean isVolative) {
103         setModifier(isVolative, VOLATILE);
104     }
105 
106     public boolean isStrictfp() {
107         return isModifier(STRICTFP);
108     }
109 
110     public void setStrictfp(boolean isStrictfp) {
111         setModifier(isStrictfp, STRICTFP);
112     }
113 
114     public boolean isDefault() {
115         return isModifier(DEFAULT);
116     }
117 
118     public void setDefault(boolean isDefault) {
119         setModifier(isDefault, DEFAULT);
120     }
121 
122     @SuppressWarnings("PMD.UselessParentheses") //TODO: fix the rule - around binary expressions the parentheses are needed...
123     private final boolean isModifier(int mask) {
124         return (modifiers & mask) == mask;
125     }
126 
127     private void setModifier(boolean enable, int mask) {
128         if (enable) {
129             this.modifiers |= mask;
130         } else {
131             this.modifiers &= ~mask;
132         }
133     }
134 
135     public boolean isPackagePrivate() {
136         return !isPrivate() && !isPublic() && !isProtected();
137     }
138 }