From: Andy Clement Date: Thu, 24 Jan 2019 20:02:42 +0000 (-0800) Subject: mavenizing runtime module - complete X-Git-Tag: V1_9_3RC1~91 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e01e4369b4c60775d679d8de678f54097fdc3120;p=aspectj.git mavenizing runtime module - complete --- diff --git a/runtime/.classpath b/runtime/.classpath deleted file mode 100644 index f33c50284..000000000 --- a/runtime/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/runtime/.cvsignore b/runtime/.cvsignore deleted file mode 100644 index 50f446ead..000000000 --- a/runtime/.cvsignore +++ /dev/null @@ -1,4 +0,0 @@ -bin -ant.properties -runtime.mf.txt -bintest diff --git a/runtime/.project b/runtime/.project deleted file mode 100644 index 91c0089c8..000000000 --- a/runtime/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - runtime - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/runtime/build.xml b/runtime/build.xml deleted file mode 100644 index 2102111ef..000000000 --- a/runtime/build.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/runtime/pom.xml b/runtime/pom.xml new file mode 100644 index 000000000..683d24aba --- /dev/null +++ b/runtime/pom.xml @@ -0,0 +1,17 @@ + + 4.0.0 + + + org.aspectj + aspectj-parent + 1.9.3.BUILD-SNAPSHOT + .. + + + runtime + jar + runtime + + diff --git a/runtime/src/.cvsignore b/runtime/src/.cvsignore deleted file mode 100644 index a3f0b1b77..000000000 --- a/runtime/src/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.lst diff --git a/runtime/src/main/java/org/aspectj/lang/Aspects14.java b/runtime/src/main/java/org/aspectj/lang/Aspects14.java new file mode 100644 index 000000000..b7f3a3a4b --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/Aspects14.java @@ -0,0 +1,188 @@ +/******************************************************************************* + * Copyright (c) 2006 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * variant of Aspects in the aspectj5rt project - this one isn't Java5 - Andy Clement + *******************************************************************************/ +package org.aspectj.lang; + + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/** + * For users working on a level of Java prior to Java5, Aspects14 handles generic aspectOf methods when they + * are not available in the aspects but added later on through load time weaving. Users on Java5 should use + * the class Aspects instead. + *

+ * Aspects14.aspectOf(..) is doing reflective calls to the aspect aspectOf, so for better performance + * consider using ajc compilation of the aspects and using them as a binary dependancies in your project. + */ +public class Aspects14 { + + private final static Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private final static Class[] PEROBJECT_CLASS_ARRAY = new Class[]{Object.class}; + private final static Class[] PERTYPEWITHIN_CLASS_ARRAY = new Class[]{Class.class}; + private final static Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + private final static String ASPECTOF = "aspectOf"; + private final static String HASASPECT = "hasAspect"; + + /** + * Returns the singleton aspect or the percflow / percflowbelow associated with the current thread + * + * @param aspectClass aspect class for which to discover the aspect instance + * @return an aspect instance + * @throws NoAspectBoundException if no such aspect + */ + public static Object aspectOf(Class aspectClass) throws NoAspectBoundException { + try { + return getSingletonOrThreadAspectOf(aspectClass).invoke(null, EMPTY_OBJECT_ARRAY); + } catch (InvocationTargetException e) { + //FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs + throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); + } catch (Exception e) { + throw new NoAspectBoundException(aspectClass.getName(), e); + } + } + + /** + * Returns the perthis / pertarget aspect + * @param aspectClass aspect class for which to discover the aspect instance + * @param perObject object for which to discover the aspect instance + * @return an aspect instance + * @throws NoAspectBoundException if no such aspect, or no aspect bound + */ + public static Object aspectOf(Class aspectClass, Object perObject) throws NoAspectBoundException { + try { + return getPerObjectAspectOf(aspectClass).invoke(null, new Object[]{perObject}); + } catch (InvocationTargetException e) { + //FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs + throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); + } catch (Exception e) { + throw new NoAspectBoundException(aspectClass.getName(), e); + } + } + + /** + * Returns the pertypewithin aspect + * @param aspectClass aspect class for which to discover the aspect instance + * @param perTypeWithin class + * @return + * @throws NoAspectBoundException if no such aspect, or no aspect bound + */ + public static Object aspectOf(Class aspectClass, Class perTypeWithin) throws NoAspectBoundException { + try { + return getPerTypeWithinAspectOf(aspectClass).invoke(null, new Object[]{perTypeWithin}); + } catch (InvocationTargetException e) { +// FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs + throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); + } catch (Exception e) { + throw new NoAspectBoundException(aspectClass.getName(), e); + } + } + + /** + * Returns true if singleton aspect or percflow / percflowbelow aspect is bound + * + * @param aspectClass aspect class for which to check the aspect instance + * @return + * @throws NoAspectBoundException if not bound + */ + public static boolean hasAspect(Class aspectClass) throws NoAspectBoundException { + try { + return ((Boolean)getSingletonOrThreadHasAspect(aspectClass).invoke(null, EMPTY_OBJECT_ARRAY)).booleanValue(); + } catch (Exception e) { + return false; + } + } + + /** + * Returns true if the perthis / pertarget aspect is bound + * @param aspectClass aspect class for which to check the aspect instance + * @param perObject + * @return true if aspect instance exists for the class/object combination + * @throws NoAspectBoundException if not bound + */ + public static boolean hasAspect(Class aspectClass, Object perObject) throws NoAspectBoundException { + try { + return ((Boolean)getPerObjectHasAspect(aspectClass).invoke(null, new Object[]{perObject})).booleanValue(); + } catch (Exception e) { + return false; + } + } + + /** + * Returns true if the pertypewithin aspect is bound + * @param aspectClass aspect class for which to check the aspect instance + * @param perTypeWithin class + * @return true if aspect instance exists for this aspect class/pertypewithin class combination + * @throws NoAspectBoundException if not bound + */ + public static boolean hasAspect(Class aspectClass, Class perTypeWithin) throws NoAspectBoundException { + try { + return ((Boolean)getPerTypeWithinHasAspect(aspectClass).invoke(null, new Object[]{perTypeWithin})).booleanValue(); + } catch (Exception e) { + return false; + } + } + + // -- aspectOf + + private static Method getSingletonOrThreadAspectOf(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(ASPECTOF, EMPTY_CLASS_ARRAY); + return checkAspectOf(method, aspectClass); + } + + private static Method getPerObjectAspectOf(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(ASPECTOF, PEROBJECT_CLASS_ARRAY); + return checkAspectOf(method, aspectClass); + } + + private static Method getPerTypeWithinAspectOf(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(ASPECTOF, PERTYPEWITHIN_CLASS_ARRAY); + return checkAspectOf(method, aspectClass); + } + + private static Method checkAspectOf(Method method, Class aspectClass) throws NoSuchMethodException { + method.setAccessible(true); + if (!method.isAccessible() + || !Modifier.isPublic(method.getModifiers()) + || !Modifier.isStatic(method.getModifiers())) { + throw new NoSuchMethodException(aspectClass.getName() + ".aspectOf(..) is not accessible public static"); + } + return method; + } + + // -- hasAspect + + private static Method getSingletonOrThreadHasAspect(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY); + return checkHasAspect(method, aspectClass); + } + + private static Method getPerObjectHasAspect(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY); + return checkHasAspect(method, aspectClass); + } + + private static Method getPerTypeWithinHasAspect(Class aspectClass) throws NoSuchMethodException { + Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY); + return checkHasAspect(method, aspectClass); + } + + private static Method checkHasAspect(Method method, Class aspectClass) throws NoSuchMethodException { + method.setAccessible(true); + if (!method.isAccessible() + || !Modifier.isPublic(method.getModifiers()) + || !Modifier.isStatic(method.getModifiers())) { + throw new NoSuchMethodException(aspectClass.getName() + ".hasAspect(..) is not accessible public static"); + } + return method; + } +} diff --git a/runtime/src/main/java/org/aspectj/lang/JoinPoint.java b/runtime/src/main/java/org/aspectj/lang/JoinPoint.java new file mode 100644 index 000000000..5d66c7930 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/JoinPoint.java @@ -0,0 +1,204 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang; + +import org.aspectj.lang.reflect.SourceLocation; + +/** + *

Provides reflective access to both the state available at a join point and + * static information about it. This information is available from the body + * of advice using the special form thisJoinPoint. The primary + * use of this reflective information is for tracing and logging applications. + *

+ * + *
+ * aspect Logging {
+ *     before(): within(com.bigboxco..*) && execution(public * *(..)) {
+ *         System.err.println("entering: " + thisJoinPoint);
+ *         System.err.println("  w/args: " + thisJoinPoint.getArgs());
+ *         System.err.println("      at: " + thisJoinPoint.getSourceLocation());
+ *     }
+ * }
+ * 
+ */ +public interface JoinPoint { + + String toString(); + + /** + * Returns an abbreviated string representation of the join point. + */ + String toShortString(); + + /** + * Returns an extended string representation of the join point. + */ + String toLongString(); + + /** + *

Returns the currently executing object. This will always be + * the same object as that matched by the this pointcut + * designator. Unless you specifically need this reflective access, + * you should use the this pointcut designator to + * get at this object for better static typing and performance.

+ * + *

Returns null when there is no currently executing object available. + * This includes all join points that occur in a static context.

+ */ + Object getThis(); + + /** + *

Returns the target object. This will always be + * the same object as that matched by the target pointcut + * designator. Unless you specifically need this reflective access, + * you should use the target pointcut designator to + * get at this object for better static typing and performance.

+ * + *

Returns null when there is no target object.

+ + */ + Object getTarget(); + + /** + *

Returns the arguments at this join point.

+ */ + Object[] getArgs(); + + /** Returns the signature at the join point. + * + * getStaticPart().getSignature() returns the same object + */ + Signature getSignature(); + + /**

Returns the source location corresponding to the join point.

+ * + *

If there is no source location available, returns null.

+ * + *

Returns the SourceLocation of the defining class for default constructors.

+ * + *

getStaticPart().getSourceLocation() returns the same object.

+ */ + SourceLocation getSourceLocation(); + + /** Returns a String representing the kind of join point. This + * String is guaranteed to be + * interned. getStaticPart().getKind() returns + * the same object. + */ + String getKind(); + + /** + *

This helper object contains only the static information about a join point. + * It is available from the JoinPoint.getStaticPart() method, and + * can be accessed separately within advice using the special form + * thisJoinPointStaticPart.

+ * + *

If you are only interested in the static information about a join point, + * you should access it through this type for the best performance. This + * is particularly useful for library methods that want to do serious + * manipulations of this information, i.e.

+ * + *
+     * public class LoggingUtils {
+     *     public static void prettyPrint(JoinPoint.StaticPart jp) {
+     *         ...
+     *     }
+     * }
+     *
+     * aspect Logging {
+     *     before(): ... { LoggingUtils.prettyPrint(thisJoinPointStaticPart); }
+     * }
+     * 
+ * + * @see JoinPoint#getStaticPart() + */ + public interface StaticPart { + /** Returns the signature at the join point. */ + Signature getSignature(); + + /**

Returns the source location corresponding to the join point.

+ * + *

If there is no source location available, returns null.

+ * + *

Returns the SourceLocation of the defining class for default constructors.

+ */ + SourceLocation getSourceLocation(); + + /**

Returns a String representing the kind of join point. This String + * is guaranteed to be interned

+ */ + 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. + *
+ * The id is guaranteed to remain constant across repeated executions + * of a program but may change if the code is recompiled. + *
+ * 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. + *
+ * 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(); + + /** + * Returns an abbreviated string representation of the join point + */ + String toShortString(); + + /** + * Returns an extended string representation of the join point + */ + String toLongString(); + } + + public interface EnclosingStaticPart extends StaticPart {} + + /** + * Returns an object that encapsulates the static parts of this join point. + */ + StaticPart getStaticPart(); + + + /** + * The legal return values from getKind() + */ + static String METHOD_EXECUTION = "method-execution"; + static String METHOD_CALL = "method-call"; + static String CONSTRUCTOR_EXECUTION = "constructor-execution"; + static String CONSTRUCTOR_CALL = "constructor-call"; + static String FIELD_GET = "field-get"; + static String FIELD_SET = "field-set"; + static String STATICINITIALIZATION = "staticinitialization"; + static String PREINITIALIZATION = "preinitialization"; + static String INITIALIZATION = "initialization"; + static String EXCEPTION_HANDLER = "exception-handler"; + static String SYNCHRONIZATION_LOCK = "lock"; + static String SYNCHRONIZATION_UNLOCK = "unlock"; + + static String ADVICE_EXECUTION = "adviceexecution"; + +} diff --git a/runtime/src/main/java/org/aspectj/lang/NoAspectBoundException.java b/runtime/src/main/java/org/aspectj/lang/NoAspectBoundException.java new file mode 100644 index 000000000..286e4c1f1 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/NoAspectBoundException.java @@ -0,0 +1,34 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang; + +/** + * Thrown by the aspectOf special method on aspect types + * when there is no aspect of that type currently bound. + */ +public class NoAspectBoundException extends RuntimeException { + Throwable cause; + public NoAspectBoundException(String aspectName, Throwable inner) { + super(inner == null ? aspectName : + "Exception while initializing " +aspectName + ": " +inner); + this.cause = inner; + } + + public NoAspectBoundException() { + } + + public Throwable getCause() { return cause; } + +} diff --git a/runtime/src/main/java/org/aspectj/lang/ProceedingJoinPoint.java b/runtime/src/main/java/org/aspectj/lang/ProceedingJoinPoint.java new file mode 100644 index 000000000..5bbc2df85 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/ProceedingJoinPoint.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * initial implementation Alexandre Vasseur + *******************************************************************************/ +package org.aspectj.lang; + +import org.aspectj.runtime.internal.AroundClosure; + +/** + * ProceedingJoinPoint exposes the proceed(..) method in order to support around advice in @AJ aspects + * + * @author Alexandre Vasseur + */ +public interface ProceedingJoinPoint extends JoinPoint { + + /** + * The joinpoint needs to know about its closure so that proceed can delegate to closure.run() + *

+ * This internal method should not be called directly, and won't be visible to the end-user when + * packed in a jar (synthetic method) + * + * @param arc + */ + void set$AroundClosure(AroundClosure arc); + + /** + * Proceed with the next advice or target method invocation + * + * @return + * @throws Throwable + */ + public Object proceed() throws Throwable; + + /** + * Proceed with the next advice or target method invocation + *

+ *

Unlike code style, proceed(..) in annotation style places different requirements on the + * parameters passed to it. The proceed(..) call takes, in this order: + *

+ *

Since proceed(..) in this case takes an Object array, AspectJ cannot do as much + * compile time checking as it can for code style. If the rules above aren't obeyed + * then it will unfortunately manifest as a runtime error. + *

+ * + * @param args + * @return + * @throws Throwable + */ + public Object proceed(Object[] args) throws Throwable; + +} + + diff --git a/runtime/src/main/java/org/aspectj/lang/Signature.java b/runtime/src/main/java/org/aspectj/lang/Signature.java new file mode 100644 index 000000000..5bc008433 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/Signature.java @@ -0,0 +1,102 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang; + +/**

Represents the signature at a join point. This interface parallels + * java.lang.reflect.Member.

+ * + *

This interface is typically used for tracing or logging applications + * to obtain reflective information about the join point, i.e. using + * the j2se 1.4 java.util.logging API

+ *
+ * aspect Logging {
+ *     Logger logger = Logger.getLogger("MethodEntries");
+ * 
+ *     before(): within(com.bigboxco..*) && execution(public * *(..)) {
+ *         Signature sig = thisJoinPoint.getSignature();
+ *         logger.entering(sig.getDeclaringType().getName(),
+ *                         sig.getName());
+ *     }
+ * }
+ * 
+ * + * + *

More detailed information about a specific kind of signature can + * be obtained by casting this Signature object into one + * of its more specific sub-types available in + * org.aspectj.lang.reflect. + * + * @see java.lang.reflect.Member + * @see java.util.logging.Logger + */ +public interface Signature { + String toString(); + /** + * Returns an abbreviated string representation of this signature. + */ + String toShortString(); + + /** + * Returns an extended string representation of this signature. + */ + String toLongString(); + + + /** + * Returns the identifier part of this signature. For methods this + * will return the method name. + * + * @see java.lang.reflect.Member#getName + */ + String getName(); + + /** + * Returns the modifiers on this signature represented as an int. Use + * the constants and helper methods defined on + * java.lang.reflect.Modifier to manipulate this, i.e. + *

+     *     // check if this signature is public
+     *     java.lang.reflect.Modifier.isPublic(sig.getModifiers());
+     * 
+     *     // print out the modifiers
+     *     java.lang.reflect.Modifier.toString(sig.getModifiers());
+     * 
+ * + * @see java.lang.reflect.Member#getModifiers + * @see java.lang.reflect.Modifier + */ + int getModifiers(); + + /** + *

Returns a java.lang.Class object representing the class, + * interface, or aspect that declared this member. For intra-member + * declarations, this will be the type on which the member is declared, + * not the type where the declaration is lexically written. Use + * SourceLocation.getWithinType() to get the type in + * which the declaration occurs lexically.

+ *

For consistency with java.lang.reflect.Member, this + * method should have been named getDeclaringClass().

+ * + * @see java.lang.reflect.Member#getDeclaringClass + */ + Class getDeclaringType(); + + /** + * Returns the fully-qualified name of the declaring type. This is + * equivalent to calling getDeclaringType().getName(), but caches + * the result for greater efficiency. + */ + String getDeclaringTypeName(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/SoftException.java b/runtime/src/main/java/org/aspectj/lang/SoftException.java new file mode 100644 index 000000000..ea75ebac4 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/SoftException.java @@ -0,0 +1,80 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC), + * 2004 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang; + +import java.io.PrintStream; +import java.io.PrintWriter; + +/** + * Wrapper for checked exceptions matched by a 'declare soft'. + * You can soften checked exceptions at join points by using + * the form declare soft: TypePattern: Pointcut. + * At the join points, any exceptions thrown which match + * TypePattern will be wrapped in SoftException + * and rethrown. You can get the original exception using + * getWrappedThrowable() or + * getCause(). + */ +public class SoftException extends RuntimeException { + + private static final boolean HAVE_JAVA_14; + + static { + boolean java14 = false; + try { + Class.forName("java.nio.Buffer"); + java14 = true; + } catch (Throwable t) { + // still false; + } + HAVE_JAVA_14 = java14; + } + + // shouldn't field be private final, constructor default or private? + // but either would be a binary incompatible change. + + Throwable inner; + + public SoftException(Throwable inner) { + super(); + this.inner = inner; + } + + public Throwable getWrappedThrowable() { return inner; } + public Throwable getCause() { return inner; } + + public void printStackTrace() { + printStackTrace(System.err); + } + + public void printStackTrace(PrintStream stream) { + super.printStackTrace(stream); + final Throwable _inner = this.inner; + if (!HAVE_JAVA_14 && (null != _inner)) { + stream.print("Caused by: "); + _inner.printStackTrace(stream); + } + } + + public void printStackTrace(PrintWriter stream) { + super.printStackTrace(stream); + final Throwable _inner = this.inner; + if (!HAVE_JAVA_14 && (null != _inner)) { + stream.print("Caused by: "); + _inner.printStackTrace(stream); + } + } +} diff --git a/runtime/src/main/java/org/aspectj/lang/package.html b/runtime/src/main/java/org/aspectj/lang/package.html new file mode 100644 index 000000000..a5fe7ae5d --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/package.html @@ -0,0 +1,14 @@ + + +Provides several interfaces for obtaining reflective information about a +join point, as well as several exceptions that can be thrown by AspectJ +code. +

+JoinPoint and Signature provide reflective +information about a join point. Instances of these interfaces are +available inside of advice with the special variables +thisJoinPoint, thisJoinPointStaticPart, and +thisEnclosingJoinPointStaticPart.

+ + + diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/AdviceSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/AdviceSignature.java new file mode 100644 index 000000000..c01f75019 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/AdviceSignature.java @@ -0,0 +1,23 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +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(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/CatchClauseSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/CatchClauseSignature.java new file mode 100644 index 000000000..9a008994d --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/CatchClauseSignature.java @@ -0,0 +1,22 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; + +import org.aspectj.lang.Signature; + +public interface CatchClauseSignature extends Signature { + Class getParameterType(); + String getParameterName(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/CodeSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/CodeSignature.java new file mode 100644 index 000000000..1c6ba45e3 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/CodeSignature.java @@ -0,0 +1,21 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; + +public interface CodeSignature extends MemberSignature { + Class[] getParameterTypes(); + String[] getParameterNames(); + Class[] getExceptionTypes(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/ConstructorSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/ConstructorSignature.java new file mode 100644 index 000000000..268a759a2 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/ConstructorSignature.java @@ -0,0 +1,20 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; +import java.lang.reflect.Constructor; + +public interface ConstructorSignature extends CodeSignature { + Constructor getConstructor(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/FieldSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/FieldSignature.java new file mode 100644 index 000000000..df1c57656 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/FieldSignature.java @@ -0,0 +1,21 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; +import java.lang.reflect.Field; + +public interface FieldSignature extends MemberSignature { + public Class getFieldType(); + public Field getField(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/InitializerSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/InitializerSignature.java new file mode 100644 index 000000000..bbef8b6fa --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/InitializerSignature.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC), + * 2006 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; +import java.lang.reflect.Constructor; + +/** + * Signature for static and instance initializers. + * Static initializers have no parameters or exceptions, + * so empty arrays are returned from the CodeSignature methods. + */ +public interface InitializerSignature extends CodeSignature { + /** + * @return Constructor associated with this initializer, + * or null in the case of interface initializers and + * static initializers. + */ + Constructor getInitializer(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/LockSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/LockSignature.java new file mode 100644 index 000000000..5a52b3041 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/LockSignature.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ + +package org.aspectj.lang.reflect; + +import org.aspectj.lang.Signature; + +public interface LockSignature extends Signature { + +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/MemberSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/MemberSignature.java new file mode 100644 index 000000000..cbc448e1b --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/MemberSignature.java @@ -0,0 +1,22 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; + +import org.aspectj.lang.Signature; + +public interface MemberSignature extends Signature { + // AccessibleObject is a 1.2 API, we run on 1.1... (thanks Wes for catching this) + //AccessibleObject getAccessibleObject(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/MethodSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/MethodSignature.java new file mode 100644 index 000000000..d660e1eb1 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/MethodSignature.java @@ -0,0 +1,21 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +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(); +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/SourceLocation.java b/runtime/src/main/java/org/aspectj/lang/reflect/SourceLocation.java new file mode 100644 index 000000000..52f1dd7a6 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/SourceLocation.java @@ -0,0 +1,30 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.lang.reflect; + +/** For defining code, the class defined and location in a source file. */ +public interface SourceLocation { + Class getWithinType(); + + String getFileName(); + int getLine(); + + /** + * @deprecated can not be implemented for bytecode weaving, may + * be removed in 1.1gold. + */ + int getColumn(); +} + diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/UnlockSignature.java b/runtime/src/main/java/org/aspectj/lang/reflect/UnlockSignature.java new file mode 100644 index 000000000..3e117ce18 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/UnlockSignature.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ + + +package org.aspectj.lang.reflect; + +import org.aspectj.lang.Signature; + +public interface UnlockSignature extends Signature { + +} diff --git a/runtime/src/main/java/org/aspectj/lang/reflect/package.html b/runtime/src/main/java/org/aspectj/lang/reflect/package.html new file mode 100644 index 000000000..fc51a5b60 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/lang/reflect/package.html @@ -0,0 +1,18 @@ + + +

Contains interfaces that extend Signature to provide +additional information about each possible join point signature. This +additional information can be accessed by casting a Signature object +to the appropriate type, i.e.

+
+  before(): call(* *(..)) {
+      MethodSignature sig = (MethodSignature)thisJoinPoint.getSignature();
+      ...
+  }
+
+ +

This package also contains SourceLocation that provides +information about the location in source code that corresponds to a +particular join point.

+ + diff --git a/runtime/src/main/java/org/aspectj/runtime/CFlow.java b/runtime/src/main/java/org/aspectj/runtime/CFlow.java new file mode 100644 index 000000000..d607b4822 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/CFlow.java @@ -0,0 +1,39 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime; + +public class CFlow { + private Object _aspect; + + public CFlow() { + this(null); + } + + public CFlow(Object _aspect) { + this._aspect = _aspect; + } + + public Object getAspect() { + return this._aspect; + } + + public void setAspect(Object _aspect) { + this._aspect = _aspect; + } + + public Object get(int index) { + return null; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/AroundClosure.java b/runtime/src/main/java/org/aspectj/runtime/internal/AroundClosure.java new file mode 100644 index 000000000..91f7f923c --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/AroundClosure.java @@ -0,0 +1,76 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Alex Vasseur wired up for @AJ proceeding + * Andy Clement 23-06-06 added extras for @AJ + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +import org.aspectj.lang.ProceedingJoinPoint; + +public abstract class AroundClosure { + protected Object[] state; + + // Records with the related joinpoint has a this or a target and whether + // either of them are bound in the pointcut. Set in the 'link' call made + // at each matching join point... (see pr126167) + // bit6 being 1 means the flags haven't been initialized + protected int bitflags = 0x100000; + protected Object[] preInitializationState; + + public AroundClosure() { + } + + public AroundClosure(Object[] state) { + this.state = state; + } + + public int getFlags() {return bitflags;} + + public Object[] getState() { + return state; + } + + public Object[] getPreInitializationState() { + return preInitializationState; + } + + /** + * This takes in the same arguments as are passed to the proceed + * call in the around advice (with primitives coerced to Object types) + */ + public abstract Object run(Object[] args) throws Throwable; + + /** + * This method is called to implicitly associate the closure with the joinpoint + * as required for @AJ aspect proceed() + */ + public ProceedingJoinPoint linkClosureAndJoinPoint() { + //TODO is this cast safe ? + ProceedingJoinPoint jp = (ProceedingJoinPoint)state[state.length-1]; + jp.set$AroundClosure(this); + return jp; + } + + /** + * This method is called to implicitly associate the closure with the joinpoint + * as required for @AJ aspect proceed() + */ + public ProceedingJoinPoint linkClosureAndJoinPoint(int flags) { + //TODO is this cast safe ? + ProceedingJoinPoint jp = (ProceedingJoinPoint)state[state.length-1]; + jp.set$AroundClosure(this); + this.bitflags = flags; + return jp; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/CFlowCounter.java b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowCounter.java new file mode 100644 index 000000000..633458195 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowCounter.java @@ -0,0 +1,88 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +import org.aspectj.runtime.internal.cflowstack.ThreadCounter; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; + + +public class CFlowCounter { + + private static ThreadStackFactory tsFactory; + private ThreadCounter flowHeightHandler; + + static { + selectFactoryForVMVersion(); + } + + public CFlowCounter() { + flowHeightHandler = tsFactory.getNewThreadCounter(); + } + + public void inc() { + flowHeightHandler.inc(); + } + + public void dec() { + flowHeightHandler.dec(); + if (!flowHeightHandler.isNotZero()) { + flowHeightHandler.removeThreadCounter(); + } + } + + public boolean isValid() { + return flowHeightHandler.isNotZero(); + } + + + private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } + private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } + + private static void selectFactoryForVMVersion() { + String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); + boolean useThreadLocalImplementation = false; + if (override.equals("unspecified")) { + String v = System.getProperty("java.class.version","0.0"); + // Java 1.2 is version 46.0 and above + useThreadLocalImplementation = (v.compareTo("46.0") >= 0); + } else { + useThreadLocalImplementation = override.equals("yes") || override.equals("true"); + } + // System.err.println("Trying to use thread local implementation? "+useThreadLocalImplementation); + if (useThreadLocalImplementation) { + tsFactory = getThreadLocalStackFactory(); + } else { + tsFactory = getThreadLocalStackFactoryFor11(); + } + } + + + private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { + try { + return System.getProperty(aPropertyName, aDefaultValue); + } + catch (SecurityException ex) { + return aDefaultValue; + } + } + + // For debug ... + public static String getThreadStackFactoryClassName() { + return tsFactory.getClass().getName(); + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/CFlowPlusState.java b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowPlusState.java new file mode 100644 index 000000000..b78864a33 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowPlusState.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +public class CFlowPlusState extends org.aspectj.runtime.CFlow { + private Object[] state; + + public CFlowPlusState(Object[] state) { + this.state = state; + } + + public CFlowPlusState(Object[] state, Object _aspect) { + super(_aspect); + this.state = state; + } + + public Object get(int index) { + return state[index]; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/CFlowStack.java b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowStack.java new file mode 100644 index 000000000..48308f145 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/CFlowStack.java @@ -0,0 +1,160 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +import java.util.Stack; + +import org.aspectj.lang.NoAspectBoundException; +import org.aspectj.runtime.CFlow; +import org.aspectj.runtime.internal.cflowstack.ThreadStack; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; +import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; + +/* + * How we benefit from ThreadLocal when it is available at runtime: + * + * When the CFlowStack class is loaded, we run its static initializer. This checks the JVM + * version number and loads an appropriate implementation of the ThreadStackFactory. + * There are two possible implementations depending on whether this is a 1.1 or 1.2+ JVM. + * Rather than doing a Class.forName for ThreadLocal and catching a ClassNotFoundEx in order + * to determine the JVM version, we look at the java class version which I believe can help + * us identify the Java level. + * + * In the 1.1 JVM case we use a factory implementation that does not use ThreadLocal storage. + * In the 1.2+ JVM case we use a factory implementation that does use ThreadLocal storage. + * + * Once we have the factory set, whenever someone builds a CFlowStack object, we ask the + * factory for a new stack proxy - this is an object that can return us the right stack + * that we should use on a particular thread. The reason we create the proxy in the ctor and + * not lazily in the getThreadStack() method is because it means the getThreadStack() method in + * this class does not have to be synchronized. + * + * When any of the methods in CFlowStack need to operate on the stack (peek/pop/etc), they + * all delegate to getThreadStack() which asks the proxy for the right stack. Depending on the + * factory loaded to build the proxy, the call to proxy.getThreadStack() will return a threadlocal + * based stack or it will call the original implementation of getThreadStack() which manages + * a Hashtable of threads->stacks. + * + */ + +public class CFlowStack { + + private static ThreadStackFactory tsFactory; + private ThreadStack stackProxy; + + static { + selectFactoryForVMVersion(); + } + + public CFlowStack() { + stackProxy = tsFactory.getNewThreadStack(); + } + + private Stack getThreadStack() { + return stackProxy.getThreadStack(); + } + + //XXX dangerous, try to remove + public void push(Object obj) { + getThreadStack().push(obj); + } + + public void pushInstance(Object obj) { + getThreadStack().push(new CFlow(obj)); + } + + public void push(Object[] obj) { + getThreadStack().push(new CFlowPlusState(obj)); + } + + public void pop() { + Stack s = getThreadStack(); + s.pop(); + if (s.isEmpty()) { + stackProxy.removeThreadStack(); + } + } + + public Object peek() { + Stack stack = getThreadStack(); + if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException(); + return (Object)stack.peek(); + } + + public Object get(int index) { + CFlow cf = peekCFlow(); + return (null == cf ? null : cf.get(index)); + } + + public Object peekInstance() { + CFlow cf = peekCFlow(); + if (cf != null ) return cf.getAspect(); + else throw new NoAspectBoundException(); + } + + public CFlow peekCFlow() { + Stack stack = getThreadStack(); + if (stack.isEmpty()) return null; + return (CFlow)stack.peek(); + } + + public CFlow peekTopCFlow() { + Stack stack = getThreadStack(); + if (stack.isEmpty()) return null; + return (CFlow)stack.elementAt(0); + } + + public boolean isValid() { + return !getThreadStack().isEmpty(); + } + + private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } + private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } + + private static void selectFactoryForVMVersion() { + String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); + boolean useThreadLocalImplementation = false; + if (override.equals("unspecified")) { + String v = System.getProperty("java.class.version","0.0"); + // Java 1.2 is version 46.0 and above + useThreadLocalImplementation = (v.compareTo("46.0") >= 0); + } else { + useThreadLocalImplementation = override.equals("yes") || override.equals("true"); + } + // System.err.println("Trying to use thread local implementation? "+useThreadLocalImplementation); + if (useThreadLocalImplementation) { + tsFactory = getThreadLocalStackFactory(); + } else { + tsFactory = getThreadLocalStackFactoryFor11(); + } + } + + private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { + try { + return System.getProperty(aPropertyName, aDefaultValue); + } + catch (SecurityException ex) { + return aDefaultValue; + } + } + + + // For debug ... + public static String getThreadStackFactoryClassName() { + return tsFactory.getClass().getName(); + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/Conversions.java b/runtime/src/main/java/org/aspectj/runtime/internal/Conversions.java new file mode 100644 index 000000000..f74e8d919 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/Conversions.java @@ -0,0 +1,145 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +public final class Conversions { + // Can't make instances of me + private Conversions() {} + + // we might want to keep a cache of small integers around + public static Object intObject(int i) { + return new Integer(i); + } + public static Object shortObject(short i) { + return new Short(i); + } + public static Object byteObject(byte i) { + return new Byte(i); + } + public static Object charObject(char i) { + return new Character(i); + } + public static Object longObject(long i) { + return new Long(i); + } + public static Object floatObject(float i) { + return new Float(i); + } + public static Object doubleObject(double i) { + return new Double(i); + } + public static Object booleanObject(boolean i) { + return new Boolean(i); + } + public static Object voidObject() { + return null; + } + + + public static int intValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).intValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to int"); + } + } + public static long longValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).longValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to long"); + } + } + public static float floatValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).floatValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to float"); + } + } + public static double doubleValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).doubleValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to double"); + } + } + public static byte byteValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).byteValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to byte"); + } + } + public static short shortValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Number) { + return ((Number)o).shortValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to short"); + } + } + public static char charValue(Object o) { + if (o == null) { + return 0; + } else if (o instanceof Character) { + return ((Character)o).charValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to char"); + } + } + public static boolean booleanValue(Object o) { + if (o == null) { + return false; + } else if (o instanceof Boolean) { + return ((Boolean)o).booleanValue(); + } else { + throw new ClassCastException(o.getClass().getName() + + " can not be converted to boolean"); + } + } + + /** + * identity function for now. This is not typed to "void" because we happen + * to know that in Java, any void context (i.e., {@link ExprStmt}) + * can also handle a return value. + */ + public static Object voidValue(Object o) { + if (o == null) { + return o; + } else { + // !!! this may be an error in the future + return o; + } + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/PerObjectMap.java b/runtime/src/main/java/org/aspectj/runtime/internal/PerObjectMap.java new file mode 100644 index 000000000..319740572 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/PerObjectMap.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.internal; + +//import java.util.WeakHashMap; // XXX REQUIRES JAVA 2!!!!!!!!!!!!!!!! + +public class PerObjectMap { +// private WeakHashMap map = new WeakHashMap(); +// +// public boolean hasAspect(Object o) { return map.containsKey(o); } +// +// public Object aspectOf(Object o) { +// return map.get(o); +// } +// +// public void bind(Object object, Object _aspect) { +// map.put(object, _aspect); +// } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java new file mode 100644 index 000000000..1fa064cee --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java @@ -0,0 +1,22 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ + +package org.aspectj.runtime.internal.cflowstack; + + +public interface ThreadCounter { + public void inc(); + public void dec(); + public boolean isNotZero(); + public void removeThreadCounter(); +} \ No newline at end of file diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java new file mode 100644 index 000000000..71aaacd62 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java @@ -0,0 +1,78 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * Copied from bits of original CFlowStack + * ******************************************************************/ +package org.aspectj.runtime.internal.cflowstack; + +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; + +public class ThreadCounterImpl11 implements ThreadCounter { + private Hashtable counters = new Hashtable(); + private Thread cached_thread; + private Counter cached_counter; + + private int change_count = 0; + private static final int COLLECT_AT = 20000; + private static final int MIN_COLLECT_AT = 100; + + static class Counter { + protected int value = 0; + } + + private synchronized Counter getThreadCounter() { + if (Thread.currentThread() != cached_thread) { + cached_thread = Thread.currentThread(); + cached_counter = (Counter)counters.get(cached_thread); + if (cached_counter == null) { + cached_counter = new Counter(); + counters.put(cached_thread, cached_counter); + } + change_count++; + // 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... + if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { + List dead_stacks = new ArrayList(); + for (Enumeration e = counters.keys(); e.hasMoreElements(); ) { + Thread t = (Thread)e.nextElement(); + if (!t.isAlive()) dead_stacks.add(t); + } + for (Iterator e = dead_stacks.iterator(); e.hasNext(); ) { + Thread t = (Thread)e.next(); + counters.remove(t); + } + change_count = 0; + } + } + return cached_counter; + } + + public void inc() { + getThreadCounter().value++; + } + + public void dec() { + getThreadCounter().value--; + } + + public boolean isNotZero() { + return getThreadCounter().value!=0; + } + + public void removeThreadCounter() { + // TODO + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStack.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStack.java new file mode 100644 index 000000000..7290163d2 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStack.java @@ -0,0 +1,23 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ + +package org.aspectj.runtime.internal.cflowstack; + +import java.util.Stack; + +public interface ThreadStack { + + public Stack getThreadStack(); + public void removeThreadStack(); + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java new file mode 100644 index 000000000..38ba0ccbd --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java @@ -0,0 +1,20 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.runtime.internal.cflowstack; + +public interface ThreadStackFactory { + + public ThreadStack getNewThreadStack(); + public ThreadCounter getNewThreadCounter(); + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java new file mode 100644 index 000000000..2437f06b0 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java @@ -0,0 +1,61 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.runtime.internal.cflowstack; + +import java.util.Stack; + +public class ThreadStackFactoryImpl implements ThreadStackFactory { + + private static class ThreadStackImpl extends ThreadLocal implements ThreadStack { + public Object initialValue() { + return new Stack(); + } + public Stack getThreadStack() { + return (Stack)get(); + } + public void removeThreadStack() { + this.remove(); + } + } + + public ThreadStack getNewThreadStack() { + return new ThreadStackImpl(); + } + + private static class ThreadCounterImpl extends ThreadLocal implements ThreadCounter { + + public Object initialValue() { + return new Counter(); + } + public Counter getThreadCounter() { + return (Counter)get(); + } + + public void removeThreadCounter() { + this.remove(); + } + + public void inc() { getThreadCounter().value++; } + public void dec() { getThreadCounter().value--; } + public boolean isNotZero() { return getThreadCounter().value!= 0; } + + static class Counter { + protected int value = 0; + } + } + + public ThreadCounter getNewThreadCounter() { + return new ThreadCounterImpl(); + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java new file mode 100644 index 000000000..21c246193 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java @@ -0,0 +1,26 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.runtime.internal.cflowstack; + + +public class ThreadStackFactoryImpl11 implements ThreadStackFactory { + + public ThreadStack getNewThreadStack() { + return new ThreadStackImpl11(); + } + + public ThreadCounter getNewThreadCounter() { + return new ThreadCounterImpl11(); + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java new file mode 100644 index 000000000..51f09cadd --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java @@ -0,0 +1,59 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * Copied from bits of original CFlowStack + * ******************************************************************/ +package org.aspectj.runtime.internal.cflowstack; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Stack; + +public class ThreadStackImpl11 implements ThreadStack { + private Hashtable stacks = new Hashtable(); + private Thread cached_thread; + private Stack cached_stack; + private int change_count = 0; + private static final int COLLECT_AT = 20000; + private static final int MIN_COLLECT_AT = 100; + + public synchronized Stack getThreadStack() { + if (Thread.currentThread() != cached_thread) { + cached_thread = Thread.currentThread(); + cached_stack = (Stack)stacks.get(cached_thread); + if (cached_stack == null) { + cached_stack = new Stack(); + stacks.put(cached_thread, cached_stack); + } + change_count++; + // 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... + if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { + Stack dead_stacks = new Stack(); + for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) { + Thread t = (Thread)e.nextElement(); + if (!t.isAlive()) dead_stacks.push(t); + } + for (Enumeration e = dead_stacks.elements(); e.hasMoreElements(); ) { + Thread t = (Thread)e.nextElement(); + stacks.remove(t); + } + change_count = 0; + } + } + return cached_stack; + } + + public void removeThreadStack() { + // TODO + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/AdviceSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/AdviceSignatureImpl.java new file mode 100644 index 000000000..0022c03ba --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/AdviceSignatureImpl.java @@ -0,0 +1,84 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Method; +import java.util.StringTokenizer; + +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, + Class returnType) + { + super(modifiers, name, declaringType, parameterTypes, parameterNames, + exceptionTypes); + this.returnType = returnType; + } + + AdviceSignatureImpl(String stringRep) { + super(stringRep); + } + /* name is consistent with reflection API + before and after always return Void.TYPE + (some around also return Void.Type) */ + public Class getReturnType() { + if (returnType == null) returnType = extractType(6); + return returnType; + } + + protected String createToString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); +// buf.append(sm.makeModifiersString(getModifiers())); + if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType())); + if (sm.includeArgs) buf.append(" "); + buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); + buf.append("."); + buf.append(toAdviceName(getName())); + sm.addSignature(buf, getParameterTypes()); + sm.addThrows(buf, getExceptionTypes()); + return buf.toString(); + } + + private String toAdviceName(String methodName) { + if (methodName.indexOf('$') == -1) return methodName; + StringTokenizer strTok = new StringTokenizer(methodName,"$"); + while (strTok.hasMoreTokens()) { + String token = strTok.nextToken(); + if ( token.startsWith("before") || + token.startsWith("after") || + token.startsWith("around") ) return token; + } + return methodName; + } + + /* (non-Javadoc) + * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() + */ + public Method getAdvice() { + if (adviceMethod == null) { + try { + adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes()); + } catch (Exception ex) { + ; // nothing we can do, caller will see null + } + } + return adviceMethod; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java new file mode 100644 index 000000000..6f049a66b --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java @@ -0,0 +1,47 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.reflect.CatchClauseSignature; + +class CatchClauseSignatureImpl extends SignatureImpl implements CatchClauseSignature { + Class parameterType; + String parameterName; + + CatchClauseSignatureImpl(Class declaringType, + Class parameterType, String parameterName) + { + super(0, "catch", declaringType); + this.parameterType = parameterType; + this.parameterName = parameterName; + } + + CatchClauseSignatureImpl(String stringRep) { + super(stringRep); + } + + public Class getParameterType() { + if (parameterType == null) parameterType = extractType(3); + return parameterType; + } + public String getParameterName() { + if (parameterName == null) parameterName = extractString(4); + return parameterName; + } + + protected String createToString(StringMaker sm) { + return "catch(" + sm.makeTypeName(getParameterType()) + ")"; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/CodeSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/CodeSignatureImpl.java new file mode 100644 index 000000000..74fc462d6 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/CodeSignatureImpl.java @@ -0,0 +1,48 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.reflect.CodeSignature; + +abstract class CodeSignatureImpl extends MemberSignatureImpl implements CodeSignature { + Class[] parameterTypes; + String[] parameterNames; + Class[] exceptionTypes; + + CodeSignatureImpl(int modifiers, String name, Class declaringType, + Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) + { + super(modifiers, name, declaringType); + this.parameterTypes = parameterTypes; + this.parameterNames = parameterNames; + this.exceptionTypes = exceptionTypes; + } + CodeSignatureImpl(String stringRep) { + super(stringRep); + } + + public Class[] getParameterTypes() { + if (parameterTypes == null) parameterTypes = extractTypes(3); + return parameterTypes; + } + public String[] getParameterNames() { + if (parameterNames == null) parameterNames = extractStrings(4); + return parameterNames; + } + public Class[] getExceptionTypes() { + if (exceptionTypes == null) exceptionTypes = extractTypes(5); + return exceptionTypes; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java new file mode 100644 index 000000000..a7f688d58 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java @@ -0,0 +1,58 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +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) + { + super(modifiers, "", declaringType, parameterTypes, parameterNames, exceptionTypes); + } + + ConstructorSignatureImpl(String stringRep) { + super(stringRep); + } + + public String getName() { return ""; } + + protected String createToString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); + buf.append(sm.makeModifiersString(getModifiers())); + buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); + sm.addSignature(buf, getParameterTypes()); + sm.addThrows(buf, getExceptionTypes()); + return buf.toString(); + } + + /* (non-Javadoc) + * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() + */ + public Constructor getConstructor() { + if (constructor == null) { + try { + constructor = getDeclaringType().getDeclaredConstructor(getParameterTypes()); + } catch (Exception ex) { + ; // nothing we can do, caller will see null + } + } + return constructor; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/Factory.java b/runtime/src/main/java/org/aspectj/runtime/reflect/Factory.java new file mode 100644 index 000000000..759a1367b --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/Factory.java @@ -0,0 +1,533 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002-2018 Palo Alto Research Center, Incorporated (PARC), Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Alex Vasseur new factory methods for variants of JP + * Abraham Nevado new factory methods for collapsed SJPs + * Andy Clement new factory methods that rely on LDC + * ******************************************************************/ + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.Hashtable; +import java.util.StringTokenizer; + +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; + + private static final Class[] NO_TYPES = new Class[0]; + private static final String[] NO_STRINGS = new String[0]; + + 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(); + } + + + /** + * Create a signature and build a JoinPoint in one step. Prior to 1.6.10 this was done as a two step operation in the generated + * code but merging these methods in the runtime library enables the generated code to be shorter. Generating code that + * uses this method requires the weaver to be invoked with -Xset:targetRuntime1_6_10=true. + * + * @since 1.6.10 + */ + public JoinPoint.StaticPart makeSJP(String kind, String modifiers, String methodName, String declaringType, String paramTypes, + String paramNames, String exceptionTypes, String returnType, int l) { + Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, exceptionTypes, returnType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); + } + + /** + * Create a signature and build a JoinPoint in one step. Prior to 1.6.10 this was done as a two step operation in the generated + * code but merging these methods in the runtime library enables the generated code to be shorter. Generating code that + * uses this method requires the weaver to be invoked with -Xset:targetRuntime1_6_10=true. + *

+ * This method differs from the previous one in that it includes no exceptionTypes parameter - it is an optimization for the + * case where there are no exceptions. The generated code won't build an empty string and will not pass it into here. + * + * @since 1.6.10 + */ + public JoinPoint.StaticPart makeSJP(String kind, String modifiers, String methodName, String declaringType, String paramTypes, + String paramNames, String returnType, int l) { + Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, "", returnType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); + } + + // These are direct routes to creating thisJoinPoint and thisEnclosingJoinPoint objects + // added in 1.9.1 + + public JoinPoint.StaticPart makeMethodSJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { + Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, + paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeMethodESJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { + Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, + paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeConstructorSJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { + ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, + exceptionTypes==null?NO_TYPES:exceptionTypes); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeConstructorESJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { + ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, + exceptionTypes==null?NO_TYPES:exceptionTypes); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeCatchClauseSJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { + CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeCatchClauseESJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { + CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeFieldSJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { + FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeFieldESJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { + FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeInitializerSJP(String kind, int modifiers, Class declaringType, int line) { + InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeInitializerESJP(String kind, int modifiers, Class declaringType, int line) { + InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeLockSJP(String kind, Class declaringType, int line) { + LockSignatureImpl sig = new LockSignatureImpl(declaringType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeLockESJP(String kind, Class declaringType, int line) { + LockSignatureImpl sig = new LockSignatureImpl(declaringType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeUnlockSJP(String kind, Class declaringType, int line) { + UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeUnlockESJP(String kind, Class declaringType, int line) { + UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.StaticPart makeAdviceSJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, + String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { + AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, + parameterTypes==null?NO_TYPES:parameterTypes, + parameterNames==null?NO_STRINGS:parameterNames, + exceptionTypes==null?NO_TYPES:exceptionTypes, + returnType==null?Void.TYPE:returnType); + return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + public JoinPoint.EnclosingStaticPart makeAdviceESJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, + String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { + AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, + parameterTypes==null?NO_TYPES:parameterTypes, + parameterNames==null?NO_STRINGS:parameterNames, + exceptionTypes==null?NO_TYPES:exceptionTypes, + returnType==null?Void.TYPE:returnType); + return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); + } + + // --- + + 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) { + 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) { + Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); + return makeMethodSig(modifiers, methodName, declaringTypeClass, paramTypes, paramNames, exceptionTypes, returnType); + } + + public MethodSignature makeMethodSig(String modifiers, String methodName, Class declaringTypeClass, String paramTypes, + String paramNames, String exceptionTypes, String returnType) { + int modifiersAsInt = Integer.parseInt(modifiers, 16); + + 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==null?NO_TYPES:parameterTypes, parameterNames, + exceptionTypes == null?NO_TYPES: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); + + 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); + + 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/main/java/org/aspectj/runtime/reflect/FieldSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/FieldSignatureImpl.java new file mode 100644 index 000000000..8c3de24c4 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/FieldSignatureImpl.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +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) + { + super(modifiers, name, declaringType); + this.fieldType = fieldType; + } + + FieldSignatureImpl(String stringRep) { + super(stringRep); + } + + public Class getFieldType() { + if (fieldType == null) fieldType = extractType(3); + return fieldType; + } + + protected String createToString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); + buf.append(sm.makeModifiersString(getModifiers())); + if (sm.includeArgs) buf.append(sm.makeTypeName(getFieldType())); + if (sm.includeArgs) buf.append(" "); + buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); + buf.append("."); + buf.append(getName()); + return buf.toString(); + } + + /* (non-Javadoc) + * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() + */ + public Field getField() { + if (field == null) { + try { + field = getDeclaringType().getDeclaredField(getName()); + } catch (Exception ex) { + ; // nothing we can do, caller will see null + } + } + return field; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/InitializerSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/InitializerSignatureImpl.java new file mode 100644 index 000000000..adb8f840e --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/InitializerSignatureImpl.java @@ -0,0 +1,60 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.reflect.InitializerSignature; + +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) ? "" : "", declaringType, EMPTY_CLASS_ARRAY, + EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY); + } + + InitializerSignatureImpl(String stringRep) { + super(stringRep); + } + + public String getName() { + return Modifier.isStatic(getModifiers()) ? "": ""; + } + + protected String createToString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); + buf.append(sm.makeModifiersString(getModifiers())); + buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); + buf.append("."); + buf.append(getName()); + return buf.toString(); + } + + /* (non-Javadoc) + * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() + */ + public Constructor getInitializer() { + if (constructor == null) { + try { + constructor = getDeclaringType().getDeclaredConstructor(getParameterTypes()); + } catch (Exception ex) { + ; // nothing we can do, caller will see null + } + } + return constructor; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java new file mode 100644 index 000000000..69bff1e3c --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/JoinPointImpl.java @@ -0,0 +1,233 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +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; + 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 + + // This previous variant doesn't seem to cope with only binding target at a joinpoint + // which has both this and target. It forces you to supply this even if you didn't bind + // it. +// firstArgumentIndexIntoAdviceBindings = (hasThis ? 1 : 0) + 1; +// state[hasThis ? 1 : 0] = adviceBindings[hasThis ? 1 : 0]; + + int targetPositionInAdviceBindings = (hasThis && bindsThis) ? 1 : 0; + firstArgumentIndexIntoAdviceBindings = ((hasThis&&bindsThis)?1:0)+((hasTarget&&bindsTarget&&!thisTargetTheSame)?1:0); + state[hasThis ? 1 : 0] = adviceBindings[targetPositionInAdviceBindings]; + } + } 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); + } + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/LockSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/LockSignatureImpl.java new file mode 100644 index 000000000..2448868d0 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/LockSignatureImpl.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ + + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Modifier; + +import org.aspectj.lang.reflect.LockSignature; + +class LockSignatureImpl extends SignatureImpl implements LockSignature { + private Class parameterType; + + LockSignatureImpl(Class c) { + super(Modifier.STATIC, "lock", c); + parameterType = c; + } + + LockSignatureImpl(String stringRep) { + super(stringRep); + } + + protected String createToString(StringMaker sm) { + if (parameterType == null) parameterType = extractType(3); + return "lock("+sm.makeTypeName(parameterType)+")"; + } + + public Class getParameterType() { + if (parameterType == null) parameterType = extractType(3); + return parameterType; + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/MemberSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/MemberSignatureImpl.java new file mode 100644 index 000000000..a7cd77a5f --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/MemberSignatureImpl.java @@ -0,0 +1,29 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.reflect.MemberSignature; + +abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature { + + MemberSignatureImpl(int modifiers, String name, Class declaringType) { + super(modifiers, name, declaringType); + } + + public MemberSignatureImpl(String stringRep) { + super(stringRep); + } + +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java new file mode 100644 index 000000000..17416bada --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java @@ -0,0 +1,114 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; + +import org.aspectj.lang.reflect.MethodSignature; + +class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature { + private Method method; + Class returnType; + + MethodSignatureImpl(int modifiers, String name, Class declaringType, Class[] parameterTypes, String[] parameterNames, + Class[] exceptionTypes, Class returnType) { + super(modifiers, name, declaringType, parameterTypes, parameterNames, exceptionTypes); + this.returnType = returnType; + } + + MethodSignatureImpl(String stringRep) { + super(stringRep); + } + + /* name is consistent with reflection API */ + public Class getReturnType() { + if (returnType == null) + returnType = extractType(6); + return returnType; + } + + protected String createToString(StringMaker sm) { + StringBuffer buf = new StringBuffer(); + buf.append(sm.makeModifiersString(getModifiers())); + if (sm.includeArgs) + buf.append(sm.makeTypeName(getReturnType())); + if (sm.includeArgs) + buf.append(" "); + buf.append(sm.makePrimaryTypeName(getDeclaringType(), getDeclaringTypeName())); + buf.append("."); + buf.append(getName()); + sm.addSignature(buf, getParameterTypes()); + sm.addThrows(buf, getExceptionTypes()); + return buf.toString(); + } + + /* + * (non-Javadoc) + * + * @see org.aspectj.lang.reflect.MemberSignature#getAccessibleObject() + */ + public Method getMethod() { + if (method == null) { + Class dtype = getDeclaringType(); + try { + method = dtype.getDeclaredMethod(getName(), getParameterTypes()); + } catch (NoSuchMethodException nsmEx) { + // pr154427 - search + Set searched = new HashSet(); + searched.add(dtype); // avoids another getDeclaredMethod() on dtype + method = search(dtype, getName(), getParameterTypes(), searched); + } + } + return method; + } + + /** + * Hunt for a method up the hierarchy for a specified type. + * + * @param type the type on which to look for the method + * @param name the name of the method + * @param params the parameters of the method + * @param searched a set of types already searched to avoid looking at anything twice + * @return the method if found, or null if not found + */ + private Method search(Class type, String name, Class[] params, Set searched) { + if (type == null) { + return null; + } + if (!searched.contains(type)) { + searched.add(type); + try { + return type.getDeclaredMethod(name, params); + } catch (NoSuchMethodException nsme) { + // drop through and check superclass and interfaces + } + } + Method m = search(type.getSuperclass(), name, params, searched); + if (m != null) { + return m; + } + Class[] superinterfaces = type.getInterfaces(); + if (superinterfaces != null) { + for (int i = 0; i < superinterfaces.length; i++) { + m = search(superinterfaces[i], name, params, searched); + if (m != null) { + return m; + } + } + } + return null; + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/SignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/SignatureImpl.java new file mode 100644 index 000000000..68079b444 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/SignatureImpl.java @@ -0,0 +1,243 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.Signature; + +import java.util.StringTokenizer; + +abstract class SignatureImpl implements Signature { + + private static boolean useCache = true; + + int modifiers = -1; + String name; + String declaringTypeName; + Class declaringType; + Cache stringCache; + + SignatureImpl(int modifiers, String name, Class declaringType) { + this.modifiers = modifiers; + this.name = name; + this.declaringType = declaringType; + } + + protected abstract String createToString (StringMaker sm); + + /* Use a soft cache for the short, middle and long String representations */ + String toString (StringMaker sm) { + String result = null; + if (useCache) { + if (stringCache == null) { + try { + stringCache = new CacheImpl(); + } catch (Throwable t) { + useCache = false; + } + } else { + result = stringCache.get(sm.cacheOffset); + } + } + if (result == null) { + result = createToString(sm); + } + if (useCache) { + stringCache.set(sm.cacheOffset, result); + } + return result; + } + + public final String toString() { return toString(StringMaker.middleStringMaker); } + public final String toShortString() { return toString(StringMaker.shortStringMaker); } + public final String toLongString() { return toString(StringMaker.longStringMaker); } + + public int getModifiers() { + if (modifiers == -1) modifiers = extractInt(0); + return modifiers; + } + public String getName() { + if (name == null) name = extractString(1); + return name; + } + public Class getDeclaringType() { + if (declaringType == null) declaringType = extractType(2); + return declaringType; + } + public String getDeclaringTypeName() { + if (declaringTypeName == null) { + declaringTypeName = getDeclaringType().getName(); + } + return declaringTypeName; + } + + String fullTypeName(Class type) { + if (type == null) return "ANONYMOUS"; + if (type.isArray()) return fullTypeName(type.getComponentType()) + "[]"; + return type.getName().replace('$', '.'); + } + + String stripPackageName(String name) { + int dot = name.lastIndexOf('.'); + if (dot == -1) return name; + return name.substring(dot+1); + } + + String shortTypeName(Class type) { + if (type == null) return "ANONYMOUS"; + if (type.isArray()) return shortTypeName(type.getComponentType()) + "[]"; + return stripPackageName(type.getName()).replace('$', '.'); + } + + void addFullTypeNames(StringBuffer buf, Class[] types) { + for (int i = 0; i < types.length; i++) { + if (i > 0) buf.append(", "); + buf.append(fullTypeName(types[i])); + } + } + void addShortTypeNames(StringBuffer buf, Class[] types) { + for (int i = 0; i < types.length; i++) { + if (i > 0) buf.append(", "); + buf.append(shortTypeName(types[i])); + } + } + + void addTypeArray(StringBuffer buf, Class[] types) { + addFullTypeNames(buf, types); + } + + // lazy version + private String stringRep; + ClassLoader lookupClassLoader = null; + + public void setLookupClassLoader(ClassLoader loader) { + this.lookupClassLoader = loader; + } + + private ClassLoader getLookupClassLoader() { + if (lookupClassLoader == null) lookupClassLoader = this.getClass().getClassLoader(); + return lookupClassLoader; + } + + public SignatureImpl(String stringRep) { + this.stringRep = stringRep; + } + + static final char SEP = '-'; + + String extractString(int n) { + //System.out.println(n + ": from " + stringRep); + + int startIndex = 0; + int endIndex = stringRep.indexOf(SEP); + while (n-- > 0) { + startIndex = endIndex+1; + endIndex = stringRep.indexOf(SEP, startIndex); + } + if (endIndex == -1) endIndex = stringRep.length(); + + //System.out.println(" " + stringRep.substring(startIndex, endIndex)); + + return stringRep.substring(startIndex, endIndex); + } + + int extractInt(int n) { + String s = extractString(n); + return Integer.parseInt(s, 16); + } + + Class extractType(int n) { + String s = extractString(n); + return Factory.makeClass(s,getLookupClassLoader()); + } + + + + static String[] EMPTY_STRING_ARRAY = new String[0]; + static Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + static final String INNER_SEP = ":"; + + String[] extractStrings(int n) { + String s = extractString(n); + StringTokenizer st = new StringTokenizer(s, INNER_SEP); + final int N = st.countTokens(); + String[] ret = new String[N]; + for (int i = 0; i < N; i++) ret[i]= st.nextToken(); + return ret; + } + Class[] extractTypes(int n) { + String s = extractString(n); + StringTokenizer st = new StringTokenizer(s, INNER_SEP); + final int N = st.countTokens(); + Class[] ret = new Class[N]; + for (int i = 0; i < N; i++) ret[i]= Factory.makeClass(st.nextToken(),getLookupClassLoader()); + return ret; + } + + /* + * Used for testing + */ + static void setUseCache (boolean b) { + useCache = b; + } + + static boolean getUseCache () { + return useCache; + } + + private static interface Cache { + + String get(int cacheOffset); + + void set(int cacheOffset, String result); + + } + + // separate implementation so we don't need SoftReference to hold the field... + private static final class CacheImpl implements Cache { + private java.lang.ref.SoftReference toStringCacheRef; + + public CacheImpl() { + makeCache(); + } + + public String get(int cacheOffset) { + String[] cachedArray = array(); + if (cachedArray == null) { + return null; + } + return cachedArray[cacheOffset]; + } + + public void set(int cacheOffset, String result) { + String[] cachedArray = array(); + if (cachedArray == null) { + cachedArray = makeCache(); + } + cachedArray[cacheOffset] = result; + } + + private String[] array() { + return (String[]) toStringCacheRef.get(); + } + + private String[] makeCache() { + String[] array = new String[3]; + toStringCacheRef = new java.lang.ref.SoftReference(array); + return array; + } + + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/SourceLocationImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/SourceLocationImpl.java new file mode 100644 index 000000000..91fc1c321 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/SourceLocationImpl.java @@ -0,0 +1,39 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import org.aspectj.lang.reflect.SourceLocation; + +class SourceLocationImpl implements SourceLocation { + Class withinType; + String fileName; + int line; + + SourceLocationImpl(Class withinType, String fileName, int line) { + this.withinType = withinType; + this.fileName = fileName; + this.line = line; + } + + public Class getWithinType() { return withinType; } + public String getFileName() { return fileName; } + public int getLine() { return line; } + public int getColumn() { return -1; } + + public String toString() { + return getFileName() + ":" + getLine(); + } +} + diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/StringMaker.java b/runtime/src/main/java/org/aspectj/runtime/reflect/StringMaker.java new file mode 100644 index 000000000..53e3988a9 --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/StringMaker.java @@ -0,0 +1,140 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Modifier; + +class StringMaker { + boolean shortTypeNames = true; + boolean includeArgs = true; + boolean includeThrows = false; + boolean includeModifiers = false; + boolean shortPrimaryTypeNames = false; + + boolean includeJoinPointTypeName = true; + boolean includeEnclosingPoint = true; + boolean shortKindName = true; + int cacheOffset; + + static StringMaker shortStringMaker; + static { + shortStringMaker = new StringMaker(); + shortStringMaker.shortTypeNames = true; + shortStringMaker.includeArgs = false; + shortStringMaker.includeThrows = false; + shortStringMaker.includeModifiers = false; + shortStringMaker.shortPrimaryTypeNames = true; + + shortStringMaker.includeJoinPointTypeName = false; + shortStringMaker.includeEnclosingPoint = false; + + shortStringMaker.cacheOffset = 0; + } + + static StringMaker middleStringMaker; + static { + middleStringMaker = new StringMaker(); + middleStringMaker.shortTypeNames = true; + middleStringMaker.includeArgs = true; + middleStringMaker.includeThrows = false; + middleStringMaker.includeModifiers = false; + middleStringMaker.shortPrimaryTypeNames = false; + + shortStringMaker.cacheOffset = 1; + } + + static StringMaker longStringMaker; + static { + longStringMaker = new StringMaker(); + longStringMaker.shortTypeNames = false; + longStringMaker.includeArgs = true; + longStringMaker.includeThrows = false; + longStringMaker.includeModifiers = true; + longStringMaker.shortPrimaryTypeNames = false; + longStringMaker.shortKindName = false; + + longStringMaker.cacheOffset = 2; + } + + String makeKindName(String name) { + int dash = name.lastIndexOf('-'); + if (dash == -1) return name; + return name.substring(dash+1); + } + + String makeModifiersString(int modifiers) { + if (!includeModifiers) return ""; + String str = Modifier.toString(modifiers); + if (str.length() == 0) return ""; + return str + " "; + } + + String stripPackageName(String name) { + int dot = name.lastIndexOf('.'); + if (dot == -1) return name; + return name.substring(dot+1); + } + + String makeTypeName(Class type, String typeName, boolean shortName) { + if (type == null) return "ANONYMOUS"; + if (type.isArray()) { + Class componentType = type.getComponentType(); + return makeTypeName(componentType, componentType.getName(), shortName) + "[]"; + } + if (shortName) { + return stripPackageName(typeName).replace('$', '.'); + } else { + return typeName.replace('$', '.'); + } + } + + public String makeTypeName(Class type) { + return makeTypeName(type, type.getName(),shortTypeNames); + } + + public String makePrimaryTypeName(Class type, String typeName) { + return makeTypeName(type, typeName, shortPrimaryTypeNames); + } + + public void addTypeNames(StringBuffer buf, Class[] types) { + for (int i = 0; i < types.length; i++) { + if (i > 0) buf.append(", "); + buf.append(makeTypeName(types[i])); + } + } + + public void addSignature(StringBuffer buf, Class[] types) { + if (types == null) return; + if (!includeArgs) { + if (types.length == 0) { + buf.append("()"); + return; + } else { + buf.append("(..)"); + return; + } + } + buf.append("("); + addTypeNames(buf, types); + buf.append(")"); + } + + public void addThrows(StringBuffer buf, Class[] types) { + if (!includeThrows || types == null || types.length == 0) return; + + buf.append(" throws "); + addTypeNames(buf, types); + } +} diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/UnlockSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/UnlockSignatureImpl.java new file mode 100644 index 000000000..d8b377a6f --- /dev/null +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/UnlockSignatureImpl.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ + + +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Modifier; + +import org.aspectj.lang.reflect.UnlockSignature; + +class UnlockSignatureImpl extends SignatureImpl implements UnlockSignature { + private Class parameterType; + + UnlockSignatureImpl(Class c) { + super(Modifier.STATIC, "unlock", c); + parameterType = c; + } + + UnlockSignatureImpl(String stringRep) { + super(stringRep); + } + + protected String createToString(StringMaker sm) { + if (parameterType == null) parameterType = extractType(3); + return "unlock("+sm.makeTypeName(parameterType)+")"; + } + + public Class getParameterType() { + if (parameterType == null) parameterType = extractType(3); + return parameterType; + } +} diff --git a/runtime/src/org/aspectj/lang/Aspects14.java b/runtime/src/org/aspectj/lang/Aspects14.java deleted file mode 100644 index b7f3a3a4b..000000000 --- a/runtime/src/org/aspectj/lang/Aspects14.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Contributors. - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: - * variant of Aspects in the aspectj5rt project - this one isn't Java5 - Andy Clement - *******************************************************************************/ -package org.aspectj.lang; - - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -/** - * For users working on a level of Java prior to Java5, Aspects14 handles generic aspectOf methods when they - * are not available in the aspects but added later on through load time weaving. Users on Java5 should use - * the class Aspects instead. - *

- * Aspects14.aspectOf(..) is doing reflective calls to the aspect aspectOf, so for better performance - * consider using ajc compilation of the aspects and using them as a binary dependancies in your project. - */ -public class Aspects14 { - - private final static Class[] EMPTY_CLASS_ARRAY = new Class[0]; - private final static Class[] PEROBJECT_CLASS_ARRAY = new Class[]{Object.class}; - private final static Class[] PERTYPEWITHIN_CLASS_ARRAY = new Class[]{Class.class}; - private final static Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - private final static String ASPECTOF = "aspectOf"; - private final static String HASASPECT = "hasAspect"; - - /** - * Returns the singleton aspect or the percflow / percflowbelow associated with the current thread - * - * @param aspectClass aspect class for which to discover the aspect instance - * @return an aspect instance - * @throws NoAspectBoundException if no such aspect - */ - public static Object aspectOf(Class aspectClass) throws NoAspectBoundException { - try { - return getSingletonOrThreadAspectOf(aspectClass).invoke(null, EMPTY_OBJECT_ARRAY); - } catch (InvocationTargetException e) { - //FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs - throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); - } catch (Exception e) { - throw new NoAspectBoundException(aspectClass.getName(), e); - } - } - - /** - * Returns the perthis / pertarget aspect - * @param aspectClass aspect class for which to discover the aspect instance - * @param perObject object for which to discover the aspect instance - * @return an aspect instance - * @throws NoAspectBoundException if no such aspect, or no aspect bound - */ - public static Object aspectOf(Class aspectClass, Object perObject) throws NoAspectBoundException { - try { - return getPerObjectAspectOf(aspectClass).invoke(null, new Object[]{perObject}); - } catch (InvocationTargetException e) { - //FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs - throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); - } catch (Exception e) { - throw new NoAspectBoundException(aspectClass.getName(), e); - } - } - - /** - * Returns the pertypewithin aspect - * @param aspectClass aspect class for which to discover the aspect instance - * @param perTypeWithin class - * @return - * @throws NoAspectBoundException if no such aspect, or no aspect bound - */ - public static Object aspectOf(Class aspectClass, Class perTypeWithin) throws NoAspectBoundException { - try { - return getPerTypeWithinAspectOf(aspectClass).invoke(null, new Object[]{perTypeWithin}); - } catch (InvocationTargetException e) { -// FIXME asc Highly temporary change to see what the build makes of it - dont use 1.4 APIs - throw new NoAspectBoundException(aspectClass.getName(), e);//e.getCause()); - } catch (Exception e) { - throw new NoAspectBoundException(aspectClass.getName(), e); - } - } - - /** - * Returns true if singleton aspect or percflow / percflowbelow aspect is bound - * - * @param aspectClass aspect class for which to check the aspect instance - * @return - * @throws NoAspectBoundException if not bound - */ - public static boolean hasAspect(Class aspectClass) throws NoAspectBoundException { - try { - return ((Boolean)getSingletonOrThreadHasAspect(aspectClass).invoke(null, EMPTY_OBJECT_ARRAY)).booleanValue(); - } catch (Exception e) { - return false; - } - } - - /** - * Returns true if the perthis / pertarget aspect is bound - * @param aspectClass aspect class for which to check the aspect instance - * @param perObject - * @return true if aspect instance exists for the class/object combination - * @throws NoAspectBoundException if not bound - */ - public static boolean hasAspect(Class aspectClass, Object perObject) throws NoAspectBoundException { - try { - return ((Boolean)getPerObjectHasAspect(aspectClass).invoke(null, new Object[]{perObject})).booleanValue(); - } catch (Exception e) { - return false; - } - } - - /** - * Returns true if the pertypewithin aspect is bound - * @param aspectClass aspect class for which to check the aspect instance - * @param perTypeWithin class - * @return true if aspect instance exists for this aspect class/pertypewithin class combination - * @throws NoAspectBoundException if not bound - */ - public static boolean hasAspect(Class aspectClass, Class perTypeWithin) throws NoAspectBoundException { - try { - return ((Boolean)getPerTypeWithinHasAspect(aspectClass).invoke(null, new Object[]{perTypeWithin})).booleanValue(); - } catch (Exception e) { - return false; - } - } - - // -- aspectOf - - private static Method getSingletonOrThreadAspectOf(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(ASPECTOF, EMPTY_CLASS_ARRAY); - return checkAspectOf(method, aspectClass); - } - - private static Method getPerObjectAspectOf(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(ASPECTOF, PEROBJECT_CLASS_ARRAY); - return checkAspectOf(method, aspectClass); - } - - private static Method getPerTypeWithinAspectOf(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(ASPECTOF, PERTYPEWITHIN_CLASS_ARRAY); - return checkAspectOf(method, aspectClass); - } - - private static Method checkAspectOf(Method method, Class aspectClass) throws NoSuchMethodException { - method.setAccessible(true); - if (!method.isAccessible() - || !Modifier.isPublic(method.getModifiers()) - || !Modifier.isStatic(method.getModifiers())) { - throw new NoSuchMethodException(aspectClass.getName() + ".aspectOf(..) is not accessible public static"); - } - return method; - } - - // -- hasAspect - - private static Method getSingletonOrThreadHasAspect(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(HASASPECT, EMPTY_CLASS_ARRAY); - return checkHasAspect(method, aspectClass); - } - - private static Method getPerObjectHasAspect(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(HASASPECT, PEROBJECT_CLASS_ARRAY); - return checkHasAspect(method, aspectClass); - } - - private static Method getPerTypeWithinHasAspect(Class aspectClass) throws NoSuchMethodException { - Method method = aspectClass.getDeclaredMethod(HASASPECT, PERTYPEWITHIN_CLASS_ARRAY); - return checkHasAspect(method, aspectClass); - } - - private static Method checkHasAspect(Method method, Class aspectClass) throws NoSuchMethodException { - method.setAccessible(true); - if (!method.isAccessible() - || !Modifier.isPublic(method.getModifiers()) - || !Modifier.isStatic(method.getModifiers())) { - throw new NoSuchMethodException(aspectClass.getName() + ".hasAspect(..) is not accessible public static"); - } - return method; - } -} diff --git a/runtime/src/org/aspectj/lang/JoinPoint.java b/runtime/src/org/aspectj/lang/JoinPoint.java deleted file mode 100644 index 5d66c7930..000000000 --- a/runtime/src/org/aspectj/lang/JoinPoint.java +++ /dev/null @@ -1,204 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang; - -import org.aspectj.lang.reflect.SourceLocation; - -/** - *

Provides reflective access to both the state available at a join point and - * static information about it. This information is available from the body - * of advice using the special form thisJoinPoint. The primary - * use of this reflective information is for tracing and logging applications. - *

- * - *
- * aspect Logging {
- *     before(): within(com.bigboxco..*) && execution(public * *(..)) {
- *         System.err.println("entering: " + thisJoinPoint);
- *         System.err.println("  w/args: " + thisJoinPoint.getArgs());
- *         System.err.println("      at: " + thisJoinPoint.getSourceLocation());
- *     }
- * }
- * 
- */ -public interface JoinPoint { - - String toString(); - - /** - * Returns an abbreviated string representation of the join point. - */ - String toShortString(); - - /** - * Returns an extended string representation of the join point. - */ - String toLongString(); - - /** - *

Returns the currently executing object. This will always be - * the same object as that matched by the this pointcut - * designator. Unless you specifically need this reflective access, - * you should use the this pointcut designator to - * get at this object for better static typing and performance.

- * - *

Returns null when there is no currently executing object available. - * This includes all join points that occur in a static context.

- */ - Object getThis(); - - /** - *

Returns the target object. This will always be - * the same object as that matched by the target pointcut - * designator. Unless you specifically need this reflective access, - * you should use the target pointcut designator to - * get at this object for better static typing and performance.

- * - *

Returns null when there is no target object.

- - */ - Object getTarget(); - - /** - *

Returns the arguments at this join point.

- */ - Object[] getArgs(); - - /** Returns the signature at the join point. - * - * getStaticPart().getSignature() returns the same object - */ - Signature getSignature(); - - /**

Returns the source location corresponding to the join point.

- * - *

If there is no source location available, returns null.

- * - *

Returns the SourceLocation of the defining class for default constructors.

- * - *

getStaticPart().getSourceLocation() returns the same object.

- */ - SourceLocation getSourceLocation(); - - /** Returns a String representing the kind of join point. This - * String is guaranteed to be - * interned. getStaticPart().getKind() returns - * the same object. - */ - String getKind(); - - /** - *

This helper object contains only the static information about a join point. - * It is available from the JoinPoint.getStaticPart() method, and - * can be accessed separately within advice using the special form - * thisJoinPointStaticPart.

- * - *

If you are only interested in the static information about a join point, - * you should access it through this type for the best performance. This - * is particularly useful for library methods that want to do serious - * manipulations of this information, i.e.

- * - *
-     * public class LoggingUtils {
-     *     public static void prettyPrint(JoinPoint.StaticPart jp) {
-     *         ...
-     *     }
-     * }
-     *
-     * aspect Logging {
-     *     before(): ... { LoggingUtils.prettyPrint(thisJoinPointStaticPart); }
-     * }
-     * 
- * - * @see JoinPoint#getStaticPart() - */ - public interface StaticPart { - /** Returns the signature at the join point. */ - Signature getSignature(); - - /**

Returns the source location corresponding to the join point.

- * - *

If there is no source location available, returns null.

- * - *

Returns the SourceLocation of the defining class for default constructors.

- */ - SourceLocation getSourceLocation(); - - /**

Returns a String representing the kind of join point. This String - * is guaranteed to be interned

- */ - 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. - *
- * The id is guaranteed to remain constant across repeated executions - * of a program but may change if the code is recompiled. - *
- * 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. - *
- * 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(); - - /** - * Returns an abbreviated string representation of the join point - */ - String toShortString(); - - /** - * Returns an extended string representation of the join point - */ - String toLongString(); - } - - public interface EnclosingStaticPart extends StaticPart {} - - /** - * Returns an object that encapsulates the static parts of this join point. - */ - StaticPart getStaticPart(); - - - /** - * The legal return values from getKind() - */ - static String METHOD_EXECUTION = "method-execution"; - static String METHOD_CALL = "method-call"; - static String CONSTRUCTOR_EXECUTION = "constructor-execution"; - static String CONSTRUCTOR_CALL = "constructor-call"; - static String FIELD_GET = "field-get"; - static String FIELD_SET = "field-set"; - static String STATICINITIALIZATION = "staticinitialization"; - static String PREINITIALIZATION = "preinitialization"; - static String INITIALIZATION = "initialization"; - static String EXCEPTION_HANDLER = "exception-handler"; - static String SYNCHRONIZATION_LOCK = "lock"; - static String SYNCHRONIZATION_UNLOCK = "unlock"; - - static String ADVICE_EXECUTION = "adviceexecution"; - -} diff --git a/runtime/src/org/aspectj/lang/NoAspectBoundException.java b/runtime/src/org/aspectj/lang/NoAspectBoundException.java deleted file mode 100644 index 286e4c1f1..000000000 --- a/runtime/src/org/aspectj/lang/NoAspectBoundException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang; - -/** - * Thrown by the aspectOf special method on aspect types - * when there is no aspect of that type currently bound. - */ -public class NoAspectBoundException extends RuntimeException { - Throwable cause; - public NoAspectBoundException(String aspectName, Throwable inner) { - super(inner == null ? aspectName : - "Exception while initializing " +aspectName + ": " +inner); - this.cause = inner; - } - - public NoAspectBoundException() { - } - - public Throwable getCause() { return cause; } - -} diff --git a/runtime/src/org/aspectj/lang/ProceedingJoinPoint.java b/runtime/src/org/aspectj/lang/ProceedingJoinPoint.java deleted file mode 100644 index 5bbc2df85..000000000 --- a/runtime/src/org/aspectj/lang/ProceedingJoinPoint.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 Contributors. - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: - * initial implementation Alexandre Vasseur - *******************************************************************************/ -package org.aspectj.lang; - -import org.aspectj.runtime.internal.AroundClosure; - -/** - * ProceedingJoinPoint exposes the proceed(..) method in order to support around advice in @AJ aspects - * - * @author Alexandre Vasseur - */ -public interface ProceedingJoinPoint extends JoinPoint { - - /** - * The joinpoint needs to know about its closure so that proceed can delegate to closure.run() - *

- * This internal method should not be called directly, and won't be visible to the end-user when - * packed in a jar (synthetic method) - * - * @param arc - */ - void set$AroundClosure(AroundClosure arc); - - /** - * Proceed with the next advice or target method invocation - * - * @return - * @throws Throwable - */ - public Object proceed() throws Throwable; - - /** - * Proceed with the next advice or target method invocation - *

- *

Unlike code style, proceed(..) in annotation style places different requirements on the - * parameters passed to it. The proceed(..) call takes, in this order: - *

    - *
  • If 'this()' was used in the pointcut for binding, it must be passed first in proceed(..). - *
  • If 'target()' was used in the pointcut for binding, it must be passed next in proceed(..) - - * it will be the first argument to proceed(..) if this() was not used for binding. - *
  • Finally come all the arguments expected at the join point, in the order they are supplied - * at the join point. Effectively the advice signature is ignored - it doesn't matter - * if a subset of arguments were bound or the ordering was changed in the advice signature, - * the proceed(..) calls takes all of them in the right order for the join point. - *
- *

Since proceed(..) in this case takes an Object array, AspectJ cannot do as much - * compile time checking as it can for code style. If the rules above aren't obeyed - * then it will unfortunately manifest as a runtime error. - *

- * - * @param args - * @return - * @throws Throwable - */ - public Object proceed(Object[] args) throws Throwable; - -} - - diff --git a/runtime/src/org/aspectj/lang/Signature.java b/runtime/src/org/aspectj/lang/Signature.java deleted file mode 100644 index 5bc008433..000000000 --- a/runtime/src/org/aspectj/lang/Signature.java +++ /dev/null @@ -1,102 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang; - -/**

Represents the signature at a join point. This interface parallels - * java.lang.reflect.Member.

- * - *

This interface is typically used for tracing or logging applications - * to obtain reflective information about the join point, i.e. using - * the j2se 1.4 java.util.logging API

- *
- * aspect Logging {
- *     Logger logger = Logger.getLogger("MethodEntries");
- * 
- *     before(): within(com.bigboxco..*) && execution(public * *(..)) {
- *         Signature sig = thisJoinPoint.getSignature();
- *         logger.entering(sig.getDeclaringType().getName(),
- *                         sig.getName());
- *     }
- * }
- * 
- * - * - *

More detailed information about a specific kind of signature can - * be obtained by casting this Signature object into one - * of its more specific sub-types available in - * org.aspectj.lang.reflect. - * - * @see java.lang.reflect.Member - * @see java.util.logging.Logger - */ -public interface Signature { - String toString(); - /** - * Returns an abbreviated string representation of this signature. - */ - String toShortString(); - - /** - * Returns an extended string representation of this signature. - */ - String toLongString(); - - - /** - * Returns the identifier part of this signature. For methods this - * will return the method name. - * - * @see java.lang.reflect.Member#getName - */ - String getName(); - - /** - * Returns the modifiers on this signature represented as an int. Use - * the constants and helper methods defined on - * java.lang.reflect.Modifier to manipulate this, i.e. - *

-     *     // check if this signature is public
-     *     java.lang.reflect.Modifier.isPublic(sig.getModifiers());
-     * 
-     *     // print out the modifiers
-     *     java.lang.reflect.Modifier.toString(sig.getModifiers());
-     * 
- * - * @see java.lang.reflect.Member#getModifiers - * @see java.lang.reflect.Modifier - */ - int getModifiers(); - - /** - *

Returns a java.lang.Class object representing the class, - * interface, or aspect that declared this member. For intra-member - * declarations, this will be the type on which the member is declared, - * not the type where the declaration is lexically written. Use - * SourceLocation.getWithinType() to get the type in - * which the declaration occurs lexically.

- *

For consistency with java.lang.reflect.Member, this - * method should have been named getDeclaringClass().

- * - * @see java.lang.reflect.Member#getDeclaringClass - */ - Class getDeclaringType(); - - /** - * Returns the fully-qualified name of the declaring type. This is - * equivalent to calling getDeclaringType().getName(), but caches - * the result for greater efficiency. - */ - String getDeclaringTypeName(); -} diff --git a/runtime/src/org/aspectj/lang/SoftException.java b/runtime/src/org/aspectj/lang/SoftException.java deleted file mode 100644 index ea75ebac4..000000000 --- a/runtime/src/org/aspectj/lang/SoftException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC), - * 2004 Contributors. - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang; - -import java.io.PrintStream; -import java.io.PrintWriter; - -/** - * Wrapper for checked exceptions matched by a 'declare soft'. - * You can soften checked exceptions at join points by using - * the form declare soft: TypePattern: Pointcut. - * At the join points, any exceptions thrown which match - * TypePattern will be wrapped in SoftException - * and rethrown. You can get the original exception using - * getWrappedThrowable() or - * getCause(). - */ -public class SoftException extends RuntimeException { - - private static final boolean HAVE_JAVA_14; - - static { - boolean java14 = false; - try { - Class.forName("java.nio.Buffer"); - java14 = true; - } catch (Throwable t) { - // still false; - } - HAVE_JAVA_14 = java14; - } - - // shouldn't field be private final, constructor default or private? - // but either would be a binary incompatible change. - - Throwable inner; - - public SoftException(Throwable inner) { - super(); - this.inner = inner; - } - - public Throwable getWrappedThrowable() { return inner; } - public Throwable getCause() { return inner; } - - public void printStackTrace() { - printStackTrace(System.err); - } - - public void printStackTrace(PrintStream stream) { - super.printStackTrace(stream); - final Throwable _inner = this.inner; - if (!HAVE_JAVA_14 && (null != _inner)) { - stream.print("Caused by: "); - _inner.printStackTrace(stream); - } - } - - public void printStackTrace(PrintWriter stream) { - super.printStackTrace(stream); - final Throwable _inner = this.inner; - if (!HAVE_JAVA_14 && (null != _inner)) { - stream.print("Caused by: "); - _inner.printStackTrace(stream); - } - } -} diff --git a/runtime/src/org/aspectj/lang/package.html b/runtime/src/org/aspectj/lang/package.html deleted file mode 100644 index a5fe7ae5d..000000000 --- a/runtime/src/org/aspectj/lang/package.html +++ /dev/null @@ -1,14 +0,0 @@ - - -Provides several interfaces for obtaining reflective information about a -join point, as well as several exceptions that can be thrown by AspectJ -code. -

-JoinPoint and Signature provide reflective -information about a join point. Instances of these interfaces are -available inside of advice with the special variables -thisJoinPoint, thisJoinPointStaticPart, and -thisEnclosingJoinPointStaticPart.

- - - diff --git a/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java b/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java deleted file mode 100644 index c01f75019..000000000 --- a/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java +++ /dev/null @@ -1,23 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -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(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java b/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java deleted file mode 100644 index 9a008994d..000000000 --- a/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java +++ /dev/null @@ -1,22 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; - -import org.aspectj.lang.Signature; - -public interface CatchClauseSignature extends Signature { - Class getParameterType(); - String getParameterName(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/CodeSignature.java b/runtime/src/org/aspectj/lang/reflect/CodeSignature.java deleted file mode 100644 index 1c6ba45e3..000000000 --- a/runtime/src/org/aspectj/lang/reflect/CodeSignature.java +++ /dev/null @@ -1,21 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; - -public interface CodeSignature extends MemberSignature { - Class[] getParameterTypes(); - String[] getParameterNames(); - Class[] getExceptionTypes(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java b/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java deleted file mode 100644 index 268a759a2..000000000 --- a/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java +++ /dev/null @@ -1,20 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; -import java.lang.reflect.Constructor; - -public interface ConstructorSignature extends CodeSignature { - Constructor getConstructor(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/FieldSignature.java b/runtime/src/org/aspectj/lang/reflect/FieldSignature.java deleted file mode 100644 index df1c57656..000000000 --- a/runtime/src/org/aspectj/lang/reflect/FieldSignature.java +++ /dev/null @@ -1,21 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; -import java.lang.reflect.Field; - -public interface FieldSignature extends MemberSignature { - public Class getFieldType(); - public Field getField(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java b/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java deleted file mode 100644 index bbef8b6fa..000000000 --- a/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java +++ /dev/null @@ -1,31 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC), - * 2006 Contributors. - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; -import java.lang.reflect.Constructor; - -/** - * Signature for static and instance initializers. - * Static initializers have no parameters or exceptions, - * so empty arrays are returned from the CodeSignature methods. - */ -public interface InitializerSignature extends CodeSignature { - /** - * @return Constructor associated with this initializer, - * or null in the case of interface initializers and - * static initializers. - */ - Constructor getInitializer(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/LockSignature.java b/runtime/src/org/aspectj/lang/reflect/LockSignature.java deleted file mode 100644 index 5a52b3041..000000000 --- a/runtime/src/org/aspectj/lang/reflect/LockSignature.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation - *******************************************************************************/ - -package org.aspectj.lang.reflect; - -import org.aspectj.lang.Signature; - -public interface LockSignature extends Signature { - -} diff --git a/runtime/src/org/aspectj/lang/reflect/MemberSignature.java b/runtime/src/org/aspectj/lang/reflect/MemberSignature.java deleted file mode 100644 index cbc448e1b..000000000 --- a/runtime/src/org/aspectj/lang/reflect/MemberSignature.java +++ /dev/null @@ -1,22 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; - -import org.aspectj.lang.Signature; - -public interface MemberSignature extends Signature { - // AccessibleObject is a 1.2 API, we run on 1.1... (thanks Wes for catching this) - //AccessibleObject getAccessibleObject(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/MethodSignature.java b/runtime/src/org/aspectj/lang/reflect/MethodSignature.java deleted file mode 100644 index d660e1eb1..000000000 --- a/runtime/src/org/aspectj/lang/reflect/MethodSignature.java +++ /dev/null @@ -1,21 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -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(); -} diff --git a/runtime/src/org/aspectj/lang/reflect/SourceLocation.java b/runtime/src/org/aspectj/lang/reflect/SourceLocation.java deleted file mode 100644 index 52f1dd7a6..000000000 --- a/runtime/src/org/aspectj/lang/reflect/SourceLocation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.lang.reflect; - -/** For defining code, the class defined and location in a source file. */ -public interface SourceLocation { - Class getWithinType(); - - String getFileName(); - int getLine(); - - /** - * @deprecated can not be implemented for bytecode weaving, may - * be removed in 1.1gold. - */ - int getColumn(); -} - diff --git a/runtime/src/org/aspectj/lang/reflect/UnlockSignature.java b/runtime/src/org/aspectj/lang/reflect/UnlockSignature.java deleted file mode 100644 index 3e117ce18..000000000 --- a/runtime/src/org/aspectj/lang/reflect/UnlockSignature.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation - *******************************************************************************/ - - -package org.aspectj.lang.reflect; - -import org.aspectj.lang.Signature; - -public interface UnlockSignature extends Signature { - -} diff --git a/runtime/src/org/aspectj/lang/reflect/package.html b/runtime/src/org/aspectj/lang/reflect/package.html deleted file mode 100644 index fc51a5b60..000000000 --- a/runtime/src/org/aspectj/lang/reflect/package.html +++ /dev/null @@ -1,18 +0,0 @@ - - -

Contains interfaces that extend Signature to provide -additional information about each possible join point signature. This -additional information can be accessed by casting a Signature object -to the appropriate type, i.e.

-
-  before(): call(* *(..)) {
-      MethodSignature sig = (MethodSignature)thisJoinPoint.getSignature();
-      ...
-  }
-
- -

This package also contains SourceLocation that provides -information about the location in source code that corresponds to a -particular join point.

- - diff --git a/runtime/src/org/aspectj/runtime/CFlow.java b/runtime/src/org/aspectj/runtime/CFlow.java deleted file mode 100644 index d607b4822..000000000 --- a/runtime/src/org/aspectj/runtime/CFlow.java +++ /dev/null @@ -1,39 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime; - -public class CFlow { - private Object _aspect; - - public CFlow() { - this(null); - } - - public CFlow(Object _aspect) { - this._aspect = _aspect; - } - - public Object getAspect() { - return this._aspect; - } - - public void setAspect(Object _aspect) { - this._aspect = _aspect; - } - - public Object get(int index) { - return null; - } -} diff --git a/runtime/src/org/aspectj/runtime/internal/AroundClosure.java b/runtime/src/org/aspectj/runtime/internal/AroundClosure.java deleted file mode 100644 index 91f7f923c..000000000 --- a/runtime/src/org/aspectj/runtime/internal/AroundClosure.java +++ /dev/null @@ -1,76 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * Alex Vasseur wired up for @AJ proceeding - * Andy Clement 23-06-06 added extras for @AJ - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -import org.aspectj.lang.ProceedingJoinPoint; - -public abstract class AroundClosure { - protected Object[] state; - - // Records with the related joinpoint has a this or a target and whether - // either of them are bound in the pointcut. Set in the 'link' call made - // at each matching join point... (see pr126167) - // bit6 being 1 means the flags haven't been initialized - protected int bitflags = 0x100000; - protected Object[] preInitializationState; - - public AroundClosure() { - } - - public AroundClosure(Object[] state) { - this.state = state; - } - - public int getFlags() {return bitflags;} - - public Object[] getState() { - return state; - } - - public Object[] getPreInitializationState() { - return preInitializationState; - } - - /** - * This takes in the same arguments as are passed to the proceed - * call in the around advice (with primitives coerced to Object types) - */ - public abstract Object run(Object[] args) throws Throwable; - - /** - * This method is called to implicitly associate the closure with the joinpoint - * as required for @AJ aspect proceed() - */ - public ProceedingJoinPoint linkClosureAndJoinPoint() { - //TODO is this cast safe ? - ProceedingJoinPoint jp = (ProceedingJoinPoint)state[state.length-1]; - jp.set$AroundClosure(this); - return jp; - } - - /** - * This method is called to implicitly associate the closure with the joinpoint - * as required for @AJ aspect proceed() - */ - public ProceedingJoinPoint linkClosureAndJoinPoint(int flags) { - //TODO is this cast safe ? - ProceedingJoinPoint jp = (ProceedingJoinPoint)state[state.length-1]; - jp.set$AroundClosure(this); - this.bitflags = flags; - return jp; - } -} diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowCounter.java b/runtime/src/org/aspectj/runtime/internal/CFlowCounter.java deleted file mode 100644 index 633458195..000000000 --- a/runtime/src/org/aspectj/runtime/internal/CFlowCounter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -import org.aspectj.runtime.internal.cflowstack.ThreadCounter; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; - - -public class CFlowCounter { - - private static ThreadStackFactory tsFactory; - private ThreadCounter flowHeightHandler; - - static { - selectFactoryForVMVersion(); - } - - public CFlowCounter() { - flowHeightHandler = tsFactory.getNewThreadCounter(); - } - - public void inc() { - flowHeightHandler.inc(); - } - - public void dec() { - flowHeightHandler.dec(); - if (!flowHeightHandler.isNotZero()) { - flowHeightHandler.removeThreadCounter(); - } - } - - public boolean isValid() { - return flowHeightHandler.isNotZero(); - } - - - private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } - private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } - - private static void selectFactoryForVMVersion() { - String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); - boolean useThreadLocalImplementation = false; - if (override.equals("unspecified")) { - String v = System.getProperty("java.class.version","0.0"); - // Java 1.2 is version 46.0 and above - useThreadLocalImplementation = (v.compareTo("46.0") >= 0); - } else { - useThreadLocalImplementation = override.equals("yes") || override.equals("true"); - } - // System.err.println("Trying to use thread local implementation? "+useThreadLocalImplementation); - if (useThreadLocalImplementation) { - tsFactory = getThreadLocalStackFactory(); - } else { - tsFactory = getThreadLocalStackFactoryFor11(); - } - } - - - private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { - try { - return System.getProperty(aPropertyName, aDefaultValue); - } - catch (SecurityException ex) { - return aDefaultValue; - } - } - - // For debug ... - public static String getThreadStackFactoryClassName() { - return tsFactory.getClass().getName(); - } - -} diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java b/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java deleted file mode 100644 index b78864a33..000000000 --- a/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java +++ /dev/null @@ -1,32 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -public class CFlowPlusState extends org.aspectj.runtime.CFlow { - private Object[] state; - - public CFlowPlusState(Object[] state) { - this.state = state; - } - - public CFlowPlusState(Object[] state, Object _aspect) { - super(_aspect); - this.state = state; - } - - public Object get(int index) { - return state[index]; - } -} diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowStack.java b/runtime/src/org/aspectj/runtime/internal/CFlowStack.java deleted file mode 100644 index 48308f145..000000000 --- a/runtime/src/org/aspectj/runtime/internal/CFlowStack.java +++ /dev/null @@ -1,160 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -import java.util.Stack; - -import org.aspectj.lang.NoAspectBoundException; -import org.aspectj.runtime.CFlow; -import org.aspectj.runtime.internal.cflowstack.ThreadStack; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; -import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; - -/* - * How we benefit from ThreadLocal when it is available at runtime: - * - * When the CFlowStack class is loaded, we run its static initializer. This checks the JVM - * version number and loads an appropriate implementation of the ThreadStackFactory. - * There are two possible implementations depending on whether this is a 1.1 or 1.2+ JVM. - * Rather than doing a Class.forName for ThreadLocal and catching a ClassNotFoundEx in order - * to determine the JVM version, we look at the java class version which I believe can help - * us identify the Java level. - * - * In the 1.1 JVM case we use a factory implementation that does not use ThreadLocal storage. - * In the 1.2+ JVM case we use a factory implementation that does use ThreadLocal storage. - * - * Once we have the factory set, whenever someone builds a CFlowStack object, we ask the - * factory for a new stack proxy - this is an object that can return us the right stack - * that we should use on a particular thread. The reason we create the proxy in the ctor and - * not lazily in the getThreadStack() method is because it means the getThreadStack() method in - * this class does not have to be synchronized. - * - * When any of the methods in CFlowStack need to operate on the stack (peek/pop/etc), they - * all delegate to getThreadStack() which asks the proxy for the right stack. Depending on the - * factory loaded to build the proxy, the call to proxy.getThreadStack() will return a threadlocal - * based stack or it will call the original implementation of getThreadStack() which manages - * a Hashtable of threads->stacks. - * - */ - -public class CFlowStack { - - private static ThreadStackFactory tsFactory; - private ThreadStack stackProxy; - - static { - selectFactoryForVMVersion(); - } - - public CFlowStack() { - stackProxy = tsFactory.getNewThreadStack(); - } - - private Stack getThreadStack() { - return stackProxy.getThreadStack(); - } - - //XXX dangerous, try to remove - public void push(Object obj) { - getThreadStack().push(obj); - } - - public void pushInstance(Object obj) { - getThreadStack().push(new CFlow(obj)); - } - - public void push(Object[] obj) { - getThreadStack().push(new CFlowPlusState(obj)); - } - - public void pop() { - Stack s = getThreadStack(); - s.pop(); - if (s.isEmpty()) { - stackProxy.removeThreadStack(); - } - } - - public Object peek() { - Stack stack = getThreadStack(); - if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException(); - return (Object)stack.peek(); - } - - public Object get(int index) { - CFlow cf = peekCFlow(); - return (null == cf ? null : cf.get(index)); - } - - public Object peekInstance() { - CFlow cf = peekCFlow(); - if (cf != null ) return cf.getAspect(); - else throw new NoAspectBoundException(); - } - - public CFlow peekCFlow() { - Stack stack = getThreadStack(); - if (stack.isEmpty()) return null; - return (CFlow)stack.peek(); - } - - public CFlow peekTopCFlow() { - Stack stack = getThreadStack(); - if (stack.isEmpty()) return null; - return (CFlow)stack.elementAt(0); - } - - public boolean isValid() { - return !getThreadStack().isEmpty(); - } - - private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } - private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } - - private static void selectFactoryForVMVersion() { - String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); - boolean useThreadLocalImplementation = false; - if (override.equals("unspecified")) { - String v = System.getProperty("java.class.version","0.0"); - // Java 1.2 is version 46.0 and above - useThreadLocalImplementation = (v.compareTo("46.0") >= 0); - } else { - useThreadLocalImplementation = override.equals("yes") || override.equals("true"); - } - // System.err.println("Trying to use thread local implementation? "+useThreadLocalImplementation); - if (useThreadLocalImplementation) { - tsFactory = getThreadLocalStackFactory(); - } else { - tsFactory = getThreadLocalStackFactoryFor11(); - } - } - - private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { - try { - return System.getProperty(aPropertyName, aDefaultValue); - } - catch (SecurityException ex) { - return aDefaultValue; - } - } - - - // For debug ... - public static String getThreadStackFactoryClassName() { - return tsFactory.getClass().getName(); - } - -} diff --git a/runtime/src/org/aspectj/runtime/internal/Conversions.java b/runtime/src/org/aspectj/runtime/internal/Conversions.java deleted file mode 100644 index f74e8d919..000000000 --- a/runtime/src/org/aspectj/runtime/internal/Conversions.java +++ /dev/null @@ -1,145 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -public final class Conversions { - // Can't make instances of me - private Conversions() {} - - // we might want to keep a cache of small integers around - public static Object intObject(int i) { - return new Integer(i); - } - public static Object shortObject(short i) { - return new Short(i); - } - public static Object byteObject(byte i) { - return new Byte(i); - } - public static Object charObject(char i) { - return new Character(i); - } - public static Object longObject(long i) { - return new Long(i); - } - public static Object floatObject(float i) { - return new Float(i); - } - public static Object doubleObject(double i) { - return new Double(i); - } - public static Object booleanObject(boolean i) { - return new Boolean(i); - } - public static Object voidObject() { - return null; - } - - - public static int intValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).intValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to int"); - } - } - public static long longValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).longValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to long"); - } - } - public static float floatValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).floatValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to float"); - } - } - public static double doubleValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).doubleValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to double"); - } - } - public static byte byteValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).byteValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to byte"); - } - } - public static short shortValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Number) { - return ((Number)o).shortValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to short"); - } - } - public static char charValue(Object o) { - if (o == null) { - return 0; - } else if (o instanceof Character) { - return ((Character)o).charValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to char"); - } - } - public static boolean booleanValue(Object o) { - if (o == null) { - return false; - } else if (o instanceof Boolean) { - return ((Boolean)o).booleanValue(); - } else { - throw new ClassCastException(o.getClass().getName() + - " can not be converted to boolean"); - } - } - - /** - * identity function for now. This is not typed to "void" because we happen - * to know that in Java, any void context (i.e., {@link ExprStmt}) - * can also handle a return value. - */ - public static Object voidValue(Object o) { - if (o == null) { - return o; - } else { - // !!! this may be an error in the future - return o; - } - } -} diff --git a/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java b/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java deleted file mode 100644 index 319740572..000000000 --- a/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java +++ /dev/null @@ -1,31 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.internal; - -//import java.util.WeakHashMap; // XXX REQUIRES JAVA 2!!!!!!!!!!!!!!!! - -public class PerObjectMap { -// private WeakHashMap map = new WeakHashMap(); -// -// public boolean hasAspect(Object o) { return map.containsKey(o); } -// -// public Object aspectOf(Object o) { -// return map.get(o); -// } -// -// public void bind(Object object, Object _aspect) { -// map.put(object, _aspect); -// } -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java deleted file mode 100644 index 1fa064cee..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounter.java +++ /dev/null @@ -1,22 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ - -package org.aspectj.runtime.internal.cflowstack; - - -public interface ThreadCounter { - public void inc(); - public void dec(); - public boolean isNotZero(); - public void removeThreadCounter(); -} \ No newline at end of file diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java deleted file mode 100644 index 71aaacd62..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java +++ /dev/null @@ -1,78 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * Copied from bits of original CFlowStack - * ******************************************************************/ -package org.aspectj.runtime.internal.cflowstack; - -import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; - -public class ThreadCounterImpl11 implements ThreadCounter { - private Hashtable counters = new Hashtable(); - private Thread cached_thread; - private Counter cached_counter; - - private int change_count = 0; - private static final int COLLECT_AT = 20000; - private static final int MIN_COLLECT_AT = 100; - - static class Counter { - protected int value = 0; - } - - private synchronized Counter getThreadCounter() { - if (Thread.currentThread() != cached_thread) { - cached_thread = Thread.currentThread(); - cached_counter = (Counter)counters.get(cached_thread); - if (cached_counter == null) { - cached_counter = new Counter(); - counters.put(cached_thread, cached_counter); - } - change_count++; - // 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... - if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { - List dead_stacks = new ArrayList(); - for (Enumeration e = counters.keys(); e.hasMoreElements(); ) { - Thread t = (Thread)e.nextElement(); - if (!t.isAlive()) dead_stacks.add(t); - } - for (Iterator e = dead_stacks.iterator(); e.hasNext(); ) { - Thread t = (Thread)e.next(); - counters.remove(t); - } - change_count = 0; - } - } - return cached_counter; - } - - public void inc() { - getThreadCounter().value++; - } - - public void dec() { - getThreadCounter().value--; - } - - public boolean isNotZero() { - return getThreadCounter().value!=0; - } - - public void removeThreadCounter() { - // TODO - } - -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStack.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStack.java deleted file mode 100644 index 7290163d2..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStack.java +++ /dev/null @@ -1,23 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ - -package org.aspectj.runtime.internal.cflowstack; - -import java.util.Stack; - -public interface ThreadStack { - - public Stack getThreadStack(); - public void removeThreadStack(); - -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java deleted file mode 100644 index 38ba0ccbd..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactory.java +++ /dev/null @@ -1,20 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.runtime.internal.cflowstack; - -public interface ThreadStackFactory { - - public ThreadStack getNewThreadStack(); - public ThreadCounter getNewThreadCounter(); - -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java deleted file mode 100644 index 2437f06b0..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.runtime.internal.cflowstack; - -import java.util.Stack; - -public class ThreadStackFactoryImpl implements ThreadStackFactory { - - private static class ThreadStackImpl extends ThreadLocal implements ThreadStack { - public Object initialValue() { - return new Stack(); - } - public Stack getThreadStack() { - return (Stack)get(); - } - public void removeThreadStack() { - this.remove(); - } - } - - public ThreadStack getNewThreadStack() { - return new ThreadStackImpl(); - } - - private static class ThreadCounterImpl extends ThreadLocal implements ThreadCounter { - - public Object initialValue() { - return new Counter(); - } - public Counter getThreadCounter() { - return (Counter)get(); - } - - public void removeThreadCounter() { - this.remove(); - } - - public void inc() { getThreadCounter().value++; } - public void dec() { getThreadCounter().value--; } - public boolean isNotZero() { return getThreadCounter().value!= 0; } - - static class Counter { - protected int value = 0; - } - } - - public ThreadCounter getNewThreadCounter() { - return new ThreadCounterImpl(); - } - -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java deleted file mode 100644 index 21c246193..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl11.java +++ /dev/null @@ -1,26 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * ******************************************************************/ -package org.aspectj.runtime.internal.cflowstack; - - -public class ThreadStackFactoryImpl11 implements ThreadStackFactory { - - public ThreadStack getNewThreadStack() { - return new ThreadStackImpl11(); - } - - public ThreadCounter getNewThreadCounter() { - return new ThreadCounterImpl11(); - } - -} diff --git a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java b/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java deleted file mode 100644 index 51f09cadd..000000000 --- a/runtime/src/org/aspectj/runtime/internal/cflowstack/ThreadStackImpl11.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2004 IBM Corporation - * - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement initial implementation - * Copied from bits of original CFlowStack - * ******************************************************************/ -package org.aspectj.runtime.internal.cflowstack; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Stack; - -public class ThreadStackImpl11 implements ThreadStack { - private Hashtable stacks = new Hashtable(); - private Thread cached_thread; - private Stack cached_stack; - private int change_count = 0; - private static final int COLLECT_AT = 20000; - private static final int MIN_COLLECT_AT = 100; - - public synchronized Stack getThreadStack() { - if (Thread.currentThread() != cached_thread) { - cached_thread = Thread.currentThread(); - cached_stack = (Stack)stacks.get(cached_thread); - if (cached_stack == null) { - cached_stack = new Stack(); - stacks.put(cached_thread, cached_stack); - } - change_count++; - // 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... - if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { - Stack dead_stacks = new Stack(); - for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) { - Thread t = (Thread)e.nextElement(); - if (!t.isAlive()) dead_stacks.push(t); - } - for (Enumeration e = dead_stacks.elements(); e.hasMoreElements(); ) { - Thread t = (Thread)e.nextElement(); - stacks.remove(t); - } - change_count = 0; - } - } - return cached_stack; - } - - public void removeThreadStack() { - // TODO - } - -} diff --git a/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java deleted file mode 100644 index 0022c03ba..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Method; -import java.util.StringTokenizer; - -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, - Class returnType) - { - super(modifiers, name, declaringType, parameterTypes, parameterNames, - exceptionTypes); - this.returnType = returnType; - } - - AdviceSignatureImpl(String stringRep) { - super(stringRep); - } - /* name is consistent with reflection API - before and after always return Void.TYPE - (some around also return Void.Type) */ - public Class getReturnType() { - if (returnType == null) returnType = extractType(6); - return returnType; - } - - protected String createToString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); -// buf.append(sm.makeModifiersString(getModifiers())); - if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType())); - if (sm.includeArgs) buf.append(" "); - buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); - buf.append("."); - buf.append(toAdviceName(getName())); - sm.addSignature(buf, getParameterTypes()); - sm.addThrows(buf, getExceptionTypes()); - return buf.toString(); - } - - private String toAdviceName(String methodName) { - if (methodName.indexOf('$') == -1) return methodName; - StringTokenizer strTok = new StringTokenizer(methodName,"$"); - while (strTok.hasMoreTokens()) { - String token = strTok.nextToken(); - if ( token.startsWith("before") || - token.startsWith("after") || - token.startsWith("around") ) return token; - } - return methodName; - } - - /* (non-Javadoc) - * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() - */ - public Method getAdvice() { - if (adviceMethod == null) { - try { - adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes()); - } catch (Exception ex) { - ; // nothing we can do, caller will see null - } - } - return adviceMethod; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java deleted file mode 100644 index 6f049a66b..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.reflect.CatchClauseSignature; - -class CatchClauseSignatureImpl extends SignatureImpl implements CatchClauseSignature { - Class parameterType; - String parameterName; - - CatchClauseSignatureImpl(Class declaringType, - Class parameterType, String parameterName) - { - super(0, "catch", declaringType); - this.parameterType = parameterType; - this.parameterName = parameterName; - } - - CatchClauseSignatureImpl(String stringRep) { - super(stringRep); - } - - public Class getParameterType() { - if (parameterType == null) parameterType = extractType(3); - return parameterType; - } - public String getParameterName() { - if (parameterName == null) parameterName = extractString(4); - return parameterName; - } - - protected String createToString(StringMaker sm) { - return "catch(" + sm.makeTypeName(getParameterType()) + ")"; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java deleted file mode 100644 index 74fc462d6..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.reflect.CodeSignature; - -abstract class CodeSignatureImpl extends MemberSignatureImpl implements CodeSignature { - Class[] parameterTypes; - String[] parameterNames; - Class[] exceptionTypes; - - CodeSignatureImpl(int modifiers, String name, Class declaringType, - Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) - { - super(modifiers, name, declaringType); - this.parameterTypes = parameterTypes; - this.parameterNames = parameterNames; - this.exceptionTypes = exceptionTypes; - } - CodeSignatureImpl(String stringRep) { - super(stringRep); - } - - public Class[] getParameterTypes() { - if (parameterTypes == null) parameterTypes = extractTypes(3); - return parameterTypes; - } - public String[] getParameterNames() { - if (parameterNames == null) parameterNames = extractStrings(4); - return parameterNames; - } - public Class[] getExceptionTypes() { - if (exceptionTypes == null) exceptionTypes = extractTypes(5); - return exceptionTypes; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java deleted file mode 100644 index a7f688d58..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -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) - { - super(modifiers, "", declaringType, parameterTypes, parameterNames, exceptionTypes); - } - - ConstructorSignatureImpl(String stringRep) { - super(stringRep); - } - - public String getName() { return ""; } - - protected String createToString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); - buf.append(sm.makeModifiersString(getModifiers())); - buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); - sm.addSignature(buf, getParameterTypes()); - sm.addThrows(buf, getExceptionTypes()); - return buf.toString(); - } - - /* (non-Javadoc) - * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() - */ - public Constructor getConstructor() { - if (constructor == null) { - try { - constructor = getDeclaringType().getDeclaredConstructor(getParameterTypes()); - } catch (Exception ex) { - ; // nothing we can do, caller will see null - } - } - return constructor; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/Factory.java b/runtime/src/org/aspectj/runtime/reflect/Factory.java deleted file mode 100644 index 759a1367b..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/Factory.java +++ /dev/null @@ -1,533 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002-2018 Palo Alto Research Center, Incorporated (PARC), Contributors - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * Alex Vasseur new factory methods for variants of JP - * Abraham Nevado new factory methods for collapsed SJPs - * Andy Clement new factory methods that rely on LDC - * ******************************************************************/ - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.Hashtable; -import java.util.StringTokenizer; - -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; - - private static final Class[] NO_TYPES = new Class[0]; - private static final String[] NO_STRINGS = new String[0]; - - 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(); - } - - - /** - * Create a signature and build a JoinPoint in one step. Prior to 1.6.10 this was done as a two step operation in the generated - * code but merging these methods in the runtime library enables the generated code to be shorter. Generating code that - * uses this method requires the weaver to be invoked with -Xset:targetRuntime1_6_10=true. - * - * @since 1.6.10 - */ - public JoinPoint.StaticPart makeSJP(String kind, String modifiers, String methodName, String declaringType, String paramTypes, - String paramNames, String exceptionTypes, String returnType, int l) { - Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, exceptionTypes, returnType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); - } - - /** - * Create a signature and build a JoinPoint in one step. Prior to 1.6.10 this was done as a two step operation in the generated - * code but merging these methods in the runtime library enables the generated code to be shorter. Generating code that - * uses this method requires the weaver to be invoked with -Xset:targetRuntime1_6_10=true. - *

- * This method differs from the previous one in that it includes no exceptionTypes parameter - it is an optimization for the - * case where there are no exceptions. The generated code won't build an empty string and will not pass it into here. - * - * @since 1.6.10 - */ - public JoinPoint.StaticPart makeSJP(String kind, String modifiers, String methodName, String declaringType, String paramTypes, - String paramNames, String returnType, int l) { - Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, "", returnType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); - } - - // These are direct routes to creating thisJoinPoint and thisEnclosingJoinPoint objects - // added in 1.9.1 - - public JoinPoint.StaticPart makeMethodSJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { - Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, - paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeMethodESJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { - Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, - paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeConstructorSJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { - ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, - exceptionTypes==null?NO_TYPES:exceptionTypes); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeConstructorESJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { - ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, - exceptionTypes==null?NO_TYPES:exceptionTypes); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeCatchClauseSJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { - CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeCatchClauseESJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { - CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeFieldSJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { - FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeFieldESJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { - FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeInitializerSJP(String kind, int modifiers, Class declaringType, int line) { - InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeInitializerESJP(String kind, int modifiers, Class declaringType, int line) { - InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeLockSJP(String kind, Class declaringType, int line) { - LockSignatureImpl sig = new LockSignatureImpl(declaringType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeLockESJP(String kind, Class declaringType, int line) { - LockSignatureImpl sig = new LockSignatureImpl(declaringType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeUnlockSJP(String kind, Class declaringType, int line) { - UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeUnlockESJP(String kind, Class declaringType, int line) { - UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.StaticPart makeAdviceSJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, - String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { - AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, - parameterTypes==null?NO_TYPES:parameterTypes, - parameterNames==null?NO_STRINGS:parameterNames, - exceptionTypes==null?NO_TYPES:exceptionTypes, - returnType==null?Void.TYPE:returnType); - return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - public JoinPoint.EnclosingStaticPart makeAdviceESJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, - String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { - AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, - parameterTypes==null?NO_TYPES:parameterTypes, - parameterNames==null?NO_STRINGS:parameterNames, - exceptionTypes==null?NO_TYPES:exceptionTypes, - returnType==null?Void.TYPE:returnType); - return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); - } - - // --- - - 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) { - 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) { - Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); - return makeMethodSig(modifiers, methodName, declaringTypeClass, paramTypes, paramNames, exceptionTypes, returnType); - } - - public MethodSignature makeMethodSig(String modifiers, String methodName, Class declaringTypeClass, String paramTypes, - String paramNames, String exceptionTypes, String returnType) { - int modifiersAsInt = Integer.parseInt(modifiers, 16); - - 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==null?NO_TYPES:parameterTypes, parameterNames, - exceptionTypes == null?NO_TYPES: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); - - 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); - - 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/FieldSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java deleted file mode 100644 index 8c3de24c4..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -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) - { - super(modifiers, name, declaringType); - this.fieldType = fieldType; - } - - FieldSignatureImpl(String stringRep) { - super(stringRep); - } - - public Class getFieldType() { - if (fieldType == null) fieldType = extractType(3); - return fieldType; - } - - protected String createToString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); - buf.append(sm.makeModifiersString(getModifiers())); - if (sm.includeArgs) buf.append(sm.makeTypeName(getFieldType())); - if (sm.includeArgs) buf.append(" "); - buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); - buf.append("."); - buf.append(getName()); - return buf.toString(); - } - - /* (non-Javadoc) - * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() - */ - public Field getField() { - if (field == null) { - try { - field = getDeclaringType().getDeclaredField(getName()); - } catch (Exception ex) { - ; // nothing we can do, caller will see null - } - } - return field; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java deleted file mode 100644 index adb8f840e..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.reflect.InitializerSignature; - -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) ? "" : "", declaringType, EMPTY_CLASS_ARRAY, - EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY); - } - - InitializerSignatureImpl(String stringRep) { - super(stringRep); - } - - public String getName() { - return Modifier.isStatic(getModifiers()) ? "": ""; - } - - protected String createToString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); - buf.append(sm.makeModifiersString(getModifiers())); - buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); - buf.append("."); - buf.append(getName()); - return buf.toString(); - } - - /* (non-Javadoc) - * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject() - */ - public Constructor getInitializer() { - if (constructor == null) { - try { - constructor = getDeclaringType().getDeclaredConstructor(getParameterTypes()); - } catch (Exception ex) { - ; // nothing we can do, caller will see null - } - } - return constructor; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java deleted file mode 100644 index 69bff1e3c..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.Signature; -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; - 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 - - // This previous variant doesn't seem to cope with only binding target at a joinpoint - // which has both this and target. It forces you to supply this even if you didn't bind - // it. -// firstArgumentIndexIntoAdviceBindings = (hasThis ? 1 : 0) + 1; -// state[hasThis ? 1 : 0] = adviceBindings[hasThis ? 1 : 0]; - - int targetPositionInAdviceBindings = (hasThis && bindsThis) ? 1 : 0; - firstArgumentIndexIntoAdviceBindings = ((hasThis&&bindsThis)?1:0)+((hasTarget&&bindsTarget&&!thisTargetTheSame)?1:0); - state[hasThis ? 1 : 0] = adviceBindings[targetPositionInAdviceBindings]; - } - } 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); - } - } - -} diff --git a/runtime/src/org/aspectj/runtime/reflect/LockSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/LockSignatureImpl.java deleted file mode 100644 index 2448868d0..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/LockSignatureImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation - *******************************************************************************/ - - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Modifier; - -import org.aspectj.lang.reflect.LockSignature; - -class LockSignatureImpl extends SignatureImpl implements LockSignature { - private Class parameterType; - - LockSignatureImpl(Class c) { - super(Modifier.STATIC, "lock", c); - parameterType = c; - } - - LockSignatureImpl(String stringRep) { - super(stringRep); - } - - protected String createToString(StringMaker sm) { - if (parameterType == null) parameterType = extractType(3); - return "lock("+sm.makeTypeName(parameterType)+")"; - } - - public Class getParameterType() { - if (parameterType == null) parameterType = extractType(3); - return parameterType; - } - -} diff --git a/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java deleted file mode 100644 index a7cd77a5f..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.reflect.MemberSignature; - -abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature { - - MemberSignatureImpl(int modifiers, String name, Class declaringType) { - super(modifiers, name, declaringType); - } - - public MemberSignatureImpl(String stringRep) { - super(stringRep); - } - -} diff --git a/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java deleted file mode 100644 index 17416bada..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.Set; - -import org.aspectj.lang.reflect.MethodSignature; - -class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature { - private Method method; - Class returnType; - - MethodSignatureImpl(int modifiers, String name, Class declaringType, Class[] parameterTypes, String[] parameterNames, - Class[] exceptionTypes, Class returnType) { - super(modifiers, name, declaringType, parameterTypes, parameterNames, exceptionTypes); - this.returnType = returnType; - } - - MethodSignatureImpl(String stringRep) { - super(stringRep); - } - - /* name is consistent with reflection API */ - public Class getReturnType() { - if (returnType == null) - returnType = extractType(6); - return returnType; - } - - protected String createToString(StringMaker sm) { - StringBuffer buf = new StringBuffer(); - buf.append(sm.makeModifiersString(getModifiers())); - if (sm.includeArgs) - buf.append(sm.makeTypeName(getReturnType())); - if (sm.includeArgs) - buf.append(" "); - buf.append(sm.makePrimaryTypeName(getDeclaringType(), getDeclaringTypeName())); - buf.append("."); - buf.append(getName()); - sm.addSignature(buf, getParameterTypes()); - sm.addThrows(buf, getExceptionTypes()); - return buf.toString(); - } - - /* - * (non-Javadoc) - * - * @see org.aspectj.lang.reflect.MemberSignature#getAccessibleObject() - */ - public Method getMethod() { - if (method == null) { - Class dtype = getDeclaringType(); - try { - method = dtype.getDeclaredMethod(getName(), getParameterTypes()); - } catch (NoSuchMethodException nsmEx) { - // pr154427 - search - Set searched = new HashSet(); - searched.add(dtype); // avoids another getDeclaredMethod() on dtype - method = search(dtype, getName(), getParameterTypes(), searched); - } - } - return method; - } - - /** - * Hunt for a method up the hierarchy for a specified type. - * - * @param type the type on which to look for the method - * @param name the name of the method - * @param params the parameters of the method - * @param searched a set of types already searched to avoid looking at anything twice - * @return the method if found, or null if not found - */ - private Method search(Class type, String name, Class[] params, Set searched) { - if (type == null) { - return null; - } - if (!searched.contains(type)) { - searched.add(type); - try { - return type.getDeclaredMethod(name, params); - } catch (NoSuchMethodException nsme) { - // drop through and check superclass and interfaces - } - } - Method m = search(type.getSuperclass(), name, params, searched); - if (m != null) { - return m; - } - Class[] superinterfaces = type.getInterfaces(); - if (superinterfaces != null) { - for (int i = 0; i < superinterfaces.length; i++) { - m = search(superinterfaces[i], name, params, searched); - if (m != null) { - return m; - } - } - } - return null; - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java deleted file mode 100644 index 68079b444..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java +++ /dev/null @@ -1,243 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.Signature; - -import java.util.StringTokenizer; - -abstract class SignatureImpl implements Signature { - - private static boolean useCache = true; - - int modifiers = -1; - String name; - String declaringTypeName; - Class declaringType; - Cache stringCache; - - SignatureImpl(int modifiers, String name, Class declaringType) { - this.modifiers = modifiers; - this.name = name; - this.declaringType = declaringType; - } - - protected abstract String createToString (StringMaker sm); - - /* Use a soft cache for the short, middle and long String representations */ - String toString (StringMaker sm) { - String result = null; - if (useCache) { - if (stringCache == null) { - try { - stringCache = new CacheImpl(); - } catch (Throwable t) { - useCache = false; - } - } else { - result = stringCache.get(sm.cacheOffset); - } - } - if (result == null) { - result = createToString(sm); - } - if (useCache) { - stringCache.set(sm.cacheOffset, result); - } - return result; - } - - public final String toString() { return toString(StringMaker.middleStringMaker); } - public final String toShortString() { return toString(StringMaker.shortStringMaker); } - public final String toLongString() { return toString(StringMaker.longStringMaker); } - - public int getModifiers() { - if (modifiers == -1) modifiers = extractInt(0); - return modifiers; - } - public String getName() { - if (name == null) name = extractString(1); - return name; - } - public Class getDeclaringType() { - if (declaringType == null) declaringType = extractType(2); - return declaringType; - } - public String getDeclaringTypeName() { - if (declaringTypeName == null) { - declaringTypeName = getDeclaringType().getName(); - } - return declaringTypeName; - } - - String fullTypeName(Class type) { - if (type == null) return "ANONYMOUS"; - if (type.isArray()) return fullTypeName(type.getComponentType()) + "[]"; - return type.getName().replace('$', '.'); - } - - String stripPackageName(String name) { - int dot = name.lastIndexOf('.'); - if (dot == -1) return name; - return name.substring(dot+1); - } - - String shortTypeName(Class type) { - if (type == null) return "ANONYMOUS"; - if (type.isArray()) return shortTypeName(type.getComponentType()) + "[]"; - return stripPackageName(type.getName()).replace('$', '.'); - } - - void addFullTypeNames(StringBuffer buf, Class[] types) { - for (int i = 0; i < types.length; i++) { - if (i > 0) buf.append(", "); - buf.append(fullTypeName(types[i])); - } - } - void addShortTypeNames(StringBuffer buf, Class[] types) { - for (int i = 0; i < types.length; i++) { - if (i > 0) buf.append(", "); - buf.append(shortTypeName(types[i])); - } - } - - void addTypeArray(StringBuffer buf, Class[] types) { - addFullTypeNames(buf, types); - } - - // lazy version - private String stringRep; - ClassLoader lookupClassLoader = null; - - public void setLookupClassLoader(ClassLoader loader) { - this.lookupClassLoader = loader; - } - - private ClassLoader getLookupClassLoader() { - if (lookupClassLoader == null) lookupClassLoader = this.getClass().getClassLoader(); - return lookupClassLoader; - } - - public SignatureImpl(String stringRep) { - this.stringRep = stringRep; - } - - static final char SEP = '-'; - - String extractString(int n) { - //System.out.println(n + ": from " + stringRep); - - int startIndex = 0; - int endIndex = stringRep.indexOf(SEP); - while (n-- > 0) { - startIndex = endIndex+1; - endIndex = stringRep.indexOf(SEP, startIndex); - } - if (endIndex == -1) endIndex = stringRep.length(); - - //System.out.println(" " + stringRep.substring(startIndex, endIndex)); - - return stringRep.substring(startIndex, endIndex); - } - - int extractInt(int n) { - String s = extractString(n); - return Integer.parseInt(s, 16); - } - - Class extractType(int n) { - String s = extractString(n); - return Factory.makeClass(s,getLookupClassLoader()); - } - - - - static String[] EMPTY_STRING_ARRAY = new String[0]; - static Class[] EMPTY_CLASS_ARRAY = new Class[0]; - - static final String INNER_SEP = ":"; - - String[] extractStrings(int n) { - String s = extractString(n); - StringTokenizer st = new StringTokenizer(s, INNER_SEP); - final int N = st.countTokens(); - String[] ret = new String[N]; - for (int i = 0; i < N; i++) ret[i]= st.nextToken(); - return ret; - } - Class[] extractTypes(int n) { - String s = extractString(n); - StringTokenizer st = new StringTokenizer(s, INNER_SEP); - final int N = st.countTokens(); - Class[] ret = new Class[N]; - for (int i = 0; i < N; i++) ret[i]= Factory.makeClass(st.nextToken(),getLookupClassLoader()); - return ret; - } - - /* - * Used for testing - */ - static void setUseCache (boolean b) { - useCache = b; - } - - static boolean getUseCache () { - return useCache; - } - - private static interface Cache { - - String get(int cacheOffset); - - void set(int cacheOffset, String result); - - } - - // separate implementation so we don't need SoftReference to hold the field... - private static final class CacheImpl implements Cache { - private java.lang.ref.SoftReference toStringCacheRef; - - public CacheImpl() { - makeCache(); - } - - public String get(int cacheOffset) { - String[] cachedArray = array(); - if (cachedArray == null) { - return null; - } - return cachedArray[cacheOffset]; - } - - public void set(int cacheOffset, String result) { - String[] cachedArray = array(); - if (cachedArray == null) { - cachedArray = makeCache(); - } - cachedArray[cacheOffset] = result; - } - - private String[] array() { - return (String[]) toStringCacheRef.get(); - } - - private String[] makeCache() { - String[] array = new String[3]; - toStringCacheRef = new java.lang.ref.SoftReference(array); - return array; - } - - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java b/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java deleted file mode 100644 index 91fc1c321..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import org.aspectj.lang.reflect.SourceLocation; - -class SourceLocationImpl implements SourceLocation { - Class withinType; - String fileName; - int line; - - SourceLocationImpl(Class withinType, String fileName, int line) { - this.withinType = withinType; - this.fileName = fileName; - this.line = line; - } - - public Class getWithinType() { return withinType; } - public String getFileName() { return fileName; } - public int getLine() { return line; } - public int getColumn() { return -1; } - - public String toString() { - return getFileName() + ":" + getLine(); - } -} - diff --git a/runtime/src/org/aspectj/runtime/reflect/StringMaker.java b/runtime/src/org/aspectj/runtime/reflect/StringMaker.java deleted file mode 100644 index 53e3988a9..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/StringMaker.java +++ /dev/null @@ -1,140 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Modifier; - -class StringMaker { - boolean shortTypeNames = true; - boolean includeArgs = true; - boolean includeThrows = false; - boolean includeModifiers = false; - boolean shortPrimaryTypeNames = false; - - boolean includeJoinPointTypeName = true; - boolean includeEnclosingPoint = true; - boolean shortKindName = true; - int cacheOffset; - - static StringMaker shortStringMaker; - static { - shortStringMaker = new StringMaker(); - shortStringMaker.shortTypeNames = true; - shortStringMaker.includeArgs = false; - shortStringMaker.includeThrows = false; - shortStringMaker.includeModifiers = false; - shortStringMaker.shortPrimaryTypeNames = true; - - shortStringMaker.includeJoinPointTypeName = false; - shortStringMaker.includeEnclosingPoint = false; - - shortStringMaker.cacheOffset = 0; - } - - static StringMaker middleStringMaker; - static { - middleStringMaker = new StringMaker(); - middleStringMaker.shortTypeNames = true; - middleStringMaker.includeArgs = true; - middleStringMaker.includeThrows = false; - middleStringMaker.includeModifiers = false; - middleStringMaker.shortPrimaryTypeNames = false; - - shortStringMaker.cacheOffset = 1; - } - - static StringMaker longStringMaker; - static { - longStringMaker = new StringMaker(); - longStringMaker.shortTypeNames = false; - longStringMaker.includeArgs = true; - longStringMaker.includeThrows = false; - longStringMaker.includeModifiers = true; - longStringMaker.shortPrimaryTypeNames = false; - longStringMaker.shortKindName = false; - - longStringMaker.cacheOffset = 2; - } - - String makeKindName(String name) { - int dash = name.lastIndexOf('-'); - if (dash == -1) return name; - return name.substring(dash+1); - } - - String makeModifiersString(int modifiers) { - if (!includeModifiers) return ""; - String str = Modifier.toString(modifiers); - if (str.length() == 0) return ""; - return str + " "; - } - - String stripPackageName(String name) { - int dot = name.lastIndexOf('.'); - if (dot == -1) return name; - return name.substring(dot+1); - } - - String makeTypeName(Class type, String typeName, boolean shortName) { - if (type == null) return "ANONYMOUS"; - if (type.isArray()) { - Class componentType = type.getComponentType(); - return makeTypeName(componentType, componentType.getName(), shortName) + "[]"; - } - if (shortName) { - return stripPackageName(typeName).replace('$', '.'); - } else { - return typeName.replace('$', '.'); - } - } - - public String makeTypeName(Class type) { - return makeTypeName(type, type.getName(),shortTypeNames); - } - - public String makePrimaryTypeName(Class type, String typeName) { - return makeTypeName(type, typeName, shortPrimaryTypeNames); - } - - public void addTypeNames(StringBuffer buf, Class[] types) { - for (int i = 0; i < types.length; i++) { - if (i > 0) buf.append(", "); - buf.append(makeTypeName(types[i])); - } - } - - public void addSignature(StringBuffer buf, Class[] types) { - if (types == null) return; - if (!includeArgs) { - if (types.length == 0) { - buf.append("()"); - return; - } else { - buf.append("(..)"); - return; - } - } - buf.append("("); - addTypeNames(buf, types); - buf.append(")"); - } - - public void addThrows(StringBuffer buf, Class[] types) { - if (!includeThrows || types == null || types.length == 0) return; - - buf.append(" throws "); - addTypeNames(buf, types); - } -} diff --git a/runtime/src/org/aspectj/runtime/reflect/UnlockSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/UnlockSignatureImpl.java deleted file mode 100644 index d8b377a6f..000000000 --- a/runtime/src/org/aspectj/runtime/reflect/UnlockSignatureImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andy Clement - initial implementation - *******************************************************************************/ - - -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Modifier; - -import org.aspectj.lang.reflect.UnlockSignature; - -class UnlockSignatureImpl extends SignatureImpl implements UnlockSignature { - private Class parameterType; - - UnlockSignatureImpl(Class c) { - super(Modifier.STATIC, "unlock", c); - parameterType = c; - } - - UnlockSignatureImpl(String stringRep) { - super(stringRep); - } - - protected String createToString(StringMaker sm) { - if (parameterType == null) parameterType = extractType(3); - return "unlock("+sm.makeTypeName(parameterType)+")"; - } - - public Class getParameterType() { - if (parameterType == null) parameterType = extractType(3); - return parameterType; - } -} diff --git a/runtime/src/test/java/org/aspectj/runtime/RuntimeModuleTest.java b/runtime/src/test/java/org/aspectj/runtime/RuntimeModuleTest.java new file mode 100644 index 000000000..97e1750d8 --- /dev/null +++ b/runtime/src/test/java/org/aspectj/runtime/RuntimeModuleTest.java @@ -0,0 +1,77 @@ +package org.aspectj.runtime; +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +import java.io.*; + +import org.aspectj.lang.*; +import org.aspectj.runtime.reflect.JoinPointImplTest; +import org.aspectj.runtime.reflect.RuntimePerformanceTest; +import org.aspectj.runtime.reflect.SignatureTest; + +import junit.framework.*; + +public class RuntimeModuleTest extends TestCase { + + public RuntimeModuleTest(String name) { super(name); } + + public void testNoAspectBoundException() { + RuntimeException fun = new RuntimeException("fun"); + NoAspectBoundException nab = new NoAspectBoundException("Foo", fun); + assertEquals(fun,nab.getCause()); + } + + public void testSoftExceptionPrintStackTrace() { + // let's see +// Throwable t = new Error("xyz"); +// new SoftException(t).printStackTrace(); + + // save to specified PrintStream + ByteArrayOutputStream sink = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(sink); + new SoftException(new Error("xyz")).printStackTrace(out); + String s = new String(sink.toByteArray()); + out.flush(); + checkSoftExceptionString(s); + + // save to specified PrintWriter + sink = new ByteArrayOutputStream(); + PrintWriter pout = new PrintWriter(sink); + new SoftException(new Error("xyz")).printStackTrace(pout); + pout.flush(); + s = new String(sink.toByteArray()); + checkSoftExceptionString(s); + + // check System.err redirect + PrintStream systemErr = System.err; + try { + sink = new ByteArrayOutputStream(); + out = new PrintStream(sink); + System.setErr(out); + new SoftException(new Error("xyz")).printStackTrace(); + out.flush(); + s = new String(sink.toByteArray()); + checkSoftExceptionString(s); + } finally { + System.setErr(systemErr); + } + } + + + static void checkSoftExceptionString(String s) { + assertTrue(-1 != s.indexOf("SoftException")); + assertTrue(-1 != s.indexOf("Caused by: java.lang.Error")); + assertTrue(-1 != s.indexOf("xyz")); + assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace")); + } +} diff --git a/runtime/src/test/java/org/aspectj/runtime/reflect/JoinPointImplTest.java b/runtime/src/test/java/org/aspectj/runtime/reflect/JoinPointImplTest.java new file mode 100644 index 000000000..2a17ad998 --- /dev/null +++ b/runtime/src/test/java/org/aspectj/runtime/reflect/JoinPointImplTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.aspectj.runtime.reflect; + +import junit.framework.TestCase; + +/** + * @author colyer + * + */ +public class JoinPointImplTest extends TestCase { + + public void testGetArgs() { + String arg1 = "abc"; + StringBuffer arg2 = new StringBuffer("def"); + Object arg3 = new Object(); + Object[] args = new Object[] { arg1, arg2, arg3 }; + JoinPointImpl jpi = new JoinPointImpl(null,null,null,args); + + Object[] retrievedArgs = jpi.getArgs(); + assertEquals("First arg unchanged",arg1,retrievedArgs[0]); + assertEquals("Second arg unchanged",arg2,retrievedArgs[1]); + assertEquals("Third arg unchanged",arg3,retrievedArgs[2]); + retrievedArgs[0] = "xyz"; + ((StringBuffer)retrievedArgs[1]).append("ghi"); + retrievedArgs[2] = "jkl"; + Object[] afterUpdateArgs = jpi.getArgs(); + assertEquals("Object reference not changed",arg1,afterUpdateArgs[0]); + assertEquals("Object reference unchanged",arg2,afterUpdateArgs[1]); + assertEquals("state of referenced object updated","defghi",afterUpdateArgs[1].toString()); + assertEquals("Object reference not changed",arg3,afterUpdateArgs[2]); + } + +} diff --git a/runtime/src/test/java/org/aspectj/runtime/reflect/RuntimePerformanceTest.java b/runtime/src/test/java/org/aspectj/runtime/reflect/RuntimePerformanceTest.java new file mode 100644 index 000000000..25959aebc --- /dev/null +++ b/runtime/src/test/java/org/aspectj/runtime/reflect/RuntimePerformanceTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.runtime.reflect; + +import java.lang.reflect.Method; +import java.util.Timer; +import java.util.TimerTask; + +import org.aspectj.lang.Signature; + +import junit.framework.TestCase; + +public class RuntimePerformanceTest extends TestCase { + + private static final Timer timer = new Timer(true); + private static final long TIMEOUT = 10000; + private static final long ITERATIONS = 1000000; + private static final long WARMUP_ITERATIONS = 10000; + private static final long EXPECTED_RATIO = 8; + private static final Factory factory = new Factory("RutimePerformanceTest.java",RuntimePerformanceTest.class); + + private boolean savedUseCaches; + private Method method; + private Signature signature; + + private TimerTask task; + private boolean abort; + + public RuntimePerformanceTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + + /* Save default state */ + savedUseCaches = SignatureImpl.getUseCache(); + + /* If a test takes too long we can kill it and fail */ + abort = false; + task = new TimerTask() { + public void run () { + abort = true; + } + }; + timer.schedule(task,TIMEOUT); + } + + protected void tearDown() throws Exception { + super.tearDown(); + + /* Restore default state */ + SignatureImpl.setUseCache(savedUseCaches); + + task.cancel(); + } + + public void testToString () { + Signature signature = makeMethodSig("test"); + + SignatureImpl.setUseCache(false); + warmUp(signature); + long noCache = invokeSignatureToString(signature,ITERATIONS/EXPECTED_RATIO); + System.out.println("noCache=" + noCache); + + SignatureImpl.setUseCache(true); + warmUp(signature); + long cache = invokeSignatureToString(signature,ITERATIONS); + System.out.println("cache=" + cache); + + long ratio = (EXPECTED_RATIO*noCache/cache); + System.out.println("ratio=" + ratio); + assertTrue("Using cache should be " + EXPECTED_RATIO + " times faster: " + ratio,(ratio >= EXPECTED_RATIO)); + } + + private long invokeSignatureToString (Signature sig, long iterations) { + long start = System.currentTimeMillis(); + String s; + + for (long l = 0; !abort && (l < iterations); l++) { + s = sig.toShortString(); + s = sig.toString(); + s = sig.toLongString(); + } + if (abort) throw new RuntimeException("invokeSignatureToString aborted after " + (TIMEOUT/1000) + " seconds"); + + long finish = System.currentTimeMillis(); + return (finish-start); + } + + private void warmUp (Signature sig) { + invokeSignatureToString(sig,WARMUP_ITERATIONS); + } + + private Signature makeMethodSig (String methodName) { + Class clazz = getClass(); + Class[] parameterTypes = new Class[] { String.class }; + String[] parameterNames = new String[] { "s" }; + Class[] exceptionTypes = new Class[] {}; + Class returnType = Void.TYPE; + return factory.makeMethodSig(1,methodName,clazz,parameterTypes,parameterNames,exceptionTypes,returnType); + } +} \ No newline at end of file diff --git a/runtime/src/test/java/org/aspectj/runtime/reflect/SignatureTest.java b/runtime/src/test/java/org/aspectj/runtime/reflect/SignatureTest.java new file mode 100644 index 000000000..7a66a5b39 --- /dev/null +++ b/runtime/src/test/java/org/aspectj/runtime/reflect/SignatureTest.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.aspectj.runtime.reflect; + +import java.lang.ref.Reference; +import java.lang.reflect.Field; + +import junit.framework.TestCase; + +/** + */ +public class SignatureTest extends TestCase { + public void testGetDeclaringTypeName() { + FieldSignatureImpl fsi = new FieldSignatureImpl(0,"x",SignatureTest.class,String.class); + assertEquals(SignatureTest.class.getName(),fsi.getDeclaringTypeName()); + assertSame(fsi.getDeclaringTypeName(),fsi.getDeclaringTypeName()); // should be cached. + } + + public void testToShortMiddleLongString () { + MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); + String shortString = msi.toShortString(); + assertSame(shortString,msi.toShortString()); // should be cached. + String middleString = msi.toString(); + assertSame(middleString,msi.toString()); // should be cached. + String longString = msi.toLongString(); + assertSame(longString,msi.toLongString()); // should be cached. + assertTrue("String representations should be different",!(shortString.equals(middleString) || middleString.equals(longString) || longString.equals(shortString))); + } + + public void testClearCache() throws Exception { + MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); + String shortString = msi.toShortString(); + assertSame(shortString,msi.toShortString()); + + Field field = SignatureImpl.class.getDeclaredField("stringCache"); + field.setAccessible(true); + Object res = field.get(msi); + + field = res.getClass().getDeclaredField("toStringCacheRef"); + field.setAccessible(true); + Reference ref = (Reference)field.get(res); + + ref.clear(); + assertEquals(shortString,msi.toShortString()); + + String longString = msi.toLongString(); + assertSame(longString,msi.toLongString()); // should be cached. + } +} diff --git a/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java b/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java deleted file mode 100644 index c9bfe88b9..000000000 --- a/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.runtime; -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - -import java.io.*; - -import org.aspectj.lang.*; -import org.aspectj.runtime.reflect.JoinPointImplTest; -import org.aspectj.runtime.reflect.RuntimePerformanceTest; -import org.aspectj.runtime.reflect.SignatureTest; - -import junit.framework.*; - -public class RuntimeModuleTests extends TestCase { - - public static TestSuite suite() { - TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName()); - suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing) - suite.addTestSuite(SignatureTest.class); - suite.addTestSuite(JoinPointImplTest.class); - suite.addTestSuite(RuntimePerformanceTest.class); - return suite; - } - - public RuntimeModuleTests(String name) { super(name); } - - public void testNoAspectBoundException() { - RuntimeException fun = new RuntimeException("fun"); - NoAspectBoundException nab = new NoAspectBoundException("Foo", fun); - assertEquals(fun,nab.getCause()); - } - - public void testSoftExceptionPrintStackTrace() { - // let's see -// Throwable t = new Error("xyz"); -// new SoftException(t).printStackTrace(); - - // save to specified PrintStream - ByteArrayOutputStream sink = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(sink); - new SoftException(new Error("xyz")).printStackTrace(out); - String s = new String(sink.toByteArray()); - out.flush(); - checkSoftExceptionString(s); - - // save to specified PrintWriter - sink = new ByteArrayOutputStream(); - PrintWriter pout = new PrintWriter(sink); - new SoftException(new Error("xyz")).printStackTrace(pout); - pout.flush(); - s = new String(sink.toByteArray()); - checkSoftExceptionString(s); - - // check System.err redirect - PrintStream systemErr = System.err; - try { - sink = new ByteArrayOutputStream(); - out = new PrintStream(sink); - System.setErr(out); - new SoftException(new Error("xyz")).printStackTrace(); - out.flush(); - s = new String(sink.toByteArray()); - checkSoftExceptionString(s); - } finally { - System.setErr(systemErr); - } - } - - - static void checkSoftExceptionString(String s) { - assertTrue(-1 != s.indexOf("SoftException")); - assertTrue(-1 != s.indexOf("Caused by: java.lang.Error")); - assertTrue(-1 != s.indexOf("xyz")); - assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace")); - } -} diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java deleted file mode 100644 index 2a17ad998..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import junit.framework.TestCase; - -/** - * @author colyer - * - */ -public class JoinPointImplTest extends TestCase { - - public void testGetArgs() { - String arg1 = "abc"; - StringBuffer arg2 = new StringBuffer("def"); - Object arg3 = new Object(); - Object[] args = new Object[] { arg1, arg2, arg3 }; - JoinPointImpl jpi = new JoinPointImpl(null,null,null,args); - - Object[] retrievedArgs = jpi.getArgs(); - assertEquals("First arg unchanged",arg1,retrievedArgs[0]); - assertEquals("Second arg unchanged",arg2,retrievedArgs[1]); - assertEquals("Third arg unchanged",arg3,retrievedArgs[2]); - retrievedArgs[0] = "xyz"; - ((StringBuffer)retrievedArgs[1]).append("ghi"); - retrievedArgs[2] = "jkl"; - Object[] afterUpdateArgs = jpi.getArgs(); - assertEquals("Object reference not changed",arg1,afterUpdateArgs[0]); - assertEquals("Object reference unchanged",arg2,afterUpdateArgs[1]); - assertEquals("state of referenced object updated","defghi",afterUpdateArgs[1].toString()); - assertEquals("Object reference not changed",arg3,afterUpdateArgs[2]); - } - -} diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java deleted file mode 100644 index 25959aebc..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Method; -import java.util.Timer; -import java.util.TimerTask; - -import org.aspectj.lang.Signature; - -import junit.framework.TestCase; - -public class RuntimePerformanceTest extends TestCase { - - private static final Timer timer = new Timer(true); - private static final long TIMEOUT = 10000; - private static final long ITERATIONS = 1000000; - private static final long WARMUP_ITERATIONS = 10000; - private static final long EXPECTED_RATIO = 8; - private static final Factory factory = new Factory("RutimePerformanceTest.java",RuntimePerformanceTest.class); - - private boolean savedUseCaches; - private Method method; - private Signature signature; - - private TimerTask task; - private boolean abort; - - public RuntimePerformanceTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - super.setUp(); - - /* Save default state */ - savedUseCaches = SignatureImpl.getUseCache(); - - /* If a test takes too long we can kill it and fail */ - abort = false; - task = new TimerTask() { - public void run () { - abort = true; - } - }; - timer.schedule(task,TIMEOUT); - } - - protected void tearDown() throws Exception { - super.tearDown(); - - /* Restore default state */ - SignatureImpl.setUseCache(savedUseCaches); - - task.cancel(); - } - - public void testToString () { - Signature signature = makeMethodSig("test"); - - SignatureImpl.setUseCache(false); - warmUp(signature); - long noCache = invokeSignatureToString(signature,ITERATIONS/EXPECTED_RATIO); - System.out.println("noCache=" + noCache); - - SignatureImpl.setUseCache(true); - warmUp(signature); - long cache = invokeSignatureToString(signature,ITERATIONS); - System.out.println("cache=" + cache); - - long ratio = (EXPECTED_RATIO*noCache/cache); - System.out.println("ratio=" + ratio); - assertTrue("Using cache should be " + EXPECTED_RATIO + " times faster: " + ratio,(ratio >= EXPECTED_RATIO)); - } - - private long invokeSignatureToString (Signature sig, long iterations) { - long start = System.currentTimeMillis(); - String s; - - for (long l = 0; !abort && (l < iterations); l++) { - s = sig.toShortString(); - s = sig.toString(); - s = sig.toLongString(); - } - if (abort) throw new RuntimeException("invokeSignatureToString aborted after " + (TIMEOUT/1000) + " seconds"); - - long finish = System.currentTimeMillis(); - return (finish-start); - } - - private void warmUp (Signature sig) { - invokeSignatureToString(sig,WARMUP_ITERATIONS); - } - - private Signature makeMethodSig (String methodName) { - Class clazz = getClass(); - Class[] parameterTypes = new Class[] { String.class }; - String[] parameterNames = new String[] { "s" }; - Class[] exceptionTypes = new Class[] {}; - Class returnType = Void.TYPE; - return factory.makeMethodSig(1,methodName,clazz,parameterTypes,parameterNames,exceptionTypes,returnType); - } -} \ No newline at end of file diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java deleted file mode 100644 index 7a66a5b39..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import java.lang.ref.Reference; -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -/** - */ -public class SignatureTest extends TestCase { - public void testGetDeclaringTypeName() { - FieldSignatureImpl fsi = new FieldSignatureImpl(0,"x",SignatureTest.class,String.class); - assertEquals(SignatureTest.class.getName(),fsi.getDeclaringTypeName()); - assertSame(fsi.getDeclaringTypeName(),fsi.getDeclaringTypeName()); // should be cached. - } - - public void testToShortMiddleLongString () { - MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); - String shortString = msi.toShortString(); - assertSame(shortString,msi.toShortString()); // should be cached. - String middleString = msi.toString(); - assertSame(middleString,msi.toString()); // should be cached. - String longString = msi.toLongString(); - assertSame(longString,msi.toLongString()); // should be cached. - assertTrue("String representations should be different",!(shortString.equals(middleString) || middleString.equals(longString) || longString.equals(shortString))); - } - - public void testClearCache() throws Exception { - MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); - String shortString = msi.toShortString(); - assertSame(shortString,msi.toShortString()); - - Field field = SignatureImpl.class.getDeclaredField("stringCache"); - field.setAccessible(true); - Object res = field.get(msi); - - field = res.getClass().getDeclaredField("toStringCacheRef"); - field.setAccessible(true); - Reference ref = (Reference)field.get(res); - - ref.clear(); - assertEquals(shortString,msi.toShortString()); - - String longString = msi.toLongString(); - assertSame(longString,msi.toLongString()); // should be cached. - } -}