package org.aspectj.lang.reflect;
+import java.lang.reflect.Method;
public interface AdviceSignature extends CodeSignature {
Class getReturnType(); /* name is consistent with reflection API */
/* before and after always return Void.TYPE */
/* (some around also return Void.Type) */
+ Method getAdvice();
}
package org.aspectj.lang.reflect;
+import java.lang.reflect.Constructor;
public interface ConstructorSignature extends CodeSignature {
+ Constructor getConstructor();
}
package org.aspectj.lang.reflect;
+import java.lang.reflect.Field;
public interface FieldSignature extends MemberSignature {
public Class getFieldType();
+ public Field getField();
}
package org.aspectj.lang.reflect;
+import java.lang.reflect.Constructor;
-public interface InitializerSignature extends CodeSignature { }
+public interface InitializerSignature extends CodeSignature {
+ Constructor getInitializer();
+}
package org.aspectj.lang.reflect;
-import java.lang.reflect.AccessibleObject;
-
import org.aspectj.lang.Signature;
public interface MemberSignature extends Signature {
- AccessibleObject getAccessibleObject();
+ // AccessibleObject is a 1.2 API, we run on 1.1... (thanks Wes for catching this)
+ //AccessibleObject getAccessibleObject();
}
package org.aspectj.lang.reflect;
+import java.lang.reflect.Method;
public interface MethodSignature extends CodeSignature {
Class getReturnType(); /* name is consistent with reflection API */
+ Method getMethod();
}
package org.aspectj.runtime.reflect;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
import org.aspectj.lang.reflect.AdviceSignature;
class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
Class returnType;
+ private Method adviceMethod = null;
AdviceSignatureImpl(int modifiers, String name, Class declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
/* (non-Javadoc)
* @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
*/
- protected AccessibleObject createAccessibleObject() {
- try {
- return declaringType.getDeclaredMethod(getName(),getParameterTypes());
- } catch (Exception ex) {
- ; // nothing we can do, caller will see null
+ public Method getAdvice() {
+ if (adviceMethod == null) {
+ try {
+ adviceMethod = declaringType.getDeclaredMethod(getName(),getParameterTypes());
+ } catch (Exception ex) {
+ ; // nothing we can do, caller will see null
+ }
}
- return null;
+ return adviceMethod;
}
}
package org.aspectj.runtime.reflect;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
import org.aspectj.lang.reflect.ConstructorSignature;
class ConstructorSignatureImpl extends CodeSignatureImpl implements ConstructorSignature {
+ private Constructor constructor;
+
ConstructorSignatureImpl(int modifiers, Class declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes)
{
/* (non-Javadoc)
* @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
*/
- protected AccessibleObject createAccessibleObject() {
- try {
- return declaringType.getDeclaredConstructor(getParameterTypes());
- } catch (Exception ex) {
- ; // nothing we can do, caller will see null
+ public Constructor getConstructor() {
+ if (constructor == null) {
+ try {
+ constructor = declaringType.getDeclaredConstructor(getParameterTypes());
+ } catch (Exception ex) {
+ ; // nothing we can do, caller will see null
+ }
}
- return null;
+ return constructor;
}
}
package org.aspectj.runtime.reflect;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
import org.aspectj.lang.reflect.FieldSignature;
public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature {
Class fieldType;
+ private Field field;
FieldSignatureImpl(int modifiers, String name, Class declaringType,
Class fieldType)
/* (non-Javadoc)
* @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
*/
- protected AccessibleObject createAccessibleObject() {
- try {
- return declaringType.getDeclaredField(getName());
- } catch (Exception ex) {
- ; // nothing we can do, caller will see null
+ public Field getField() {
+ if (field == null) {
+ try {
+ field = declaringType.getDeclaredField(getName());
+ } catch (Exception ex) {
+ ; // nothing we can do, caller will see null
+ }
}
- return null;
+ return field;
}
}
import org.aspectj.lang.reflect.InitializerSignature;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
class InitializerSignatureImpl extends CodeSignatureImpl implements InitializerSignature {
+ private Constructor constructor;
+
InitializerSignatureImpl(int modifiers, Class declaringType) {
super(modifiers, Modifier.isStatic(modifiers) ? "<clinit>" : "<init>", declaringType, EMPTY_CLASS_ARRAY,
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY);
/* (non-Javadoc)
* @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
*/
- protected AccessibleObject createAccessibleObject() {
- try {
- return declaringType.getDeclaredConstructor(getParameterTypes());
- } catch (Exception ex) {
- ; // nothing we can do, caller will see null
+ public Constructor getInitializer() {
+ if (constructor == null) {
+ try {
+ constructor = declaringType.getDeclaredConstructor(getParameterTypes());
+ } catch (Exception ex) {
+ ; // nothing we can do, caller will see null
+ }
}
- return null;
+ return constructor;
}
}
package org.aspectj.runtime.reflect;
-import java.lang.reflect.AccessibleObject;
-
import org.aspectj.lang.reflect.MemberSignature;
abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature {
- protected AccessibleObject accessibleObj = null;
MemberSignatureImpl(int modifiers, String name, Class declaringType) {
super(modifiers, name, declaringType);
super(stringRep);
}
- /* (non-Javadoc)
- * @see org.aspectj.lang.reflect.MemberSignature#getAccessibleObject()
- */
- public AccessibleObject getAccessibleObject() {
- if (accessibleObj == null) {
- accessibleObj = createAccessibleObject();
- }
- return accessibleObj;
- }
-
- protected abstract AccessibleObject createAccessibleObject();
}
package org.aspectj.runtime.reflect;
-import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
import org.aspectj.lang.reflect.MethodSignature;
class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature {
+ private Method method;
Class returnType;
MethodSignatureImpl(int modifiers, String name, Class declaringType,
/* (non-Javadoc)
* @see org.aspectj.lang.reflect.MemberSignature#getAccessibleObject()
*/
- public AccessibleObject createAccessibleObject() {
- try {
- return declaringType.getDeclaredMethod(getName(),getParameterTypes());
- } catch (NoSuchMethodException nsmEx) {
- ; // nothing we can do, user will see null return
+ public Method getMethod() {
+ if (method == null) {
+ try {
+ method = declaringType.getDeclaredMethod(getName(),getParameterTypes());
+ } catch (NoSuchMethodException nsmEx) {
+ ; // nothing we can do, user will see null return
+ }
}
- return null;
+ return method;
}
}