diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/src/org/aspectj/lang/JoinPoint.java | 22 | ||||
-rw-r--r-- | runtime/src/org/aspectj/runtime/reflect/Factory.java | 698 | ||||
-rw-r--r-- | runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java | 355 |
3 files changed, 577 insertions, 498 deletions
diff --git a/runtime/src/org/aspectj/lang/JoinPoint.java b/runtime/src/org/aspectj/lang/JoinPoint.java index 7e4276537..5d66c7930 100644 --- a/runtime/src/org/aspectj/lang/JoinPoint.java +++ b/runtime/src/org/aspectj/lang/JoinPoint.java @@ -99,7 +99,6 @@ public interface JoinPoint { */ String getKind(); - /** * <p>This helper object contains only the static information about a join point. * It is available from the <code>JoinPoint.getStaticPart()</code> method, and @@ -141,6 +140,27 @@ public interface JoinPoint { * is guaranteed to be interned</p> */ String getKind(); + + /** + * Return the id for this JoinPoint.StaticPart. All JoinPoint.StaticPart + * instances are assigned an id number upon creation. For each advised type + * the id numbers start at 0. + * <br> + * The id is guaranteed to remain constant across repeated executions + * of a program but may change if the code is recompiled. + * <br> + * The benefit of having an id is that it can be used for array index + * purposes which can be quicker than using the JoinPoint.StaticPart + * object itself in a map lookup. + * <br> + * Since two JoinPoint.StaticPart instances in different advised types may have + * the same id, then if the id is being used to index some joinpoint specific + * state then that state must be maintained on a pertype basis - either by + * using pertypewithin() or an ITD. + * + * @return the id of this joinpoint + */ + int getId(); String toString(); diff --git a/runtime/src/org/aspectj/runtime/reflect/Factory.java b/runtime/src/org/aspectj/runtime/reflect/Factory.java index 51cff98bd..4e88f8cf5 100644 --- a/runtime/src/org/aspectj/runtime/reflect/Factory.java +++ b/runtime/src/org/aspectj/runtime/reflect/Factory.java @@ -12,7 +12,6 @@ * Alex Vasseur new factory methods for variants of JP * ******************************************************************/ - package org.aspectj.runtime.reflect; import java.lang.reflect.Constructor; @@ -21,363 +20,376 @@ import java.lang.reflect.Method; import java.util.Hashtable; import java.util.StringTokenizer; -import org.aspectj.lang.*; -import org.aspectj.lang.reflect.*; - -public final class Factory { - Class lexicalClass; - ClassLoader lookupClassLoader; - String filename; - - static Hashtable prims = new Hashtable(); - static { - prims.put("void", Void.TYPE); - prims.put("boolean", Boolean.TYPE); - prims.put("byte", Byte.TYPE); - prims.put("char", Character.TYPE); - prims.put("short", Short.TYPE); - prims.put("int", Integer.TYPE); - prims.put("long", Long.TYPE); - prims.put("float", Float.TYPE); - prims.put("double", Double.TYPE); - } - - static Class makeClass(String s, ClassLoader loader) { - if (s.equals("*")) return null; - Class ret = (Class)prims.get(s); - if (ret != null) return ret; - try { - /* The documentation of Class.forName explains why this is the right thing - * better than I could here. - */ - if (loader == null) { - return Class.forName(s); - } else { - // used to be 'return loader.loadClass(s)' but that didn't cause - // array types to be created and loaded correctly. (pr70404) - return Class.forName(s,false,loader); - } - } catch (ClassNotFoundException e) { - //System.out.println("null for: " + s); - //XXX there should be a better return value for this - return ClassNotFoundException.class; - } - } - - public Factory(String filename, Class lexicalClass) { - //System.out.println("making - this.filename = filename; - this.lexicalClass = lexicalClass; - lookupClassLoader = lexicalClass.getClassLoader(); - } - - - - public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) { - return new JoinPointImpl.StaticPartImpl(kind, sig, loc); - } - - public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l, int c) { - return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, c)); - } - - public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l) { - return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, -1)); - } - - public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, SourceLocation loc) { - return new JoinPointImpl.EnclosingStaticPartImpl(kind, sig, loc); - } - - public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, int l, int c) { - return new JoinPointImpl.EnclosingStaticPartImpl(kind, sig, makeSourceLoc(l, c)); - } - - public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, int l) { - return new JoinPointImpl.EnclosingStaticPartImpl(kind, sig, makeSourceLoc(l, -1)); - } - - public static JoinPoint.StaticPart makeEncSJP(Member member) { - Signature sig = null; - String kind = null; - if (member instanceof Method) { - Method method = (Method) member; - sig = new MethodSignatureImpl(method.getModifiers(),method.getName(), - method.getDeclaringClass(),method.getParameterTypes(), - new String[method.getParameterTypes().length], - method.getExceptionTypes(),method.getReturnType()); - kind = JoinPoint.METHOD_EXECUTION; - } else if (member instanceof Constructor) { - Constructor cons = (Constructor) member; - sig = new ConstructorSignatureImpl(cons.getModifiers(),cons.getDeclaringClass(), - cons.getParameterTypes(), - new String[cons.getParameterTypes().length], - cons.getExceptionTypes()); - kind = JoinPoint.CONSTRUCTOR_EXECUTION; - } else { - throw new IllegalArgumentException("member must be either a method or constructor"); - } - return new JoinPointImpl.EnclosingStaticPartImpl(kind,sig,null); - } - - private static Object[] NO_ARGS = new Object[0]; - public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, - Object _this, Object target) - { +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.reflect.AdviceSignature; +import org.aspectj.lang.reflect.CatchClauseSignature; +import org.aspectj.lang.reflect.ConstructorSignature; +import org.aspectj.lang.reflect.FieldSignature; +import org.aspectj.lang.reflect.InitializerSignature; +import org.aspectj.lang.reflect.LockSignature; +import org.aspectj.lang.reflect.MethodSignature; +import org.aspectj.lang.reflect.SourceLocation; +import org.aspectj.lang.reflect.UnlockSignature; + +public final class Factory { + Class lexicalClass; + ClassLoader lookupClassLoader; + String filename; + int count; + + static Hashtable prims = new Hashtable(); + static { + prims.put("void", Void.TYPE); + prims.put("boolean", Boolean.TYPE); + prims.put("byte", Byte.TYPE); + prims.put("char", Character.TYPE); + prims.put("short", Short.TYPE); + prims.put("int", Integer.TYPE); + prims.put("long", Long.TYPE); + prims.put("float", Float.TYPE); + prims.put("double", Double.TYPE); + } + + static Class makeClass(String s, ClassLoader loader) { + if (s.equals("*")) + return null; + Class ret = (Class) prims.get(s); + if (ret != null) + return ret; + try { + /* + * The documentation of Class.forName explains why this is the right thing better than I could here. + */ + if (loader == null) { + return Class.forName(s); + } else { + // used to be 'return loader.loadClass(s)' but that didn't cause + // array types to be created and loaded correctly. (pr70404) + return Class.forName(s, false, loader); + } + } catch (ClassNotFoundException e) { + // System.out.println("null for: " + s); + // XXX there should be a better return value for this + return ClassNotFoundException.class; + } + } + + public Factory(String filename, Class lexicalClass) { + // System.out.println("making + this.filename = filename; + this.lexicalClass = lexicalClass; + this.count = 0; + lookupClassLoader = lexicalClass.getClassLoader(); + } + + public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) { + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, loc); + } + + public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l, int c) { + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, c)); + } + + public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l) { + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); + } + + public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, SourceLocation loc) { + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, loc); + } + + public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, int l, int c) { + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(l, c)); + } + + public JoinPoint.EnclosingStaticPart makeESJP(String kind, Signature sig, int l) { + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); + } + + public static JoinPoint.StaticPart makeEncSJP(Member member) { + Signature sig = null; + String kind = null; + if (member instanceof Method) { + Method method = (Method) member; + sig = new MethodSignatureImpl(method.getModifiers(), method.getName(), method.getDeclaringClass(), method + .getParameterTypes(), new String[method.getParameterTypes().length], method.getExceptionTypes(), method + .getReturnType()); + kind = JoinPoint.METHOD_EXECUTION; + } else if (member instanceof Constructor) { + Constructor cons = (Constructor) member; + sig = new ConstructorSignatureImpl(cons.getModifiers(), cons.getDeclaringClass(), cons.getParameterTypes(), + new String[cons.getParameterTypes().length], cons.getExceptionTypes()); + kind = JoinPoint.CONSTRUCTOR_EXECUTION; + } else { + throw new IllegalArgumentException("member must be either a method or constructor"); + } + return new JoinPointImpl.EnclosingStaticPartImpl(-1, kind, sig, null); + } + + private static Object[] NO_ARGS = new Object[0]; + + public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, Object _this, Object target) { return new JoinPointImpl(staticPart, _this, target, NO_ARGS); } - - public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, - Object _this, Object target, Object arg0) - { - return new JoinPointImpl(staticPart, _this, target, new Object[] {arg0}); - } - - public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, - Object _this, Object target, Object arg0, Object arg1) - { - return new JoinPointImpl(staticPart, _this, target, new Object[] {arg0, arg1}); - } - - - public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, - Object _this, Object target, Object[] args) - { + + public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, Object _this, Object target, Object arg0) { + return new JoinPointImpl(staticPart, _this, target, new Object[] { arg0 }); + } + + public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, Object _this, Object target, Object arg0, Object arg1) { + return new JoinPointImpl(staticPart, _this, target, new Object[] { arg0, arg1 }); + } + + public static JoinPoint makeJP(JoinPoint.StaticPart staticPart, Object _this, Object target, Object[] args) { return new JoinPointImpl(staticPart, _this, target, args); } - - public MethodSignature makeMethodSig(String stringRep) { - MethodSignatureImpl ret = new MethodSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - - public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes, String paramNames, String exceptionTypes, String returnType) { - int modifiersAsInt = Integer.parseInt(modifiers, 16); - - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); - - StringTokenizer st = new StringTokenizer(paramTypes, ":"); - int numParams = st.countTokens(); - Class[] paramTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader); - - st = new StringTokenizer(paramNames, ":"); - numParams = st.countTokens(); - String[] paramNamesArray = new String[numParams]; - for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken(); - - st = new StringTokenizer(exceptionTypes, ":"); - numParams = st.countTokens(); - Class[] exceptionTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader); - - Class returnTypeClass = makeClass(returnType,lookupClassLoader); - - MethodSignatureImpl ret = - new MethodSignatureImpl(modifiersAsInt, methodName, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses, returnTypeClass); - - return ret; - } - - public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType, - Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, - Class returnType) { - MethodSignatureImpl ret = new MethodSignatureImpl(modifiers,name,declaringType,parameterTypes,parameterNames,exceptionTypes,returnType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public ConstructorSignature makeConstructorSig(String stringRep) { - ConstructorSignatureImpl ret = new ConstructorSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public ConstructorSignature makeConstructorSig(String modifiers, String declaringType, String paramTypes, String paramNames, String exceptionTypes) { + + public MethodSignature makeMethodSig(String stringRep) { + MethodSignatureImpl ret = new MethodSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes, + String paramNames, String exceptionTypes, String returnType) { + int modifiersAsInt = Integer.parseInt(modifiers, 16); + + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + + StringTokenizer st = new StringTokenizer(paramTypes, ":"); + int numParams = st.countTokens(); + Class[] paramTypeClasses = new Class[numParams]; + for (int i = 0; i < numParams; i++) + paramTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); + + st = new StringTokenizer(paramNames, ":"); + numParams = st.countTokens(); + String[] paramNamesArray = new String[numParams]; + for (int i = 0; i < numParams; i++) + paramNamesArray[i] = st.nextToken(); + + st = new StringTokenizer(exceptionTypes, ":"); + numParams = st.countTokens(); + Class[] exceptionTypeClasses = new Class[numParams]; + for (int i = 0; i < numParams; i++) + exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); + + Class returnTypeClass = makeClass(returnType, lookupClassLoader); + + MethodSignatureImpl ret = new MethodSignatureImpl(modifiersAsInt, methodName, declaringTypeClass, paramTypeClasses, + paramNamesArray, exceptionTypeClasses, returnTypeClass); + + return ret; + } + + public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType, Class[] parameterTypes, + String[] parameterNames, Class[] exceptionTypes, Class returnType) { + MethodSignatureImpl ret = new MethodSignatureImpl(modifiers, name, declaringType, parameterTypes, parameterNames, + exceptionTypes, returnType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public ConstructorSignature makeConstructorSig(String stringRep) { + ConstructorSignatureImpl ret = new ConstructorSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public ConstructorSignature makeConstructorSig(String modifiers, String declaringType, String paramTypes, String paramNames, + String exceptionTypes) { int modifiersAsInt = Integer.parseInt(modifiers, 16); - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); StringTokenizer st = new StringTokenizer(paramTypes, ":"); int numParams = st.countTokens(); Class[] paramTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader); + for (int i = 0; i < numParams; i++) + paramTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); st = new StringTokenizer(paramNames, ":"); numParams = st.countTokens(); String[] paramNamesArray = new String[numParams]; - for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken(); - + for (int i = 0; i < numParams; i++) + paramNamesArray[i] = st.nextToken(); + st = new StringTokenizer(exceptionTypes, ":"); numParams = st.countTokens(); Class[] exceptionTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader); - - ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiersAsInt, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - - public ConstructorSignature makeConstructorSig(int modifiers, Class declaringType, - Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) { - ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiers,declaringType,parameterTypes,parameterNames,exceptionTypes); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public FieldSignature makeFieldSig(String stringRep) { - FieldSignatureImpl ret = new FieldSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - - public FieldSignature makeFieldSig(String modifiers, String name, String declaringType, String fieldType) { - int modifiersAsInt = Integer.parseInt(modifiers, 16); - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); - Class fieldTypeClass = makeClass(fieldType,lookupClassLoader); - - FieldSignatureImpl ret = new FieldSignatureImpl(modifiersAsInt, name, declaringTypeClass, fieldTypeClass); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public FieldSignature makeFieldSig(int modifiers, String name, Class declaringType, - Class fieldType) { - FieldSignatureImpl ret = new FieldSignatureImpl(modifiers,name,declaringType,fieldType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public AdviceSignature makeAdviceSig(String stringRep) { - AdviceSignatureImpl ret = new AdviceSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public AdviceSignature makeAdviceSig(String modifiers, String name, String declaringType, String paramTypes, String paramNames, String exceptionTypes, String returnType) { - int modifiersAsInt = Integer.parseInt(modifiers, 16); - - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); - - StringTokenizer st = new StringTokenizer(paramTypes, ":"); - int numParams = st.countTokens(); - Class[] paramTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader); - - st = new StringTokenizer(paramNames, ":"); - numParams = st.countTokens(); - String[] paramNamesArray = new String[numParams]; - for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken(); - - st = new StringTokenizer(exceptionTypes, ":"); - numParams = st.countTokens(); - Class[] exceptionTypeClasses = new Class[numParams]; - for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);; - - Class returnTypeClass = makeClass(returnType,lookupClassLoader); - - AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiersAsInt, name, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses, returnTypeClass); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public AdviceSignature makeAdviceSig(int modifiers, String name, Class declaringType, - Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, - Class returnType) { - AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiers,name,declaringType,parameterTypes,parameterNames,exceptionTypes,returnType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public InitializerSignature makeInitializerSig(String stringRep) { - InitializerSignatureImpl ret = new InitializerSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public InitializerSignature makeInitializerSig(String modifiers, String declaringType) { - int modifiersAsInt = Integer.parseInt(modifiers, 16); - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); - - InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiersAsInt, declaringTypeClass); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public InitializerSignature makeInitializerSig(int modifiers, Class declaringType) { - InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiers,declaringType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public CatchClauseSignature makeCatchClauseSig(String stringRep) { - CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public CatchClauseSignature makeCatchClauseSig(String declaringType, String parameterType, String parameterName) { - Class declaringTypeClass = makeClass(declaringType,lookupClassLoader); - - StringTokenizer st = new StringTokenizer(parameterType, ":"); - Class parameterTypeClass = makeClass(st.nextToken(),lookupClassLoader); - - st = new StringTokenizer(parameterName, ":"); - String parameterNameForReturn = st.nextToken(); - - CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringTypeClass, parameterTypeClass, parameterNameForReturn); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public CatchClauseSignature makeCatchClauseSig(Class declaringType, - Class parameterType, String parameterName) { - CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringType,parameterType,parameterName); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public LockSignature makeLockSig(String stringRep) { - LockSignatureImpl ret = new LockSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - public LockSignature makeLockSig() { - Class declaringTypeClass = makeClass("Ljava/lang/Object;",lookupClassLoader); - LockSignatureImpl ret = new LockSignatureImpl(declaringTypeClass); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - public LockSignature makeLockSig(Class declaringType) { - LockSignatureImpl ret = new LockSignatureImpl(declaringType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - public UnlockSignature makeUnlockSig(String stringRep) { - UnlockSignatureImpl ret = new UnlockSignatureImpl(stringRep); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - public UnlockSignature makeUnlockSig() { - Class declaringTypeClass = makeClass("Ljava/lang/Object;",lookupClassLoader); - UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringTypeClass); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - public UnlockSignature makeUnlockSig(Class declaringType) { - UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringType); - ret.setLookupClassLoader(lookupClassLoader); - return ret; - } - - - public SourceLocation makeSourceLoc(int line, int col) - { - return new SourceLocationImpl(lexicalClass, this.filename, line); - } + for (int i = 0; i < numParams; i++) + exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); + + ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiersAsInt, declaringTypeClass, paramTypeClasses, + paramNamesArray, exceptionTypeClasses); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public ConstructorSignature makeConstructorSig(int modifiers, Class declaringType, Class[] parameterTypes, + String[] parameterNames, Class[] exceptionTypes) { + ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes, parameterNames, + exceptionTypes); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public FieldSignature makeFieldSig(String stringRep) { + FieldSignatureImpl ret = new FieldSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public FieldSignature makeFieldSig(String modifiers, String name, String declaringType, String fieldType) { + int modifiersAsInt = Integer.parseInt(modifiers, 16); + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + Class fieldTypeClass = makeClass(fieldType, lookupClassLoader); + + FieldSignatureImpl ret = new FieldSignatureImpl(modifiersAsInt, name, declaringTypeClass, fieldTypeClass); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public FieldSignature makeFieldSig(int modifiers, String name, Class declaringType, Class fieldType) { + FieldSignatureImpl ret = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public AdviceSignature makeAdviceSig(String stringRep) { + AdviceSignatureImpl ret = new AdviceSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public AdviceSignature makeAdviceSig(String modifiers, String name, String declaringType, String paramTypes, String paramNames, + String exceptionTypes, String returnType) { + int modifiersAsInt = Integer.parseInt(modifiers, 16); + + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + + StringTokenizer st = new StringTokenizer(paramTypes, ":"); + int numParams = st.countTokens(); + Class[] paramTypeClasses = new Class[numParams]; + for (int i = 0; i < numParams; i++) + paramTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); + + st = new StringTokenizer(paramNames, ":"); + numParams = st.countTokens(); + String[] paramNamesArray = new String[numParams]; + for (int i = 0; i < numParams; i++) + paramNamesArray[i] = st.nextToken(); + + st = new StringTokenizer(exceptionTypes, ":"); + numParams = st.countTokens(); + Class[] exceptionTypeClasses = new Class[numParams]; + for (int i = 0; i < numParams; i++) + exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); + ; + + Class returnTypeClass = makeClass(returnType, lookupClassLoader); + + AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiersAsInt, name, declaringTypeClass, paramTypeClasses, + paramNamesArray, exceptionTypeClasses, returnTypeClass); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public AdviceSignature makeAdviceSig(int modifiers, String name, Class declaringType, Class[] parameterTypes, + String[] parameterNames, Class[] exceptionTypes, Class returnType) { + AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiers, name, declaringType, parameterTypes, parameterNames, + exceptionTypes, returnType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public InitializerSignature makeInitializerSig(String stringRep) { + InitializerSignatureImpl ret = new InitializerSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public InitializerSignature makeInitializerSig(String modifiers, String declaringType) { + int modifiersAsInt = Integer.parseInt(modifiers, 16); + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + + InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiersAsInt, declaringTypeClass); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public InitializerSignature makeInitializerSig(int modifiers, Class declaringType) { + InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiers, declaringType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public CatchClauseSignature makeCatchClauseSig(String stringRep) { + CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public CatchClauseSignature makeCatchClauseSig(String declaringType, String parameterType, String parameterName) { + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + + StringTokenizer st = new StringTokenizer(parameterType, ":"); + Class parameterTypeClass = makeClass(st.nextToken(), lookupClassLoader); + + st = new StringTokenizer(parameterName, ":"); + String parameterNameForReturn = st.nextToken(); + + CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringTypeClass, parameterTypeClass, parameterNameForReturn); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public CatchClauseSignature makeCatchClauseSig(Class declaringType, Class parameterType, String parameterName) { + CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public LockSignature makeLockSig(String stringRep) { + LockSignatureImpl ret = new LockSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public LockSignature makeLockSig() { + Class declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader); + LockSignatureImpl ret = new LockSignatureImpl(declaringTypeClass); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public LockSignature makeLockSig(Class declaringType) { + LockSignatureImpl ret = new LockSignatureImpl(declaringType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public UnlockSignature makeUnlockSig(String stringRep) { + UnlockSignatureImpl ret = new UnlockSignatureImpl(stringRep); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public UnlockSignature makeUnlockSig() { + Class declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader); + UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringTypeClass); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public UnlockSignature makeUnlockSig(Class declaringType) { + UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringType); + ret.setLookupClassLoader(lookupClassLoader); + return ret; + } + + public SourceLocation makeSourceLoc(int line, int col) { + return new SourceLocationImpl(lexicalClass, this.filename, line); + } } diff --git a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java index bb468feef..cae6cf577 100644 --- a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java +++ b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java @@ -11,7 +11,6 @@ * Xerox/PARC initial implementation * ******************************************************************/ - package org.aspectj.runtime.reflect; import org.aspectj.lang.JoinPoint; @@ -21,158 +20,206 @@ import org.aspectj.lang.reflect.SourceLocation; import org.aspectj.runtime.internal.AroundClosure; class JoinPointImpl implements ProceedingJoinPoint { - static class StaticPartImpl implements JoinPoint.StaticPart { - String kind; - Signature signature; - SourceLocation sourceLocation; - - public StaticPartImpl(String kind, Signature signature, SourceLocation sourceLocation) { - this.kind = kind; - this.signature = signature; - this.sourceLocation = sourceLocation; - } - - public String getKind() { return kind; } - public Signature getSignature() { return signature; } - public SourceLocation getSourceLocation() { return sourceLocation; } - - String toString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); - buf.append(sm.makeKindName(getKind())); - buf.append("("); - buf.append(((SignatureImpl)getSignature()).toString(sm)); - buf.append(")"); - return buf.toString(); - } - - public final String toString() { return toString(StringMaker.middleStringMaker); } - public final String toShortString() { return toString(StringMaker.shortStringMaker); } - public final String toLongString() { return toString(StringMaker.longStringMaker); } - } - - static class EnclosingStaticPartImpl extends StaticPartImpl implements EnclosingStaticPart { - public EnclosingStaticPartImpl(String kind, Signature signature, SourceLocation sourceLocation) { - super(kind, signature, sourceLocation); - } - } - - Object _this; - Object target; - Object[] args; - org.aspectj.lang.JoinPoint.StaticPart staticPart; - - public JoinPointImpl(org.aspectj.lang.JoinPoint.StaticPart staticPart, Object _this, Object target, Object[] args) { - this.staticPart = staticPart; - this._this = _this; - this.target = target; - this.args = args; - } - - public Object getThis() { return _this; } - public Object getTarget() { return target; } - public Object[] getArgs() { - if (args == null) { args = new Object[0]; } - Object[] argsCopy = new Object[args.length]; - System.arraycopy(args,0,argsCopy,0,args.length); - return argsCopy; - } - - public org.aspectj.lang.JoinPoint.StaticPart getStaticPart() { return staticPart; } - - public String getKind() { return staticPart.getKind(); } - public Signature getSignature() { return staticPart.getSignature(); } - public SourceLocation getSourceLocation() { return staticPart.getSourceLocation(); } - - public final String toString() { return staticPart.toString(); } - public final String toShortString() { return staticPart.toShortString(); } - public final String toLongString() { return staticPart.toLongString(); } - - // To proceed we need a closure to proceed on - private AroundClosure arc; - public void set$AroundClosure(AroundClosure arc) { - this.arc = arc; - } - - public Object proceed() throws Throwable { - // when called from a before advice, but be a no-op - if (arc == null) - return null; - else - return arc.run(arc.getState()); - } - - public Object proceed(Object[] adviceBindings) throws Throwable { - // when called from a before advice, but be a no-op - if (arc == null) - return null; - else { - - // Based on the bit flags in the AroundClosure we can determine what to - // expect in the adviceBindings array. We may or may not be expecting - // the first value to be a new this or a new target... (see pr126167) - int flags = arc.getFlags(); - boolean unset = (flags &0x100000)!=0; - boolean thisTargetTheSame = (flags &0x010000)!=0; - boolean hasThis = (flags &0x001000)!=0; - boolean bindsThis = (flags &0x000100)!=0; - boolean hasTarget = (flags &0x000010)!=0; - boolean bindsTarget = (flags &0x000001)!=0; - - // state is always consistent with caller?,callee?,formals...,jp - Object[] state = arc.getState(); - - // these next two numbers can differ because some join points have a this and - // target that are the same (eg. call) - and yet you can bind this and target - // separately. - - // In the state array, [0] may be this, [1] may be target - - int firstArgumentIndexIntoAdviceBindings = 0; - int firstArgumentIndexIntoState = 0; - firstArgumentIndexIntoState+=(hasThis?1:0); - firstArgumentIndexIntoState+=(hasTarget&&!thisTargetTheSame?1:0); - if (hasThis) { - if (bindsThis) { - // replace [0] (this) - firstArgumentIndexIntoAdviceBindings=1; - state[0]=adviceBindings[0]; - } else { - // leave state[0] alone, its OK - } - } - if (hasTarget) { - if (bindsTarget) { - if (thisTargetTheSame) { - // this and target are the same so replace state[0] - firstArgumentIndexIntoAdviceBindings=1+(bindsThis?1:0); - state[0]=adviceBindings[(bindsThis?1:0)]; - } else { - // need to replace the target, and it is different to this, whether - // that means replacing state[0] or state[1] depends on whether - // the join point has a this - firstArgumentIndexIntoAdviceBindings=(hasThis?1:0)+1; - state[hasThis?1:0]=adviceBindings[hasThis?1:0]; - } - } else { - // leave state[0]/state[1] alone, they are OK - } - } - - // copy the rest across - for (int i=firstArgumentIndexIntoAdviceBindings;i<adviceBindings.length;i++) { - state[firstArgumentIndexIntoState+(i-firstArgumentIndexIntoAdviceBindings)]=adviceBindings[i]; - } - - // old code that did this, didnt allow this/target overriding -// for (int i = state.length-2; i >= 0; i--) { -// int formalIndex = (adviceBindings.length - 1) - (state.length-2) + i; -// if (formalIndex >= 0 && formalIndex < adviceBindings.length) { -// state[i] = adviceBindings[formalIndex]; -// } -// } - return arc.run(state); - } - } - + static class StaticPartImpl implements JoinPoint.StaticPart { + String kind; + Signature signature; + SourceLocation sourceLocation; + private int id; + + public StaticPartImpl(int id, String kind, Signature signature, SourceLocation sourceLocation) { + this.kind = kind; + this.signature = signature; + this.sourceLocation = sourceLocation; + this.id = id; + } + + public int getId() { + return id; + } + + public String getKind() { + return kind; + } + + public Signature getSignature() { + return signature; + } + + public SourceLocation getSourceLocation() { + return sourceLocation; + } + + String toString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); + buf.append(sm.makeKindName(getKind())); + buf.append("("); + buf.append(((SignatureImpl) getSignature()).toString(sm)); + buf.append(")"); + return buf.toString(); + } + + public final String toString() { + return toString(StringMaker.middleStringMaker); + } + + public final String toShortString() { + return toString(StringMaker.shortStringMaker); + } + + public final String toLongString() { + return toString(StringMaker.longStringMaker); + } + } + + static class EnclosingStaticPartImpl extends StaticPartImpl implements EnclosingStaticPart { + public EnclosingStaticPartImpl(int count, String kind, Signature signature, SourceLocation sourceLocation) { + super(count, kind, signature, sourceLocation); + } + } + + Object _this; + Object target; + Object[] args; + org.aspectj.lang.JoinPoint.StaticPart staticPart; + + public JoinPointImpl(org.aspectj.lang.JoinPoint.StaticPart staticPart, Object _this, Object target, Object[] args) { + this.staticPart = staticPart; + this._this = _this; + this.target = target; + this.args = args; + } + + public Object getThis() { + return _this; + } + + public Object getTarget() { + return target; + } + + public Object[] getArgs() { + if (args == null) { + args = new Object[0]; + } + Object[] argsCopy = new Object[args.length]; + System.arraycopy(args, 0, argsCopy, 0, args.length); + return argsCopy; + } + + public org.aspectj.lang.JoinPoint.StaticPart getStaticPart() { + return staticPart; + } + + public String getKind() { + return staticPart.getKind(); + } + + public Signature getSignature() { + return staticPart.getSignature(); + } + + public SourceLocation getSourceLocation() { + return staticPart.getSourceLocation(); + } + + public final String toString() { + return staticPart.toString(); + } + + public final String toShortString() { + return staticPart.toShortString(); + } + + public final String toLongString() { + return staticPart.toLongString(); + } + + // To proceed we need a closure to proceed on + private AroundClosure arc; + + public void set$AroundClosure(AroundClosure arc) { + this.arc = arc; + } + + public Object proceed() throws Throwable { + // when called from a before advice, but be a no-op + if (arc == null) + return null; + else + return arc.run(arc.getState()); + } + + public Object proceed(Object[] adviceBindings) throws Throwable { + // when called from a before advice, but be a no-op + if (arc == null) + return null; + else { + + // Based on the bit flags in the AroundClosure we can determine what to + // expect in the adviceBindings array. We may or may not be expecting + // the first value to be a new this or a new target... (see pr126167) + int flags = arc.getFlags(); + boolean unset = (flags & 0x100000) != 0; + boolean thisTargetTheSame = (flags & 0x010000) != 0; + boolean hasThis = (flags & 0x001000) != 0; + boolean bindsThis = (flags & 0x000100) != 0; + boolean hasTarget = (flags & 0x000010) != 0; + boolean bindsTarget = (flags & 0x000001) != 0; + + // state is always consistent with caller?,callee?,formals...,jp + Object[] state = arc.getState(); + + // these next two numbers can differ because some join points have a this and + // target that are the same (eg. call) - and yet you can bind this and target + // separately. + + // In the state array, [0] may be this, [1] may be target + + int firstArgumentIndexIntoAdviceBindings = 0; + int firstArgumentIndexIntoState = 0; + firstArgumentIndexIntoState += (hasThis ? 1 : 0); + firstArgumentIndexIntoState += (hasTarget && !thisTargetTheSame ? 1 : 0); + if (hasThis) { + if (bindsThis) { + // replace [0] (this) + firstArgumentIndexIntoAdviceBindings = 1; + state[0] = adviceBindings[0]; + } else { + // leave state[0] alone, its OK + } + } + if (hasTarget) { + if (bindsTarget) { + if (thisTargetTheSame) { + // this and target are the same so replace state[0] + firstArgumentIndexIntoAdviceBindings = 1 + (bindsThis ? 1 : 0); + state[0] = adviceBindings[(bindsThis ? 1 : 0)]; + } else { + // need to replace the target, and it is different to this, whether + // that means replacing state[0] or state[1] depends on whether + // the join point has a this + firstArgumentIndexIntoAdviceBindings = (hasThis ? 1 : 0) + 1; + state[hasThis ? 1 : 0] = adviceBindings[hasThis ? 1 : 0]; + } + } else { + // leave state[0]/state[1] alone, they are OK + } + } + + // copy the rest across + for (int i = firstArgumentIndexIntoAdviceBindings; i < adviceBindings.length; i++) { + state[firstArgumentIndexIntoState + (i - firstArgumentIndexIntoAdviceBindings)] = adviceBindings[i]; + } + + // old code that did this, didnt allow this/target overriding + // for (int i = state.length-2; i >= 0; i--) { + // int formalIndex = (adviceBindings.length - 1) - (state.length-2) + i; + // if (formalIndex >= 0 && formalIndex < adviceBindings.length) { + // state[i] = adviceBindings[formalIndex]; + // } + // } + return arc.run(state); + } + } } |