View Javadoc

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