1 24 25 package org.aspectj.compiler.base; 26 27 import org.aspectj.compiler.base.ast.*; 28 import org.aspectj.compiler.base.*; 29 30 import java.util.*; 31 32 36 public final class InnerInfoPass extends WalkerPass { 37 public InnerInfoPass(JavaCompiler jc) { super(jc); } 38 39 public String getDisplayName() { return "setting inner info"; } 40 41 private static final int CU = 0; private static final int MEMBER = 1; private static final int STATICMEMBER = 2; private static final int DYNAMIC = 3; private static final int STATIC = 4; private static final int NIGH_STATIC = 5; 49 private int context = CU; 50 51 public ASTObject process(ASTObject object) { 52 object.walkInnerInfo(this); 53 object.postInnerInfo(this); 54 return object; 55 } 56 57 public int inCCall() { return setContext(NIGH_STATIC); } 58 public int inType(boolean isInterface) { 59 return setContext(isInterface ? STATICMEMBER : MEMBER); 60 } 61 public int inMember(boolean isStatic) { 62 return setContext(isStatic ? STATIC : DYNAMIC); 63 } 64 private int setContext(int c) { 65 int context = this.context; 66 this.context = c; 67 return context; 68 } 69 public void restoreContext(int context) { 70 this.context = context; 71 } 72 73 public boolean isStatic() { 74 return context != DYNAMIC; 75 } 76 77 public boolean hasNonStaticAccess(ASTObject node, Type type) { 78 return isAccessible(type); 79 } 86 87 public void checkStaticAccess(ASTObject node, SemanticObject so) { 88 if (so.isStatic()) return; 89 90 if (!hasNonStaticAccess(node, so.getDeclaringType())) { 91 node.showError("non-static " + so.getKind() + " " + so.getName() + 92 " cannot be referenced from a static context"); 93 } 94 } 95 96 public static boolean isInner(Type t) { 97 if (! (t instanceof NameType)) return false; 98 NameType nt = (NameType) t; 99 return nt.isInner() 100 || (nt.getTypeDec().fromSource() 103 && ! nt.isAspect() 104 && ! nt.isPackageMember() 105 && ! nt.isLocal() 106 && ! nt.getTypeDec().isStatic() 107 && ! nt.getDeclaringType().isInterface()); 108 } 109 110 public boolean isInDynamicContext() { 111 return (context == MEMBER) || (context == DYNAMIC); 112 } 113 114 116 private List types = new ArrayList(); 117 public void enterType(TypeDec dec) { types.add(dec.getType()); } 118 public void leaveType() { types.remove(types.size() - 1); } 119 120 public NameType currentType() { 121 return (NameType) types.get(types.size() - 1); 122 } 123 public NameType enclosingType() { 124 return (NameType) types.get(types.size() - 2); 125 } 126 127 public boolean isAccessibleExactly(Type t) { 128 return isAccessible(t, false); 129 } 130 public boolean isAccessible(Type t) { 131 return isAccessible(t, true); 132 } 133 public boolean isAccessible(Type t, boolean allowSubs) { 134 NameType current = (NameType) types.get(types.size() - 1); 135 if (current == t || (allowSubs && current.isSubtypeOf(t))) { 136 return (context == DYNAMIC); 137 } 138 if (! current.isInner()) return false; 139 for (int i = types.size() - 2; i >= 0; i--) { 140 current = (NameType) types.get(i); 141 if (current == t || (allowSubs && current.isSubtypeOf(t))) { 142 return (context != STATIC); 143 } else if (! current.isInner()) { 144 return false; 145 } 146 } 147 return false; } 149 } 150 | Popular Tags |