+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="testsrc"/>
- <classpathentry kind="lib" path="/lib/junit/junit.jar" sourcepath="/lib/junit/junit-src.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+++ /dev/null
-bin
-ant.properties
-runtime.mf.txt
-bintest
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>runtime</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-<?xml version="1.0"?>
-<!-- see ../build/*.html for explanation -->
-<project name="runtime" default="test" basedir=".">
- <import file="${basedir}/../build/build.xml"/>
-</project>
-
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectj-parent</artifactId>
+ <version>1.9.3.BUILD-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>runtime</artifactId>
+ <packaging>jar</packaging>
+ <name>runtime</name>
+
+</project>
--- /dev/null
+/*******************************************************************************
+ * 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.
+ * <p/>
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+
+/**
+ * <p>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 <code>thisJoinPoint</code>. The primary
+ * use of this reflective information is for tracing and logging applications.
+ * </p>
+ *
+ * <pre>
+ * 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());
+ * }
+ * }
+ * </pre>
+ */
+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();
+
+ /**
+ * <p> Returns the currently executing object. This will always be
+ * the same object as that matched by the <code>this</code> pointcut
+ * designator. Unless you specifically need this reflective access,
+ * you should use the <code>this</code> pointcut designator to
+ * get at this object for better static typing and performance.</p>
+ *
+ * <p> Returns null when there is no currently executing object available.
+ * This includes all join points that occur in a static context.</p>
+ */
+ Object getThis();
+
+ /**
+ * <p> Returns the target object. This will always be
+ * the same object as that matched by the <code>target</code> pointcut
+ * designator. Unless you specifically need this reflective access,
+ * you should use the <code>target</code> pointcut designator to
+ * get at this object for better static typing and performance.</p>
+ *
+ * <p> Returns null when there is no target object.</p>
+
+ */
+ Object getTarget();
+
+ /**
+ * <p>Returns the arguments at this join point.</p>
+ */
+ Object[] getArgs();
+
+ /** Returns the signature at the join point.
+ *
+ * <code>getStaticPart().getSignature()</code> returns the same object
+ */
+ Signature getSignature();
+
+ /** <p>Returns the source location corresponding to the join point.</p>
+ *
+ * <p>If there is no source location available, returns null.</p>
+ *
+ * <p>Returns the SourceLocation of the defining class for default constructors.</p>
+ *
+ * <p> <code>getStaticPart().getSourceLocation()</code> returns the same object. </p>
+ */
+ SourceLocation getSourceLocation();
+
+ /** Returns a String representing the kind of join point. This
+ * String is guaranteed to be
+ * interned. <code>getStaticPart().getKind()</code> returns
+ * the same object.
+ */
+ String getKind();
+
+ /**
+ * <p>This helper object contains only the static information about a join point.
+ * It is available from the <code>JoinPoint.getStaticPart()</code> method, and
+ * can be accessed separately within advice using the special form
+ * <code>thisJoinPointStaticPart</code>.</p>
+ *
+ * <p>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.</p>
+ *
+ * <pre>
+ * public class LoggingUtils {
+ * public static void prettyPrint(JoinPoint.StaticPart jp) {
+ * ...
+ * }
+ * }
+ *
+ * aspect Logging {
+ * before(): ... { LoggingUtils.prettyPrint(thisJoinPointStaticPart); }
+ * }
+ * </pre>
+ *
+ * @see JoinPoint#getStaticPart()
+ */
+ public interface StaticPart {
+ /** Returns the signature at the join point. */
+ Signature getSignature();
+
+ /** <p>Returns the source location corresponding to the join point.</p>
+ *
+ * <p>If there is no source location available, returns null.</p>
+ *
+ * <p>Returns the SourceLocation of the defining class for default constructors.</p>
+ */
+ SourceLocation getSourceLocation();
+
+ /** <p> Returns a String representing the kind of join point. This String
+ * is guaranteed to be interned</p>
+ */
+ String getKind();
+
+ /**
+ * Return the id for this JoinPoint.StaticPart. All JoinPoint.StaticPart
+ * instances are assigned an id number upon creation. For each advised type
+ * the id numbers start at 0.
+ * <br>
+ * The id is guaranteed to remain constant across repeated executions
+ * of a program but may change if the code is recompiled.
+ * <br>
+ * The benefit of having an id is that it can be used for array index
+ * purposes which can be quicker than using the JoinPoint.StaticPart
+ * object itself in a map lookup.
+ * <br>
+ * Since two JoinPoint.StaticPart instances in different advised types may have
+ * the same id, then if the id is being used to index some joinpoint specific
+ * state then that state must be maintained on a pertype basis - either by
+ * using pertypewithin() or an ITD.
+ *
+ * @return the id of this joinpoint
+ */
+ int getId();
+
+ String toString();
+
+ /**
+ * 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";
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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 <code>aspectOf</code> 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; }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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 <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public interface ProceedingJoinPoint extends JoinPoint {
+
+ /**
+ * The joinpoint needs to know about its closure so that proceed can delegate to closure.run()
+ * <p/>
+ * 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
+ * <p/>
+ * <p>Unlike code style, proceed(..) in annotation style places different requirements on the
+ * parameters passed to it. The proceed(..) call takes, in this order:
+ * <ul>
+ * <li> If 'this()' was used in the pointcut for binding, it must be passed first in proceed(..).
+ * <li> 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.
+ * <li> 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.
+ * </ul>
+ * <p>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.
+ * </p>
+ *
+ * @param args
+ * @return
+ * @throws Throwable
+ */
+ public Object proceed(Object[] args) throws Throwable;
+
+}
+
+
--- /dev/null
+/* *******************************************************************
+ * 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;
+
+/** <p>Represents the signature at a join point. This interface parallels
+ * <code>java.lang.reflect.Member</code>. </p>
+ *
+ * <p>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 <code>java.util.logging</code> API</p>
+ * <pre>
+ * aspect Logging {
+ * Logger logger = Logger.getLogger("MethodEntries");
+ *
+ * before(): within(com.bigboxco..*) && execution(public * *(..)) {
+ * Signature sig = thisJoinPoint.getSignature();
+ * logger.entering(sig.getDeclaringType().getName(),
+ * sig.getName());
+ * }
+ * }
+ * </pre>
+ *
+ *
+ * <p>More detailed information about a specific kind of signature can
+ * be obtained by casting this <code>Signature</code> object into one
+ * of its more specific sub-types available in
+ * <code>org.aspectj.lang.reflect</code>.
+ *
+ * @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
+ * <code>java.lang.reflect.Modifier</code> to manipulate this, i.e.
+ * <pre>
+ * // check if this signature is public
+ * java.lang.reflect.Modifier.isPublic(sig.getModifiers());
+ *
+ * // print out the modifiers
+ * java.lang.reflect.Modifier.toString(sig.getModifiers());
+ * </pre>
+ *
+ * @see java.lang.reflect.Member#getModifiers
+ * @see java.lang.reflect.Modifier
+ */
+ int getModifiers();
+
+ /**
+ * <p>Returns a <code>java.lang.Class</code> 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
+ * <code>SourceLocation.getWithinType()</code> to get the type in
+ * which the declaration occurs lexically.</p>
+ * <p>For consistency with <code>java.lang.reflect.Member</code>, this
+ * method should have been named <code>getDeclaringClass()</code>.</p>
+ *
+ * @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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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 <code>declare soft: TypePattern: Pointcut</code>.
+ * At the join points, any exceptions thrown which match
+ * TypePattern will be wrapped in <code>SoftException</code>
+ * and rethrown. You can get the original exception using
+ * <code>getWrappedThrowable()</code> or
+ * <code>getCause()</code>.
+ */
+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);
+ }
+ }
+}
--- /dev/null
+<html>
+<body>
+Provides several interfaces for obtaining reflective information about a
+join point, as well as several exceptions that can be thrown by AspectJ
+code.
+<p>
+<code>JoinPoint</code> and <code>Signature</code> provide reflective
+information about a join point. Instances of these interfaces are
+available inside of <code>advice</code> with the special variables
+<code>thisJoinPoint</code>, <code>thisJoinPointStaticPart</code>, and
+<code>thisEnclosingJoinPointStaticPart</code>.</p>
+
+</body>
+</html>
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/*******************************************************************************
+ * 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 {
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+}
+
--- /dev/null
+/*******************************************************************************
+ * 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 {
+
+}
--- /dev/null
+<html>
+<body>
+<p>Contains interfaces that extend <code>Signature</code> 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.</p>
+<pre>
+ before(): call(* *(..)) {
+ MethodSignature sig = (MethodSignature)thisJoinPoint.getSignature();
+ ...
+ }
+</pre>
+
+<p>This package also contains <code>SourceLocation</code> that provides
+information about the location in source code that corresponds to a
+particular join point.</p>
+</body>
+</html>
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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];
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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);
+// }
+}
--- /dev/null
+/* *******************************************************************
+ * 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
--- /dev/null
+/* *******************************************************************
+ * 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
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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()) + ")";
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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, "<init>", declaringType, parameterTypes, parameterNames, exceptionTypes);
+ }
+
+ ConstructorSignatureImpl(String stringRep) {
+ super(stringRep);
+ }
+
+ public String getName() { return "<init>"; }
+
+ 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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 <class>
+ * ******************************************************************/
+
+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 <tt>-Xset:targetRuntime1_6_10=true</tt>.
+ *
+ * @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 <tt>-Xset:targetRuntime1_6_10=true</tt>.
+ * <p>
+ * 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);
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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) ? "<clinit>" : "<init>", declaringType, EMPTY_CLASS_ARRAY,
+ EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY);
+ }
+
+ InitializerSignatureImpl(String stringRep) {
+ super(stringRep);
+ }
+
+ public String getName() {
+ return Modifier.isStatic(getModifiers()) ? "<clinit>": "<init>";
+ }
+
+ 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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);
+ }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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);
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * 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();
+ }
+}
+
--- /dev/null
+/* *******************************************************************
+ * 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);
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+}
+++ /dev/null
-/*******************************************************************************
- * 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.
- * <p/>
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
-
-/**
- * <p>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 <code>thisJoinPoint</code>. The primary
- * use of this reflective information is for tracing and logging applications.
- * </p>
- *
- * <pre>
- * 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());
- * }
- * }
- * </pre>
- */
-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();
-
- /**
- * <p> Returns the currently executing object. This will always be
- * the same object as that matched by the <code>this</code> pointcut
- * designator. Unless you specifically need this reflective access,
- * you should use the <code>this</code> pointcut designator to
- * get at this object for better static typing and performance.</p>
- *
- * <p> Returns null when there is no currently executing object available.
- * This includes all join points that occur in a static context.</p>
- */
- Object getThis();
-
- /**
- * <p> Returns the target object. This will always be
- * the same object as that matched by the <code>target</code> pointcut
- * designator. Unless you specifically need this reflective access,
- * you should use the <code>target</code> pointcut designator to
- * get at this object for better static typing and performance.</p>
- *
- * <p> Returns null when there is no target object.</p>
-
- */
- Object getTarget();
-
- /**
- * <p>Returns the arguments at this join point.</p>
- */
- Object[] getArgs();
-
- /** Returns the signature at the join point.
- *
- * <code>getStaticPart().getSignature()</code> returns the same object
- */
- Signature getSignature();
-
- /** <p>Returns the source location corresponding to the join point.</p>
- *
- * <p>If there is no source location available, returns null.</p>
- *
- * <p>Returns the SourceLocation of the defining class for default constructors.</p>
- *
- * <p> <code>getStaticPart().getSourceLocation()</code> returns the same object. </p>
- */
- SourceLocation getSourceLocation();
-
- /** Returns a String representing the kind of join point. This
- * String is guaranteed to be
- * interned. <code>getStaticPart().getKind()</code> returns
- * the same object.
- */
- String getKind();
-
- /**
- * <p>This helper object contains only the static information about a join point.
- * It is available from the <code>JoinPoint.getStaticPart()</code> method, and
- * can be accessed separately within advice using the special form
- * <code>thisJoinPointStaticPart</code>.</p>
- *
- * <p>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.</p>
- *
- * <pre>
- * public class LoggingUtils {
- * public static void prettyPrint(JoinPoint.StaticPart jp) {
- * ...
- * }
- * }
- *
- * aspect Logging {
- * before(): ... { LoggingUtils.prettyPrint(thisJoinPointStaticPart); }
- * }
- * </pre>
- *
- * @see JoinPoint#getStaticPart()
- */
- public interface StaticPart {
- /** Returns the signature at the join point. */
- Signature getSignature();
-
- /** <p>Returns the source location corresponding to the join point.</p>
- *
- * <p>If there is no source location available, returns null.</p>
- *
- * <p>Returns the SourceLocation of the defining class for default constructors.</p>
- */
- SourceLocation getSourceLocation();
-
- /** <p> Returns a String representing the kind of join point. This String
- * is guaranteed to be interned</p>
- */
- String getKind();
-
- /**
- * Return the id for this JoinPoint.StaticPart. All JoinPoint.StaticPart
- * instances are assigned an id number upon creation. For each advised type
- * the id numbers start at 0.
- * <br>
- * The id is guaranteed to remain constant across repeated executions
- * of a program but may change if the code is recompiled.
- * <br>
- * The benefit of having an id is that it can be used for array index
- * purposes which can be quicker than using the JoinPoint.StaticPart
- * object itself in a map lookup.
- * <br>
- * Since two JoinPoint.StaticPart instances in different advised types may have
- * the same id, then if the id is being used to index some joinpoint specific
- * state then that state must be maintained on a pertype basis - either by
- * using pertypewithin() or an ITD.
- *
- * @return the id of this joinpoint
- */
- int getId();
-
- String toString();
-
- /**
- * 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";
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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 <code>aspectOf</code> 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; }
-
-}
+++ /dev/null
-/*******************************************************************************
- * 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 <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
- */
-public interface ProceedingJoinPoint extends JoinPoint {
-
- /**
- * The joinpoint needs to know about its closure so that proceed can delegate to closure.run()
- * <p/>
- * 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
- * <p/>
- * <p>Unlike code style, proceed(..) in annotation style places different requirements on the
- * parameters passed to it. The proceed(..) call takes, in this order:
- * <ul>
- * <li> If 'this()' was used in the pointcut for binding, it must be passed first in proceed(..).
- * <li> 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.
- * <li> 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.
- * </ul>
- * <p>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.
- * </p>
- *
- * @param args
- * @return
- * @throws Throwable
- */
- public Object proceed(Object[] args) throws Throwable;
-
-}
-
-
+++ /dev/null
-/* *******************************************************************
- * 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;
-
-/** <p>Represents the signature at a join point. This interface parallels
- * <code>java.lang.reflect.Member</code>. </p>
- *
- * <p>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 <code>java.util.logging</code> API</p>
- * <pre>
- * aspect Logging {
- * Logger logger = Logger.getLogger("MethodEntries");
- *
- * before(): within(com.bigboxco..*) && execution(public * *(..)) {
- * Signature sig = thisJoinPoint.getSignature();
- * logger.entering(sig.getDeclaringType().getName(),
- * sig.getName());
- * }
- * }
- * </pre>
- *
- *
- * <p>More detailed information about a specific kind of signature can
- * be obtained by casting this <code>Signature</code> object into one
- * of its more specific sub-types available in
- * <code>org.aspectj.lang.reflect</code>.
- *
- * @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
- * <code>java.lang.reflect.Modifier</code> to manipulate this, i.e.
- * <pre>
- * // check if this signature is public
- * java.lang.reflect.Modifier.isPublic(sig.getModifiers());
- *
- * // print out the modifiers
- * java.lang.reflect.Modifier.toString(sig.getModifiers());
- * </pre>
- *
- * @see java.lang.reflect.Member#getModifiers
- * @see java.lang.reflect.Modifier
- */
- int getModifiers();
-
- /**
- * <p>Returns a <code>java.lang.Class</code> 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
- * <code>SourceLocation.getWithinType()</code> to get the type in
- * which the declaration occurs lexically.</p>
- * <p>For consistency with <code>java.lang.reflect.Member</code>, this
- * method should have been named <code>getDeclaringClass()</code>.</p>
- *
- * @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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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 <code>declare soft: TypePattern: Pointcut</code>.
- * At the join points, any exceptions thrown which match
- * TypePattern will be wrapped in <code>SoftException</code>
- * and rethrown. You can get the original exception using
- * <code>getWrappedThrowable()</code> or
- * <code>getCause()</code>.
- */
-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);
- }
- }
-}
+++ /dev/null
-<html>
-<body>
-Provides several interfaces for obtaining reflective information about a
-join point, as well as several exceptions that can be thrown by AspectJ
-code.
-<p>
-<code>JoinPoint</code> and <code>Signature</code> provide reflective
-information about a join point. Instances of these interfaces are
-available inside of <code>advice</code> with the special variables
-<code>thisJoinPoint</code>, <code>thisJoinPointStaticPart</code>, and
-<code>thisEnclosingJoinPointStaticPart</code>.</p>
-
-</body>
-</html>
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/*******************************************************************************
- * 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 {
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-}
-
+++ /dev/null
-/*******************************************************************************
- * 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 {
-
-}
+++ /dev/null
-<html>
-<body>
-<p>Contains interfaces that extend <code>Signature</code> 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.</p>
-<pre>
- before(): call(* *(..)) {
- MethodSignature sig = (MethodSignature)thisJoinPoint.getSignature();
- ...
- }
-</pre>
-
-<p>This package also contains <code>SourceLocation</code> that provides
-information about the location in source code that corresponds to a
-particular join point.</p>
-</body>
-</html>
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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];
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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);
-// }
-}
+++ /dev/null
-/* *******************************************************************
- * 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
+++ /dev/null
-/* *******************************************************************
- * 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
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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()) + ")";
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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, "<init>", declaringType, parameterTypes, parameterNames, exceptionTypes);
- }
-
- ConstructorSignatureImpl(String stringRep) {
- super(stringRep);
- }
-
- public String getName() { return "<init>"; }
-
- 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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 <class>
- * ******************************************************************/
-
-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 <tt>-Xset:targetRuntime1_6_10=true</tt>.
- *
- * @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 <tt>-Xset:targetRuntime1_6_10=true</tt>.
- * <p>
- * 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);
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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) ? "<clinit>" : "<init>", declaringType, EMPTY_CLASS_ARRAY,
- EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY);
- }
-
- InitializerSignatureImpl(String stringRep) {
- super(stringRep);
- }
-
- public String getName() {
- return Modifier.isStatic(getModifiers()) ? "<clinit>": "<init>";
- }
-
- 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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);
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * 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;
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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);
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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;
- }
-
- }
-}
+++ /dev/null
-/* *******************************************************************
- * 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();
- }
-}
-
+++ /dev/null
-/* *******************************************************************
- * 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);
- }
-}
+++ /dev/null
-/*******************************************************************************
- * 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;
- }
-}
--- /dev/null
+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"));
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * 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]);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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
--- /dev/null
+/*******************************************************************************
+ * 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.
+ }
+}
+++ /dev/null
-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"));
- }
-}
+++ /dev/null
-/*******************************************************************************
- * 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]);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * 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
+++ /dev/null
-/*******************************************************************************
- * 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.
- }
-}