Browse Source

Update 'runtime' code to use generics

tags/V1_9_8
Andrey Turbanov 2 years ago
parent
commit
a877b48c51
24 changed files with 98 additions and 98 deletions
  1. 7
    7
      runtime/src/main/java/org/aspectj/internal/lang/reflect/AjTypeImpl.java
  2. 1
    1
      runtime/src/main/java/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java
  3. 1
    1
      runtime/src/main/java/org/aspectj/internal/lang/reflect/PointcutImpl.java
  4. 3
    3
      runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java
  5. 4
    4
      runtime/src/main/java/org/aspectj/lang/Aspects.java
  6. 8
    8
      runtime/src/main/java/org/aspectj/lang/Aspects14.java
  7. 4
    4
      runtime/src/main/java/org/aspectj/runtime/internal/CFlowStack.java
  8. 3
    3
      runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java
  9. 4
    4
      runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java
  10. 6
    6
      runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java
  11. 3
    3
      runtime/src/main/java/org/aspectj/runtime/reflect/AdviceSignatureImpl.java
  12. 3
    3
      runtime/src/main/java/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java
  13. 1
    1
      runtime/src/main/java/org/aspectj/runtime/reflect/CodeSignatureImpl.java
  14. 2
    2
      runtime/src/main/java/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java
  15. 17
    17
      runtime/src/main/java/org/aspectj/runtime/reflect/Factory.java
  16. 3
    3
      runtime/src/main/java/org/aspectj/runtime/reflect/FieldSignatureImpl.java
  17. 2
    2
      runtime/src/main/java/org/aspectj/runtime/reflect/InitializerSignatureImpl.java
  18. 3
    3
      runtime/src/main/java/org/aspectj/runtime/reflect/LockSignatureImpl.java
  19. 1
    1
      runtime/src/main/java/org/aspectj/runtime/reflect/MemberSignatureImpl.java
  20. 7
    7
      runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java
  21. 7
    7
      runtime/src/main/java/org/aspectj/runtime/reflect/SignatureImpl.java
  22. 2
    2
      runtime/src/main/java/org/aspectj/runtime/reflect/SourceLocationImpl.java
  23. 4
    4
      runtime/src/main/java/org/aspectj/runtime/reflect/StringMaker.java
  24. 2
    2
      runtime/src/main/java/org/aspectj/runtime/reflect/UnlockSignatureImpl.java

+ 7
- 7
runtime/src/main/java/org/aspectj/internal/lang/reflect/AjTypeImpl.java View File

*/ */
public AjType<? super T> getSupertype() { public AjType<? super T> getSupertype() {
Class<? super T> superclass = clazz.getSuperclass(); Class<? super T> superclass = clazz.getSuperclass();
return superclass==null ? null : (AjType<? super T>) new AjTypeImpl(superclass);
return superclass==null ? null : (AjType<? super T>) new AjTypeImpl<>(superclass);
} }


/* (non-Javadoc) /* (non-Javadoc)
*/ */
public AjType<?> getEnclosingType() { public AjType<?> getEnclosingType() {
Class<?> enc = clazz.getEnclosingClass(); Class<?> enc = clazz.getEnclosingClass();
return enc != null ? new AjTypeImpl(enc) : null;
return enc != null ? new AjTypeImpl<>(enc) : null;
} }


/* (non-Javadoc) /* (non-Javadoc)
* @see org.aspectj.lang.reflect.AjType#getDeclaringType() * @see org.aspectj.lang.reflect.AjType#getDeclaringType()
*/ */
public AjType<?> getDeclaringType() { public AjType<?> getDeclaringType() {
Class dec = clazz.getDeclaringClass();
return dec != null ? new AjTypeImpl(dec) : null;
Class<?> dec = clazz.getDeclaringClass();
return dec != null ? new AjTypeImpl<>(dec) : null;
} }


