1 22 package org.aspectj.tools.ajdoc; 23 24 import org.aspectj.compiler.base.ast.Modifiers; 25 import org.aspectj.compiler.base.ast.FieldDec; 26 import org.aspectj.compiler.base.ast.TypeDec; 27 import org.aspectj.compiler.base.ast.NameType; 28 import org.aspectj.compiler.base.ast.CodeDec; 29 import org.aspectj.compiler.crosscuts.ast.PointcutDec; 30 31 40 public abstract class AccessChecker { 41 43 44 public static final AccessChecker PUBLIC = new AccessChecker("public") { 45 public boolean doCanAccess(Modifiers mods, Object object) { 46 return mods.isPublic(); 47 } 48 }; 49 50 51 public static final AccessChecker PROTECTED = new AccessChecker("protected") { 52 public boolean doCanAccess(Modifiers mods, Object object) { 53 return mods.isPublic() || mods.isProtected(); 54 } 55 }; 56 57 58 public static final AccessChecker PACKAGE = new AccessChecker("package") { 59 public boolean doCanAccess(Modifiers mods, Object object) { 60 return !mods.isPrivate(); 61 } 62 }; 63 64 65 public static final AccessChecker PRIVATE = new AccessChecker("private") { 66 public boolean doCanAccess(Modifiers mods, Object object) { 67 return true; 68 } 69 }; 70 71 72 protected final String optionName; 73 74 80 protected AccessChecker(String optionName){ 81 this.optionName = optionName; 82 } 83 84 85 public boolean canAccess(FieldDec dec) { 86 if (null == dec) return false; 87 if (!canAccess(dec.getModifiers(), dec)) { 88 return false; 89 } else { 90 return canAccess(dec.getBytecodeTypeDec()); 91 } 92 } 93 94 95 public boolean canAccess(CodeDec dec) { 96 if (null == dec) return false; 97 if (!canAccess(dec.getModifiers(), dec)) { 98 return false; 99 } else { 100 return canAccess(dec.getBytecodeTypeDec()); 101 } 102 } 103 104 105 public boolean canAccess(PointcutDec dec) { 106 if (null == dec) return false; 107 if (!canAccess(dec.getModifiers(), dec)) { 108 return false; 109 } else { 110 return canAccess(dec.getBytecodeTypeDec()); 111 } 112 } 113 114 122 132 133 134 public boolean canAccess(TypeDec dec) { 135 if (null == dec) return false; 136 boolean result = canAccess(dec.getModifiers(), dec); 137 if (result) { 138 NameType outerType = dec.getEnclosingInstanceType(); 140 TypeDec outer = (null == outerType? null 141 : outerType.getTypeDec()); result = ((null == outer) || canAccess(outer)); 143 } 144 return result; 145 } 146 147 152 protected boolean canAccessLog(Modifiers mods, Object object, 153 boolean result) { 154 return result; 155 } 156 157 164 public final boolean canAccess(Modifiers mods, Object object) { 166 boolean result = (null == mods? false : doCanAccess(mods, object)); 167 return canAccessLog(mods, object, result); 168 } 169 170 171 public final String getOption() { return optionName; } 172 173 174 public final String toString() { return optionName.toUpperCase(); } 175 176 177 abstract protected boolean doCanAccess(Modifiers mods, Object object); 178 } 179 | Popular Tags |