public PerClause getPerClause() { public PerClause getPerClause() {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType) * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
*/ */
private Advice[] getDeclaredAdvice(Set ofAdviceTypes) {
private Advice[] getDeclaredAdvice(Set<AdviceKind> ofAdviceTypes) {
if (declaredAdvice == null) initDeclaredAdvice(); if (declaredAdvice == null) initDeclaredAdvice();
List<Advice> adviceList = new ArrayList<>(); List<Advice> adviceList = new ArrayList<>();
for (Advice a : declaredAdvice) { for (Advice a : declaredAdvice) {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType) * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
*/ */
private Advice[] getAdvice(Set ofAdviceTypes) {
private Advice[] getAdvice(Set<AdviceKind> ofAdviceTypes) {
if (advice == null) initAdvice(); if (advice == null) initAdvice();
List<Advice> adviceList = new ArrayList<>(); List<Advice> adviceList = new ArrayList<>();
for (Advice a : advice) { for (Advice a : advice) {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof AjTypeImpl)) return false; if (!(obj instanceof AjTypeImpl)) return false;
AjTypeImpl other = (AjTypeImpl) obj;
AjTypeImpl<?> other = (AjTypeImpl<?>) obj;
return other.clazz.equals(clazz); return other.clazz.equals(clazz);
} }



+ 1
- 1
runtime/src/main/java/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java View File

private PointcutExpression pc; private PointcutExpression pc;
private String msg; private String msg;
private boolean isError; private boolean isError;
private AjType declaringType;
private AjType<?> declaringType;


public DeclareErrorOrWarningImpl(String pointcut, String message, boolean isError, AjType decType) { public DeclareErrorOrWarningImpl(String pointcut, String message, boolean isError, AjType decType) {
this.pc = new PointcutExpressionImpl(pointcut); this.pc = new PointcutExpressionImpl(pointcut);

+ 1
- 1
runtime/src/main/java/org/aspectj/internal/lang/reflect/PointcutImpl.java View File

private final String name; private final String name;
private final PointcutExpression pc; private final PointcutExpression pc;
private final Method baseMethod; private final Method baseMethod;
private final AjType declaringType;
private final AjType<?> declaringType;
private String[] parameterNames = new String[0]; private String[] parameterNames = new String[0];


protected PointcutImpl(String name, String pc, Method method, AjType declaringType, String pNames) { protected PointcutImpl(String name, String pc, Method method, AjType declaringType, String pNames) {

+ 3
- 3
runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java View File

} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// could be a type variable // could be a type variable
TypeVariable[] tVars = classScope.getTypeParameters(); TypeVariable[] tVars = classScope.getTypeParameters();
for (TypeVariable tVar : tVars) {
for (TypeVariable<?> tVar : tVars) {
if (tVar.getName().equals(typeName)) { if (tVar.getName().equals(typeName)) {
return tVar; return tVar;
} }
} }
} }


private static Type makeParameterizedType(String typeName, Class classScope)
private static Type makeParameterizedType(String typeName, Class<?> classScope)
throws ClassNotFoundException { throws ClassNotFoundException {
int paramStart = typeName.indexOf('<'); int paramStart = typeName.indexOf('<');
String baseName = typeName.substring(0, paramStart); String baseName = typeName.substring(0, paramStart);
final Class baseClass = Class.forName(baseName,false,classScope.getClassLoader());
final Class<?> baseClass = Class.forName(baseName,false,classScope.getClassLoader());
int paramEnd = typeName.lastIndexOf('>'); int paramEnd = typeName.lastIndexOf('>');
String params = typeName.substring(paramStart+1,paramEnd); String params = typeName.substring(paramStart+1,paramEnd);
final Type[] typeParams = commaSeparatedListToTypeArray(params,classScope); final Type[] typeParams = commaSeparatedListToTypeArray(params,classScope);

+ 4
- 4
runtime/src/main/java/org/aspectj/lang/Aspects.java View File



// -- hasAspect // -- hasAspect


private static Method getSingletonOrThreadHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getSingletonOrThreadHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method getPerObjectHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getPerObjectHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method getPerTypeWithinHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getPerTypeWithinHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method checkHasAspect(Method method, Class aspectClass) throws NoSuchMethodException {
private static Method checkHasAspect(Method method, Class<?> aspectClass) throws NoSuchMethodException {
method.setAccessible(true); method.setAccessible(true);
if (!method.isAccessible() if (!method.isAccessible()
|| !Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())

+ 8
- 8
runtime/src/main/java/org/aspectj/lang/Aspects14.java View File



// -- aspectOf // -- aspectOf


private static Method getSingletonOrThreadAspectOf(Class aspectClass) throws NoSuchMethodException {
private static Method getSingletonOrThreadAspectOf(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(ASPECTOF, EMPTY_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(ASPECTOF, EMPTY_CLASS_ARRAY);
return checkAspectOf(method, aspectClass); return checkAspectOf(method, aspectClass);
} }


private static Method getPerObjectAspectOf(Class aspectClass) throws NoSuchMethodException {
private static Method getPerObjectAspectOf(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(ASPECTOF, PEROBJECT_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(ASPECTOF, PEROBJECT_CLASS_ARRAY);
return checkAspectOf(method, aspectClass); return checkAspectOf(method, aspectClass);
} }


private static Method getPerTypeWithinAspectOf(Class aspectClass) throws NoSuchMethodException {
private static Method getPerTypeWithinAspectOf(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(ASPECTOF, PERTYPEWITHIN_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(ASPECTOF, PERTYPEWITHIN_CLASS_ARRAY);
return checkAspectOf(method, aspectClass); return checkAspectOf(method, aspectClass);
} }


private static Method checkAspectOf(Method method, Class aspectClass) throws NoSuchMethodException {
private static Method checkAspectOf(Method method, Class<?> aspectClass) throws NoSuchMethodException {
method.setAccessible(true); method.setAccessible(true);
if (!method.isAccessible() if (!method.isAccessible()
|| !Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())


// -- hasAspect // -- hasAspect


private static Method getSingletonOrThreadHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getSingletonOrThreadHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method getPerObjectHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getPerObjectHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method getPerTypeWithinHasAspect(Class aspectClass) throws NoSuchMethodException {
private static Method getPerTypeWithinHasAspect(Class<?> aspectClass) throws NoSuchMethodException {
Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY); Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY);
return checkHasAspect(method, aspectClass); return checkHasAspect(method, aspectClass);
} }


private static Method checkHasAspect(Method method, Class aspectClass) throws NoSuchMethodException {
private static Method checkHasAspect(Method method, Class<?> aspectClass) throws NoSuchMethodException {
method.setAccessible(true); method.setAccessible(true);
if (!method.isAccessible() if (!method.isAccessible()
|| !Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())

+ 4
- 4
runtime/src/main/java/org/aspectj/runtime/internal/CFlowStack.java View File

} }


public void pop() { public void pop() {
Stack s = getThreadStack();
Stack<?> s = getThreadStack();
s.pop(); s.pop();
if (s.isEmpty()) { if (s.isEmpty()) {
stackProxy.removeThreadStack(); stackProxy.removeThreadStack();
} }


public Object peek() { public Object peek() {
Stack stack = getThreadStack();
Stack<?> stack = getThreadStack();
if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException(); if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException();
return (Object)stack.peek(); return (Object)stack.peek();
} }
} }


public CFlow peekCFlow() { public CFlow peekCFlow() {
Stack stack = getThreadStack();
Stack<?> stack = getThreadStack();
if (stack.isEmpty()) return null; if (stack.isEmpty()) return null;
return (CFlow)stack.peek(); return (CFlow)stack.peek();
} }


public CFlow peekTopCFlow() { public CFlow peekTopCFlow() {
Stack stack = getThreadStack();
Stack<?> stack = getThreadStack();
if (stack.isEmpty()) return null; if (stack.isEmpty()) return null;
return (CFlow)stack.elementAt(0); return (CFlow)stack.elementAt(0);
} }

+ 3
- 3
runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java View File

import java.util.Hashtable; import java.util.Hashtable;


public class ThreadCounterImpl11 implements ThreadCounter { public class ThreadCounterImpl11 implements ThreadCounter {
private Hashtable counters = new Hashtable();
private Hashtable<Thread, Counter> counters = new Hashtable<>();
private Thread cached_thread; private Thread cached_thread;
private Counter cached_counter; private Counter cached_counter;


// Collect more often if there are many threads, but not *too* often // Collect more often if there are many threads, but not *too* often
int size = Math.max(1, counters.size()); // should be >1 b/c always live threads, but... int size = Math.max(1, counters.size()); // should be >1 b/c always live threads, but...
if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) {
List dead_stacks = new ArrayList();
for (Enumeration e = counters.keys(); e.hasMoreElements(); ) {
List<Thread> dead_stacks = new ArrayList<>();
for (Enumeration<Thread> e = counters.keys(); e.hasMoreElements(); ) {
Thread t = (Thread)e.nextElement(); Thread t = (Thread)e.nextElement();
if (!t.isAlive()) dead_stacks.add(t); if (!t.isAlive()) dead_stacks.add(t);
} }

+ 4
- 4
runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java View File



public class ThreadStackFactoryImpl implements ThreadStackFactory { public class ThreadStackFactoryImpl implements ThreadStackFactory {


private static class ThreadStackImpl extends ThreadLocal implements ThreadStack {
public Object initialValue() {
private static class ThreadStackImpl extends ThreadLocal<Stack> implements ThreadStack {
public Stack initialValue() {
return new Stack(); return new Stack();
} }
public Stack getThreadStack() { public Stack getThreadStack() {
return new ThreadStackImpl(); return new ThreadStackImpl();
} }


private static class ThreadCounterImpl extends ThreadLocal implements ThreadCounter {
private static class ThreadCounterImpl extends ThreadLocal<ThreadCounterImpl.Counter> implements ThreadCounter {


public Object initialValue() {
public Counter initialValue() {
return new Counter(); return new Counter();
} }
public Counter getThreadCounter() { public Counter getThreadCounter() {

+ 6
- 6
runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java View File

import java.util.Stack; import java.util.Stack;


public class ThreadStackImpl11 implements ThreadStack { public class ThreadStackImpl11 implements ThreadStack {
private Hashtable stacks = new Hashtable();
private Hashtable<Thread, Stack> stacks = new Hashtable<>();
private Thread cached_thread; private Thread cached_thread;
private Stack cached_stack; private Stack cached_stack;
private int change_count = 0; private int change_count = 0;
public synchronized Stack getThreadStack() { public synchronized Stack getThreadStack() {
if (Thread.currentThread() != cached_thread) { if (Thread.currentThread() != cached_thread) {
cached_thread = Thread.currentThread(); cached_thread = Thread.currentThread();
cached_stack = (Stack)stacks.get(cached_thread);
cached_stack = (Stack<?>)stacks.get(cached_thread);
if (cached_stack == null) { if (cached_stack == null) {
cached_stack = new Stack();
cached_stack = new Stack<>();
stacks.put(cached_thread, cached_stack); stacks.put(cached_thread, cached_stack);
} }
change_count++; change_count++;
// Collect more often if there are many threads, but not *too* often // Collect more often if there are many threads, but not *too* often
int size = Math.max(1, stacks.size()); // should be >1 b/c always live threads, but... int size = Math.max(1, stacks.size()); // should be >1 b/c always live threads, but...
if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) {
Stack dead_stacks = new Stack();
for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) {
Stack<Thread> dead_stacks = new Stack<>();
for (Enumeration<Thread> e = stacks.keys(); e.hasMoreElements(); ) {
Thread t = (Thread)e.nextElement(); Thread t = (Thread)e.nextElement();
if (!t.isAlive()) dead_stacks.push(t); if (!t.isAlive()) dead_stacks.push(t);
} }
for (Enumeration e = dead_stacks.elements(); e.hasMoreElements(); ) {
for (Enumeration<Thread> e = dead_stacks.elements(); e.hasMoreElements(); ) {
Thread t = (Thread)e.nextElement(); Thread t = (Thread)e.nextElement();
stacks.remove(t); stacks.remove(t);
} }

+ 3
- 3
runtime/src/main/java/org/aspectj/runtime/reflect/AdviceSignatureImpl.java View File

import org.aspectj.lang.reflect.AdviceSignature; import org.aspectj.lang.reflect.AdviceSignature;


class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature { class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
Class returnType;
Class<?> returnType;
private Method adviceMethod = null; private Method adviceMethod = null;


AdviceSignatureImpl(int modifiers, String name, Class declaringType,
AdviceSignatureImpl(int modifiers, String name, Class<?> declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
Class returnType)
Class<?> returnType)
{ {
super(modifiers, name, declaringType, parameterTypes, parameterNames, super(modifiers, name, declaringType, parameterTypes, parameterNames,
exceptionTypes); exceptionTypes);

+ 3
- 3
runtime/src/main/java/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java View File

import org.aspectj.lang.reflect.CatchClauseSignature; import org.aspectj.lang.reflect.CatchClauseSignature;


class CatchClauseSignatureImpl extends SignatureImpl implements CatchClauseSignature { class CatchClauseSignatureImpl extends SignatureImpl implements CatchClauseSignature {
Class parameterType;
Class<?> parameterType;
String parameterName; String parameterName;


CatchClauseSignatureImpl(Class declaringType,
Class parameterType, String parameterName)
CatchClauseSignatureImpl(Class<?> declaringType,
Class<?> parameterType, String parameterName)
{ {
super(0, "catch", declaringType); super(0, "catch", declaringType);
this.parameterType = parameterType; this.parameterType = parameterType;

+ 1
- 1
runtime/src/main/java/org/aspectj/runtime/reflect/CodeSignatureImpl.java View File

String[] parameterNames; String[] parameterNames;
Class[] exceptionTypes; Class[] exceptionTypes;


CodeSignatureImpl(int modifiers, String name, Class declaringType,
CodeSignatureImpl(int modifiers, String name, Class<?> declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes)
{ {
super(modifiers, name, declaringType); super(modifiers, name, declaringType);

+ 2
- 2
runtime/src/main/java/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java View File

import org.aspectj.lang.reflect.ConstructorSignature; import org.aspectj.lang.reflect.ConstructorSignature;


class ConstructorSignatureImpl extends CodeSignatureImpl implements ConstructorSignature { class ConstructorSignatureImpl extends CodeSignatureImpl implements ConstructorSignature {
private Constructor constructor;
private Constructor<?> constructor;


ConstructorSignatureImpl(int modifiers, Class declaringType,
ConstructorSignatureImpl(int modifiers, Class<?> declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes)
{ {
super(modifiers, "<init>", declaringType, parameterTypes, parameterNames, exceptionTypes); super(modifiers, "<init>", declaringType, parameterTypes, parameterNames, exceptionTypes);

+ 17
- 17
runtime/src/main/java/org/aspectj/runtime/reflect/Factory.java View File

import org.aspectj.lang.reflect.UnlockSignature; import org.aspectj.lang.reflect.UnlockSignature;


public final class Factory { public final class Factory {
Class lexicalClass;
Class<?> lexicalClass;
ClassLoader lookupClassLoader; ClassLoader lookupClassLoader;
String filename; String filename;
int count; int count;
private static final Class[] NO_TYPES = new Class[0]; private static final Class[] NO_TYPES = new Class[0];
private static final String[] NO_STRINGS = new String[0]; private static final String[] NO_STRINGS = new String[0];


static Hashtable prims = new Hashtable();
static Hashtable<String, Class<?>> prims = new Hashtable<>();
static { static {
prims.put("void", Void.TYPE); prims.put("void", Void.TYPE);
prims.put("boolean", Boolean.TYPE); prims.put("boolean", Boolean.TYPE);
prims.put("double", Double.TYPE); prims.put("double", Double.TYPE);
} }


static Class makeClass(String s, ClassLoader loader) {
static Class<?> makeClass(String s, ClassLoader loader) {
if (s.equals("*")) if (s.equals("*"))
return null; return null;
Class ret = (Class)prims.get(s);
Class<?> ret = (Class)prims.get(s);
if (ret != null) if (ret != null)
return ret; return ret;
try { try {
.getReturnType()); .getReturnType());
kind = JoinPoint.METHOD_EXECUTION; kind = JoinPoint.METHOD_EXECUTION;
} else if (member instanceof Constructor) { } else if (member instanceof Constructor) {
Constructor cons = (Constructor) member;
Constructor<?> cons = (Constructor<?>) member;
sig = new ConstructorSignatureImpl(cons.getModifiers(), cons.getDeclaringClass(), cons.getParameterTypes(), sig = new ConstructorSignatureImpl(cons.getModifiers(), cons.getDeclaringClass(), cons.getParameterTypes(),
new String[cons.getParameterTypes().length], cons.getExceptionTypes()); new String[cons.getParameterTypes().length], cons.getExceptionTypes());
kind = JoinPoint.CONSTRUCTOR_EXECUTION; kind = JoinPoint.CONSTRUCTOR_EXECUTION;


public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes, public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes,
String paramNames, String exceptionTypes, String returnType) { String paramNames, String exceptionTypes, String returnType) {
Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);
return makeMethodSig(modifiers, methodName, declaringTypeClass, paramTypes, paramNames, exceptionTypes, returnType); return makeMethodSig(modifiers, methodName, declaringTypeClass, paramTypes, paramNames, exceptionTypes, returnType);
} }


for (int i = 0; i < numParams; i++) for (int i = 0; i < numParams; i++)
exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader);


Class returnTypeClass = makeClass(returnType, lookupClassLoader);
Class<?> returnTypeClass = makeClass(returnType, lookupClassLoader);


MethodSignatureImpl ret = new MethodSignatureImpl(modifiersAsInt, methodName, declaringTypeClass, paramTypeClasses, MethodSignatureImpl ret = new MethodSignatureImpl(modifiersAsInt, methodName, declaringTypeClass, paramTypeClasses,
paramNamesArray, exceptionTypeClasses, returnTypeClass); paramNamesArray, exceptionTypeClasses, returnTypeClass);
String exceptionTypes) { String exceptionTypes) {
int modifiersAsInt = Integer.parseInt(modifiers, 16); int modifiersAsInt = Integer.parseInt(modifiers, 16);


Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);


StringTokenizer st = new StringTokenizer(paramTypes, ":"); StringTokenizer st = new StringTokenizer(paramTypes, ":");
int numParams = st.countTokens(); int numParams = st.countTokens();


public FieldSignature makeFieldSig(String modifiers, String name, String declaringType, String fieldType) { public FieldSignature makeFieldSig(String modifiers, String name, String declaringType, String fieldType) {
int modifiersAsInt = Integer.parseInt(modifiers, 16); int modifiersAsInt = Integer.parseInt(modifiers, 16);
Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class fieldTypeClass = makeClass(fieldType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> fieldTypeClass = makeClass(fieldType, lookupClassLoader);


FieldSignatureImpl ret = new FieldSignatureImpl(modifiersAsInt, name, declaringTypeClass, fieldTypeClass); FieldSignatureImpl ret = new FieldSignatureImpl(modifiersAsInt, name, declaringTypeClass, fieldTypeClass);
ret.setLookupClassLoader(lookupClassLoader); ret.setLookupClassLoader(lookupClassLoader);
String exceptionTypes, String returnType) { String exceptionTypes, String returnType) {
int modifiersAsInt = Integer.parseInt(modifiers, 16); int modifiersAsInt = Integer.parseInt(modifiers, 16);


Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);


StringTokenizer st = new StringTokenizer(paramTypes, ":"); StringTokenizer st = new StringTokenizer(paramTypes, ":");
int numParams = st.countTokens(); int numParams = st.countTokens();
exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader); exceptionTypeClasses[i] = makeClass(st.nextToken(), lookupClassLoader);
; ;


Class returnTypeClass = makeClass(returnType, lookupClassLoader);
Class<?> returnTypeClass = makeClass(returnType, lookupClassLoader);


AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiersAsInt, name, declaringTypeClass, paramTypeClasses, AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiersAsInt, name, declaringTypeClass, paramTypeClasses,
paramNamesArray, exceptionTypeClasses, returnTypeClass); paramNamesArray, exceptionTypeClasses, returnTypeClass);


public InitializerSignature makeInitializerSig(String modifiers, String declaringType) { public InitializerSignature makeInitializerSig(String modifiers, String declaringType) {
int modifiersAsInt = Integer.parseInt(modifiers, 16); int modifiersAsInt = Integer.parseInt(modifiers, 16);
Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);


InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiersAsInt, declaringTypeClass); InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiersAsInt, declaringTypeClass);
ret.setLookupClassLoader(lookupClassLoader); ret.setLookupClassLoader(lookupClassLoader);
} }


public CatchClauseSignature makeCatchClauseSig(String declaringType, String parameterType, String parameterName) { public CatchClauseSignature makeCatchClauseSig(String declaringType, String parameterType, String parameterName) {
Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
Class<?> declaringTypeClass = makeClass(declaringType, lookupClassLoader);


StringTokenizer st = new StringTokenizer(parameterType, ":"); StringTokenizer st = new StringTokenizer(parameterType, ":");
Class parameterTypeClass = makeClass(st.nextToken(), lookupClassLoader);
Class<?> parameterTypeClass = makeClass(st.nextToken(), lookupClassLoader);


st = new StringTokenizer(parameterName, ":"); st = new StringTokenizer(parameterName, ":");
String parameterNameForReturn = st.nextToken(); String parameterNameForReturn = st.nextToken();
} }


public LockSignature makeLockSig() { public LockSignature makeLockSig() {
Class declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader);
Class<?> declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader);
LockSignatureImpl ret = new LockSignatureImpl(declaringTypeClass); LockSignatureImpl ret = new LockSignatureImpl(declaringTypeClass);
ret.setLookupClassLoader(lookupClassLoader); ret.setLookupClassLoader(lookupClassLoader);
return ret; return ret;
} }


public UnlockSignature makeUnlockSig() { public UnlockSignature makeUnlockSig() {
Class declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader);
Class<?> declaringTypeClass = makeClass("Ljava/lang/Object;", lookupClassLoader);
UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringTypeClass); UnlockSignatureImpl ret = new UnlockSignatureImpl(declaringTypeClass);
ret.setLookupClassLoader(lookupClassLoader); ret.setLookupClassLoader(lookupClassLoader);
return ret; return ret;

+ 3
- 3
runtime/src/main/java/org/aspectj/runtime/reflect/FieldSignatureImpl.java View File

import org.aspectj.lang.reflect.FieldSignature; import org.aspectj.lang.reflect.FieldSignature;


public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature { public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature {
Class fieldType;
Class<?> fieldType;
private Field field; private Field field;


FieldSignatureImpl(int modifiers, String name, Class declaringType,
Class fieldType)
FieldSignatureImpl(int modifiers, String name, Class<?> declaringType,
Class<?> fieldType)
{ {
super(modifiers, name, declaringType); super(modifiers, name, declaringType);
this.fieldType = fieldType; this.fieldType = fieldType;

+ 2
- 2
runtime/src/main/java/org/aspectj/runtime/reflect/InitializerSignatureImpl.java View File

import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;


class InitializerSignatureImpl extends CodeSignatureImpl implements InitializerSignature { class InitializerSignatureImpl extends CodeSignatureImpl implements InitializerSignature {
private Constructor constructor;
private Constructor<?> constructor;


InitializerSignatureImpl(int modifiers, Class declaringType) {
InitializerSignatureImpl(int modifiers, Class<?> declaringType) {
super(modifiers, Modifier.isStatic(modifiers) ? "<clinit>" : "<init>", declaringType, EMPTY_CLASS_ARRAY, super(modifiers, Modifier.isStatic(modifiers) ? "<clinit>" : "<init>", declaringType, EMPTY_CLASS_ARRAY,
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY); EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY);
} }

+ 3
- 3
runtime/src/main/java/org/aspectj/runtime/reflect/LockSignatureImpl.java View File

import org.aspectj.lang.reflect.LockSignature; import org.aspectj.lang.reflect.LockSignature;


class LockSignatureImpl extends SignatureImpl implements LockSignature { class LockSignatureImpl extends SignatureImpl implements LockSignature {
private Class parameterType;
private Class<?> parameterType;


LockSignatureImpl(Class c) {
LockSignatureImpl(Class<?> c) {
super(Modifier.STATIC, "lock", c); super(Modifier.STATIC, "lock", c);
parameterType = c; parameterType = c;
} }
return "lock("+sm.makeTypeName(parameterType)+")"; return "lock("+sm.makeTypeName(parameterType)+")";
} }


public Class getParameterType() {
public Class<?> getParameterType() {
if (parameterType == null) parameterType = extractType(3); if (parameterType == null) parameterType = extractType(3);
return parameterType; return parameterType;
} }

+ 1
- 1
runtime/src/main/java/org/aspectj/runtime/reflect/MemberSignatureImpl.java View File



abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature { abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature {


MemberSignatureImpl(int modifiers, String name, Class declaringType) {
MemberSignatureImpl(int modifiers, String name, Class<?> declaringType) {
super(modifiers, name, declaringType); super(modifiers, name, declaringType);
} }



+ 7
- 7
runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java View File



class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature { class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature {
private Method method; private Method method;
Class returnType;
Class<?> returnType;


MethodSignatureImpl(int modifiers, String name, Class declaringType, Class[] parameterTypes, String[] parameterNames,
Class[] exceptionTypes, Class returnType) {
MethodSignatureImpl(int modifiers, String name, Class<?> declaringType, Class[] parameterTypes, String[] parameterNames,
Class[] exceptionTypes, Class<?> returnType) {
super(modifiers, name, declaringType, parameterTypes, parameterNames, exceptionTypes); super(modifiers, name, declaringType, parameterTypes, parameterNames, exceptionTypes);
this.returnType = returnType; this.returnType = returnType;
} }
*/ */
public Method getMethod() { public Method getMethod() {
if (method == null) { if (method == null) {
Class dtype = getDeclaringType();
Class<?> dtype = getDeclaringType();
try { try {
method = dtype.getDeclaredMethod(getName(), getParameterTypes()); method = dtype.getDeclaredMethod(getName(), getParameterTypes());
} catch (NoSuchMethodException nsmEx) { } catch (NoSuchMethodException nsmEx) {
// pr154427 - search // pr154427 - search
Set searched = new HashSet();
Set<Class<?>> searched = new HashSet<>();
searched.add(dtype); // avoids another getDeclaredMethod() on dtype searched.add(dtype); // avoids another getDeclaredMethod() on dtype
method = search(dtype, getName(), getParameterTypes(), searched); method = search(dtype, getName(), getParameterTypes(), searched);
} }
* @param searched a set of types already searched to avoid looking at anything twice * @param searched a set of types already searched to avoid looking at anything twice
* @return the method if found, or null if not found * @return the method if found, or null if not found
*/ */
private Method search(Class type, String name, Class[] params, Set searched) {
private Method search(Class<?> type, String name, Class[] params, Set<Class<?>> searched) {
if (type == null) { if (type == null) {
return null; return null;
} }
} }
Class[] superinterfaces = type.getInterfaces(); Class[] superinterfaces = type.getInterfaces();
if (superinterfaces != null) { if (superinterfaces != null) {
for (Class superinterface : superinterfaces) {
for (Class<?> superinterface : superinterfaces) {
m = search(superinterface, name, params, searched); m = search(superinterface, name, params, searched);
if (m != null) { if (m != null) {
return m; return m;

+ 7
- 7
runtime/src/main/java/org/aspectj/runtime/reflect/SignatureImpl.java View File

int modifiers = -1; int modifiers = -1;
String name; String name;
String declaringTypeName; String declaringTypeName;
Class declaringType;
Class<?> declaringType;
Cache stringCache; Cache stringCache;


SignatureImpl(int modifiers, String name, Class declaringType) {
SignatureImpl(int modifiers, String name, Class<?> declaringType) {
this.modifiers = modifiers; this.modifiers = modifiers;
this.name = name; this.name = name;
this.declaringType = declaringType; this.declaringType = declaringType;
return declaringTypeName; return declaringTypeName;
} }


String fullTypeName(Class type) {
String fullTypeName(Class<?> type) {
if (type == null) return "ANONYMOUS"; if (type == null) return "ANONYMOUS";
if (type.isArray()) return fullTypeName(type.getComponentType()) + "[]"; if (type.isArray()) return fullTypeName(type.getComponentType()) + "[]";
return type.getName().replace('$', '.'); return type.getName().replace('$', '.');
return name.substring(dot+1); return name.substring(dot+1);
} }


String shortTypeName(Class type) {
String shortTypeName(Class<?> type) {
if (type == null) return "ANONYMOUS"; if (type == null) return "ANONYMOUS";
if (type.isArray()) return shortTypeName(type.getComponentType()) + "[]"; if (type.isArray()) return shortTypeName(type.getComponentType()) + "[]";
return stripPackageName(type.getName()).replace('$', '.'); return stripPackageName(type.getName()).replace('$', '.');
return Integer.parseInt(s, 16); return Integer.parseInt(s, 16);
} }


Class extractType(int n) {
Class<?> extractType(int n) {
String s = extractString(n); String s = extractString(n);
return Factory.makeClass(s,getLookupClassLoader()); return Factory.makeClass(s,getLookupClassLoader());
} }


// separate implementation so we don't need SoftReference to hold the field... // separate implementation so we don't need SoftReference to hold the field...
private static final class CacheImpl implements Cache { private static final class CacheImpl implements Cache {
private java.lang.ref.SoftReference toStringCacheRef;
private java.lang.ref.SoftReference<String[]> toStringCacheRef;


public CacheImpl() { public CacheImpl() {
makeCache(); makeCache();


private String[] makeCache() { private String[] makeCache() {
String[] array = new String[3]; String[] array = new String[3];
toStringCacheRef = new java.lang.ref.SoftReference(array);
toStringCacheRef = new java.lang.ref.SoftReference<>(array);
return array; return array;
} }



+ 2
- 2
runtime/src/main/java/org/aspectj/runtime/reflect/SourceLocationImpl.java View File

import org.aspectj.lang.reflect.SourceLocation; import org.aspectj.lang.reflect.SourceLocation;


class SourceLocationImpl implements SourceLocation { class SourceLocationImpl implements SourceLocation {
Class withinType;
Class<?> withinType;
String fileName; String fileName;
int line; int line;


SourceLocationImpl(Class withinType, String fileName, int line) {
SourceLocationImpl(Class<?> withinType, String fileName, int line) {
this.withinType = withinType; this.withinType = withinType;
this.fileName = fileName; this.fileName = fileName;
this.line = line; this.line = line;

+ 4
- 4
runtime/src/main/java/org/aspectj/runtime/reflect/StringMaker.java View File

return name.substring(dot+1); return name.substring(dot+1);
} }


String makeTypeName(Class type, String typeName, boolean shortName) {
String makeTypeName(Class<?> type, String typeName, boolean shortName) {
if (type == null) return "ANONYMOUS"; if (type == null) return "ANONYMOUS";
if (type.isArray()) { if (type.isArray()) {
Class componentType = type.getComponentType();
Class<?> componentType = type.getComponentType();
return makeTypeName(componentType, componentType.getName(), shortName) + "[]"; return makeTypeName(componentType, componentType.getName(), shortName) + "[]";
} }
if (shortName) { if (shortName) {
} }
} }


public String makeTypeName(Class type) {
public String makeTypeName(Class<?> type) {
return makeTypeName(type, type.getName(),shortTypeNames); return makeTypeName(type, type.getName(),shortTypeNames);
} }


public String makePrimaryTypeName(Class type, String typeName) {
public String makePrimaryTypeName(Class<?> type, String typeName) {
return makeTypeName(type, typeName, shortPrimaryTypeNames); return makeTypeName(type, typeName, shortPrimaryTypeNames);
} }



+ 2
- 2
runtime/src/main/java/org/aspectj/runtime/reflect/UnlockSignatureImpl.java View File

import org.aspectj.lang.reflect.UnlockSignature; import org.aspectj.lang.reflect.UnlockSignature;


class UnlockSignatureImpl extends SignatureImpl implements UnlockSignature { class UnlockSignatureImpl extends SignatureImpl implements UnlockSignature {
private Class parameterType;
private Class<?> parameterType;


UnlockSignatureImpl(Class c) {
UnlockSignatureImpl(Class<?> c) {
super(Modifier.STATIC, "unlock", c); super(Modifier.STATIC, "unlock", c);
parameterType = c; parameterType = c;
} }

Loading…
Cancel
Save