aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 17:09:36 +0000
committerwisberg <wisberg>2002-12-16 17:09:36 +0000
commitc3300283ecc397d26ad9dfe31d1710ec45db2af0 (patch)
treee9acb7f3d33c1499975cec9ef3cc7ea151078344 /runtime/src
parent3cde920c3f7eb8241bf569007e25225d80b43c0f (diff)
downloadaspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.tar.gz
aspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.zip
initial version
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/.cvsignore1
-rw-r--r--runtime/src/org/aspectj/lang/JoinPoint.java179
-rw-r--r--runtime/src/org/aspectj/lang/NoAspectBoundException.java21
-rw-r--r--runtime/src/org/aspectj/lang/Signature.java95
-rw-r--r--runtime/src/org/aspectj/lang/SoftException.java37
-rw-r--r--runtime/src/org/aspectj/lang/package.html14
-rw-r--r--runtime/src/org/aspectj/lang/reflect/AdviceSignature.java21
-rw-r--r--runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java22
-rw-r--r--runtime/src/org/aspectj/lang/reflect/CodeSignature.java21
-rw-r--r--runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java18
-rw-r--r--runtime/src/org/aspectj/lang/reflect/FieldSignature.java21
-rw-r--r--runtime/src/org/aspectj/lang/reflect/InitializerSignature.java17
-rw-r--r--runtime/src/org/aspectj/lang/reflect/MemberSignature.java20
-rw-r--r--runtime/src/org/aspectj/lang/reflect/MethodSignature.java19
-rw-r--r--runtime/src/org/aspectj/lang/reflect/SourceLocation.java30
-rw-r--r--runtime/src/org/aspectj/lang/reflect/package.html18
-rw-r--r--runtime/src/org/aspectj/runtime/CFlow.java39
-rw-r--r--runtime/src/org/aspectj/runtime/internal/AroundClosure.java39
-rw-r--r--runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java32
-rw-r--r--runtime/src/org/aspectj/runtime/internal/CFlowStack.java107
-rw-r--r--runtime/src/org/aspectj/runtime/internal/Conversions.java145
-rw-r--r--runtime/src/org/aspectj/runtime/internal/PerObjectMap.java35
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java58
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java48
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java49
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java41
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/Factory.java90
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java51
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java44
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java76
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java28
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java55
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java188
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java43
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/StringMaker.java134
35 files changed, 1856 insertions, 0 deletions
diff --git a/runtime/src/.cvsignore b/runtime/src/.cvsignore
new file mode 100644
index 000000000..a3f0b1b77
--- /dev/null
+++ b/runtime/src/.cvsignore
@@ -0,0 +1 @@
+*.lst
diff --git a/runtime/src/org/aspectj/lang/JoinPoint.java b/runtime/src/org/aspectj/lang/JoinPoint.java
new file mode 100644
index 000000000..4fae1571a
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/JoinPoint.java
@@ -0,0 +1,179 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-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();
+
+ 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 an object that encapsulates the static parts of this join point </p>
+ */
+ 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 PREINTIALIZATION = "preinitialization";
+ static String INITIALIZATION = "initialization";
+ static String EXCEPTION_HANDLER = "exception-handler";
+
+ static String ADVICE_EXECUTION = "advice-execution"; //??? consider this vs. pcd
+}
diff --git a/runtime/src/org/aspectj/lang/NoAspectBoundException.java b/runtime/src/org/aspectj/lang/NoAspectBoundException.java
new file mode 100644
index 000000000..4bebcfb47
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/NoAspectBoundException.java
@@ -0,0 +1,21 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-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 {
+}
diff --git a/runtime/src/org/aspectj/lang/Signature.java b/runtime/src/org/aspectj/lang/Signature.java
new file mode 100644
index 000000000..91e2f00a2
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/Signature.java
@@ -0,0 +1,95 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-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; i.e. 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();
+}
diff --git a/runtime/src/org/aspectj/lang/SoftException.java b/runtime/src/org/aspectj/lang/SoftException.java
new file mode 100644
index 000000000..e3c19ed80
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/SoftException.java
@@ -0,0 +1,37 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang;
+
+/**
+ * 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>.
+ */
+public class SoftException extends RuntimeException {
+ Throwable inner;
+ public SoftException(Throwable inner) {
+ super();
+ this.inner = inner;
+ }
+
+ public Throwable getWrappedThrowable() { return inner; }
+
+ //XXX should add a getCause() method to parallel j2se 1.4's new
+ //XXX chained exception mechanism
+}
diff --git a/runtime/src/org/aspectj/lang/package.html b/runtime/src/org/aspectj/lang/package.html
new file mode 100644
index 000000000..a5fe7ae5d
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/package.html
@@ -0,0 +1,14 @@
+<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>
diff --git a/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java b/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java
new file mode 100644
index 000000000..8afc4e1ac
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/AdviceSignature.java
@@ -0,0 +1,21 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+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) */
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java b/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java
new file mode 100644
index 000000000..8932395aa
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/CatchClauseSignature.java
@@ -0,0 +1,22 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+import org.aspectj.lang.Signature;
+
+public interface CatchClauseSignature extends Signature {
+ Class getParameterType();
+ String getParameterName();
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/CodeSignature.java b/runtime/src/org/aspectj/lang/reflect/CodeSignature.java
new file mode 100644
index 000000000..795cb6dc9
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/CodeSignature.java
@@ -0,0 +1,21 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+public interface CodeSignature extends MemberSignature {
+ Class[] getParameterTypes();
+ String[] getParameterNames();
+ Class[] getExceptionTypes();
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java b/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java
new file mode 100644
index 000000000..66ab51397
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/ConstructorSignature.java
@@ -0,0 +1,18 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+public interface ConstructorSignature extends CodeSignature {
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/FieldSignature.java b/runtime/src/org/aspectj/lang/reflect/FieldSignature.java
new file mode 100644
index 000000000..0983509c5
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/FieldSignature.java
@@ -0,0 +1,21 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+import org.aspectj.lang.Signature;
+
+public interface FieldSignature extends MemberSignature {
+ public Class getFieldType();
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java b/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java
new file mode 100644
index 000000000..2b75f92a6
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/InitializerSignature.java
@@ -0,0 +1,17 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+public interface InitializerSignature extends CodeSignature { }
diff --git a/runtime/src/org/aspectj/lang/reflect/MemberSignature.java b/runtime/src/org/aspectj/lang/reflect/MemberSignature.java
new file mode 100644
index 000000000..31f21df7d
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/MemberSignature.java
@@ -0,0 +1,20 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+import org.aspectj.lang.Signature;
+
+public interface MemberSignature extends Signature {
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/MethodSignature.java b/runtime/src/org/aspectj/lang/reflect/MethodSignature.java
new file mode 100644
index 000000000..f26d6c504
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/MethodSignature.java
@@ -0,0 +1,19 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+public interface MethodSignature extends CodeSignature {
+ Class getReturnType(); /* name is consistent with reflection API */
+}
diff --git a/runtime/src/org/aspectj/lang/reflect/SourceLocation.java b/runtime/src/org/aspectj/lang/reflect/SourceLocation.java
new file mode 100644
index 000000000..cb6bfcf95
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/SourceLocation.java
@@ -0,0 +1,30 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.lang.reflect;
+
+/** For defining code, the class defined and location in a source file. */
+public interface SourceLocation {
+ Class getWithinType();
+
+ String getFileName();
+ int getLine();
+
+ /**
+ * @deprecated can not be implemented for bytecode weaving, may
+ * be removed in 1.1gold.
+ */
+ int getColumn();
+}
+
diff --git a/runtime/src/org/aspectj/lang/reflect/package.html b/runtime/src/org/aspectj/lang/reflect/package.html
new file mode 100644
index 000000000..fc51a5b60
--- /dev/null
+++ b/runtime/src/org/aspectj/lang/reflect/package.html
@@ -0,0 +1,18 @@
+<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>
diff --git a/runtime/src/org/aspectj/runtime/CFlow.java b/runtime/src/org/aspectj/runtime/CFlow.java
new file mode 100644
index 000000000..59165f8a7
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/CFlow.java
@@ -0,0 +1,39 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime;
+
+public class CFlow {
+ private Object _aspect;
+
+ public CFlow() {
+ this(null);
+ }
+
+ public CFlow(Object _aspect) {
+ this._aspect = _aspect;
+ }
+
+ public Object getAspect() {
+ return this._aspect;
+ }
+
+ public void setAspect(Object _aspect) {
+ this._aspect = _aspect;
+ }
+
+ public Object get(int index) {
+ return null;
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/internal/AroundClosure.java b/runtime/src/org/aspectj/runtime/internal/AroundClosure.java
new file mode 100644
index 000000000..1d5ad810a
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/internal/AroundClosure.java
@@ -0,0 +1,39 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.internal;
+
+public abstract class AroundClosure {
+ //private Object[] state;
+
+ public AroundClosure(/* Object[] state */) {
+ // this.state = state;
+ }
+
+ protected Object[] state;
+ protected Object[] preInitializationState;
+ public AroundClosure(Object[] state) {
+ this.state = 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;
+}
diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java b/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java
new file mode 100644
index 000000000..b47addde3
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/internal/CFlowPlusState.java
@@ -0,0 +1,32 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.internal;
+
+public class CFlowPlusState extends org.aspectj.runtime.CFlow {
+ private Object[] state;
+
+ public CFlowPlusState(Object[] state) {
+ this.state = state;
+ }
+
+ public CFlowPlusState(Object[] state, Object _aspect) {
+ super(_aspect);
+ this.state = state;
+ }
+
+ public Object get(int index) {
+ return state[index];
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowStack.java b/runtime/src/org/aspectj/runtime/internal/CFlowStack.java
new file mode 100644
index 000000000..d3b18c710
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/internal/CFlowStack.java
@@ -0,0 +1,107 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.internal;
+
+import org.aspectj.lang.NoAspectBoundException;
+import org.aspectj.runtime.CFlow;
+
+import java.util.Stack;
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.Enumeration;
+
+public class CFlowStack {
+ 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;
+
+ private 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
+ if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/stacks.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;
+ }
+
+ //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() {
+ getThreadStack().pop();
+ }
+
+ public Object peek() {
+ Stack stack = getThreadStack();
+ if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException();
+ return (Object)stack.peek();
+ }
+
+ public Object get(int index) {
+ return peekCFlow().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.get(0);
+ }
+
+ public boolean isValid() {
+ return !getThreadStack().isEmpty();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/internal/Conversions.java b/runtime/src/org/aspectj/runtime/internal/Conversions.java
new file mode 100644
index 000000000..24be02d0d
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/internal/Conversions.java
@@ -0,0 +1,145 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.internal;
+
+public final class Conversions {
+ // Can't make instances of me
+ private Conversions() {}
+
+ // we might want to keep a cache of small integers around
+ public static Object intObject(int i) {
+ return new Integer(i);
+ }
+ public static Object shortObject(short i) {
+ return new Short(i);
+ }
+ public static Object byteObject(byte i) {
+ return new Byte(i);
+ }
+ public static Object charObject(char i) {
+ return new Character(i);
+ }
+ public static Object longObject(long i) {
+ return new Long(i);
+ }
+ public static Object floatObject(float i) {
+ return new Float(i);
+ }
+ public static Object doubleObject(double i) {
+ return new Double(i);
+ }
+ public static Object booleanObject(boolean i) {
+ return new Boolean(i);
+ }
+ public static Object voidObject() {
+ return null;
+ }
+
+
+ public static int intValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).intValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to int");
+ }
+ }
+ public static long longValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).longValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to long");
+ }
+ }
+ public static float floatValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).floatValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to float");
+ }
+ }
+ public static double doubleValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).doubleValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to double");
+ }
+ }
+ public static byte byteValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).byteValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to byte");
+ }
+ }
+ public static short shortValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Number) {
+ return ((Number)o).shortValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to short");
+ }
+ }
+ public static char charValue(Object o) {
+ if (o == null) {
+ return 0;
+ } else if (o instanceof Character) {
+ return ((Character)o).charValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to char");
+ }
+ }
+ public static boolean booleanValue(Object o) {
+ if (o == null) {
+ return false;
+ } else if (o instanceof Boolean) {
+ return ((Boolean)o).booleanValue();
+ } else {
+ throw new ClassCastException(o.getClass().getName() +
+ " can not be converted to boolean");
+ }
+ }
+
+ /**
+ * identity function for now. This is not typed to "void" because we happen
+ * to know that in Java, any void context (i.e., {@link ExprStmt})
+ * can also handle a return value.
+ */
+ public static Object voidValue(Object o) {
+ if (o == null) {
+ return o;
+ } else {
+ // !!! this may be an error in the future
+ return o;
+ }
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java b/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java
new file mode 100644
index 000000000..5a4b5b765
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/internal/PerObjectMap.java
@@ -0,0 +1,35 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.internal;
+
+import org.aspectj.runtime.CFlow;
+
+
+// REQUIRES JAVA 2!!!!!!!!!!!!!!!!
+import java.util.WeakHashMap;
+
+public class PerObjectMap {
+ private WeakHashMap map = new WeakHashMap();
+
+ public boolean hasAspect(Object o) { return map.containsKey(o); }
+
+ public Object aspectOf(Object o) {
+ return map.get(o);
+ }
+
+ public void bind(Object object, Object _aspect) {
+ map.put(object, _aspect);
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java
new file mode 100644
index 000000000..7ea1ceff1
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java
@@ -0,0 +1,58 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+import java.lang.reflect.Modifier;
+
+class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
+ Class returnType;
+
+ 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;
+ }
+
+ String toString(StringMaker sm) {
+ //XXX this signature needs a lot of work
+ StringBuffer buf = new StringBuffer("ADVICE: ");
+ buf.append(sm.makeModifiersString(getModifiers()));
+ if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType()));
+ if (sm.includeArgs) buf.append(" ");
+ buf.append(sm.makePrimaryTypeName(getDeclaringType()));
+ buf.append(".");
+ buf.append(getName());
+ sm.addSignature(buf, getParameterTypes());
+ sm.addThrows(buf, getExceptionTypes());
+ return buf.toString();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java
new file mode 100644
index 000000000..638b7fea9
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/CatchClauseSignatureImpl.java
@@ -0,0 +1,48 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+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;
+ }
+
+ String toString(StringMaker sm) {
+ return "catch(" + sm.makeTypeName(getParameterType()) + ")";
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java
new file mode 100644
index 000000000..1045152d4
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/CodeSignatureImpl.java
@@ -0,0 +1,49 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+abstract class CodeSignatureImpl extends MemberSignatureImpl implements CodeSignature {
+ Class[] parameterTypes;
+ String[] parameterNames;
+ Class[] exceptionTypes;
+
+ CodeSignatureImpl(int modifiers, String name, Class declaringType,
+ Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes)
+ {
+ super(modifiers, name, declaringType);
+ this.parameterTypes = parameterTypes;
+ this.parameterNames = parameterNames;
+ this.exceptionTypes = exceptionTypes;
+ }
+ CodeSignatureImpl(String stringRep) {
+ super(stringRep);
+ }
+
+ public Class[] getParameterTypes() {
+ if (parameterTypes == null) parameterTypes = extractTypes(3);
+ return parameterTypes;
+ }
+ public String[] getParameterNames() {
+ if (parameterNames == null) parameterNames = extractStrings(4);
+ return parameterNames;
+ }
+ public Class[] getExceptionTypes() {
+ if (exceptionTypes == null) exceptionTypes = extractTypes(5);
+ return exceptionTypes;
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java
new file mode 100644
index 000000000..49b0827f9
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java
@@ -0,0 +1,41 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.reflect.*;
+import org.aspectj.lang.*;
+
+class ConstructorSignatureImpl extends CodeSignatureImpl implements ConstructorSignature {
+ 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>"; }
+
+ String toString(StringMaker sm) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(sm.makeModifiersString(getModifiers()));
+ buf.append(sm.makePrimaryTypeName(getDeclaringType()));
+ sm.addSignature(buf, getParameterTypes());
+ sm.addThrows(buf, getExceptionTypes());
+ return buf.toString();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/Factory.java b/runtime/src/org/aspectj/runtime/reflect/Factory.java
new file mode 100644
index 000000000..781286389
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/Factory.java
@@ -0,0 +1,90 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+public final class Factory {
+ Class lexicalClass;
+ ClassLoader lookupClassLoader;
+ String filename;
+ public Factory(String filename, Class lexicalClass) {
+ //System.out.println("making
+ this.filename = filename;
+ this.lexicalClass = lexicalClass;
+ lookupClassLoader = lexicalClass.getClassLoader();
+ }
+
+ public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) {
+ return new JoinPointImpl.StaticPartImpl(kind, sig, loc);
+ }
+
+ public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l, int c) {
+ return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, c));
+ }
+
+ public JoinPoint.StaticPart makeSJP(String kind, Signature sig, int l) {
+ return new JoinPointImpl.StaticPartImpl(kind, sig, makeSourceLoc(l, -1));
+ }
+
+ public 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 ConstructorSignature makeConstructorSig(String stringRep) {
+ ConstructorSignatureImpl ret = new ConstructorSignatureImpl(stringRep);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+ public FieldSignature makeFieldSig(String stringRep) {
+ FieldSignatureImpl ret = new FieldSignatureImpl(stringRep);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+ public AdviceSignature makeAdviceSig(String stringRep) {
+ AdviceSignatureImpl ret = new AdviceSignatureImpl(stringRep);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+ public InitializerSignature makeInitializerSig(String stringRep) {
+ InitializerSignatureImpl ret = new InitializerSignatureImpl(stringRep);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+ public CatchClauseSignature makeCatchClauseSig(String stringRep) {
+ CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(stringRep);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+
+ public SourceLocation makeSourceLoc(int line, int col)
+ {
+ return new SourceLocationImpl(lexicalClass, this.filename, line, col);
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java
new file mode 100644
index 000000000..5ab058edd
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java
@@ -0,0 +1,51 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.reflect.*;
+import org.aspectj.lang.*;
+
+import java.lang.reflect.Modifier;
+
+public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature {
+ Class fieldType;
+
+ 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;
+ }
+
+ String toString(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()));
+ buf.append(".");
+ buf.append(getName());
+ return buf.toString();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java
new file mode 100644
index 000000000..f7065d673
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java
@@ -0,0 +1,44 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.reflect.*;
+import org.aspectj.lang.*;
+
+import java.lang.reflect.Modifier;
+
+class InitializerSignatureImpl extends CodeSignatureImpl implements InitializerSignature {
+ 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>";
+ }
+
+ String toString(StringMaker sm) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(sm.makeModifiersString(getModifiers()));
+ buf.append(sm.makePrimaryTypeName(getDeclaringType()));
+ buf.append(".");
+ buf.append(getName());
+ return buf.toString();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java
new file mode 100644
index 000000000..573d8b338
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java
@@ -0,0 +1,76 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+
+import org.aspectj.lang.reflect.SourceLocation;
+
+class JoinPointImpl implements JoinPoint {
+ static class StaticPartImpl implements JoinPoint.StaticPart {
+ String kind;
+ Signature signature;
+ SourceLocation sourceLocation;
+
+ public StaticPartImpl(String kind, Signature signature, SourceLocation sourceLocation) {
+ this.kind = kind;
+ this.signature = signature;
+ this.sourceLocation = sourceLocation;
+ }
+
+ public String getKind() { return kind; }
+ public Signature getSignature() { return signature; }
+ public SourceLocation getSourceLocation() { return sourceLocation; }
+
+ String toString(StringMaker sm) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(sm.makeKindName(getKind()));
+ buf.append("(");
+ buf.append(((SignatureImpl)getSignature()).toString(sm));
+ buf.append(")");
+ return buf.toString();
+ }
+
+ public final String toString() { return toString(StringMaker.middleStringMaker); }
+ public final String toShortString() { return toString(StringMaker.shortStringMaker); }
+ public final String toLongString() { return toString(StringMaker.longStringMaker); }
+ }
+
+ 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() { return args; }
+
+ 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(); }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java
new file mode 100644
index 000000000..3097a1abf
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/MemberSignatureImpl.java
@@ -0,0 +1,28 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+abstract class MemberSignatureImpl extends SignatureImpl implements MemberSignature {
+ MemberSignatureImpl(int modifiers, String name, Class declaringType) {
+ super(modifiers, name, declaringType);
+ }
+
+ public MemberSignatureImpl(String stringRep) {
+ super(stringRep);
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java
new file mode 100644
index 000000000..4318dc9ca
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java
@@ -0,0 +1,55 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.Modifier;
+
+class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature {
+ 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;
+ }
+
+ String toString(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()));
+ buf.append(".");
+ buf.append(getName());
+ sm.addSignature(buf, getParameterTypes());
+ sm.addThrows(buf, getExceptionTypes());
+ return buf.toString();
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
new file mode 100644
index 000000000..ec46bbbab
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
@@ -0,0 +1,188 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+import java.util.*;
+
+abstract class SignatureImpl implements Signature {
+ int modifiers = -1;
+ String name;
+ Class declaringType;
+
+ SignatureImpl(int modifiers, String name, Class declaringType) {
+ this.modifiers = modifiers;
+ this.name = name;
+ this.declaringType = declaringType;
+ }
+
+ abstract String toString(StringMaker sm);
+
+ 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;
+ }
+
+
+ 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
+ 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 makeClass(s);
+ }
+
+ 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);
+ }
+
+ Class makeClass(String s) {
+ 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.
+ */
+ ClassLoader loader = getLookupClassLoader();
+ if (loader == null) {
+ return Class.forName(s);
+ } else {
+ return loader.loadClass(s);
+ }
+ } catch (ClassNotFoundException e) {
+ //System.out.println("null for: " + s);
+ //XXX there should be a better return value for this
+ return ClassNotFoundException.class;
+ }
+ }
+
+ 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]= makeClass(st.nextToken());
+ return ret;
+ }
+}
diff --git a/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java b/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java
new file mode 100644
index 000000000..6a04283b3
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/SourceLocationImpl.java
@@ -0,0 +1,43 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+
+class SourceLocationImpl implements SourceLocation {
+ Class withinType;
+ String fileName;
+ int line;
+ int column;
+
+ SourceLocationImpl(Class withinType, String fileName, int line, int column) {
+ this.withinType = withinType;
+ this.fileName = fileName;
+ this.line = line;
+ this.column = column;
+ }
+
+ public Class getWithinType() { return withinType; }
+ public String getFileName() { return fileName; }
+ public int getLine() { return line; }
+ public int getColumn() { return column; }
+
+ public String toString() {
+ return getFileName() + ":" + getLine() +
+ ((getColumn() == -1) ? "" : ":" + getColumn());
+ }
+}
+
diff --git a/runtime/src/org/aspectj/runtime/reflect/StringMaker.java b/runtime/src/org/aspectj/runtime/reflect/StringMaker.java
new file mode 100644
index 000000000..bc46f992c
--- /dev/null
+++ b/runtime/src/org/aspectj/runtime/reflect/StringMaker.java
@@ -0,0 +1,134 @@
+/* *******************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.runtime.reflect;
+
+import org.aspectj.lang.*;
+import org.aspectj.lang.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;
+
+ 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;
+
+ }
+
+ static StringMaker middleStringMaker;
+ static {
+ middleStringMaker = new StringMaker();
+ middleStringMaker.shortTypeNames = true;
+ middleStringMaker.includeArgs = true;
+ middleStringMaker.includeThrows = false;
+ middleStringMaker.includeModifiers = false;
+ middleStringMaker.shortPrimaryTypeNames = false;
+ }
+
+ 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;
+ }
+
+ 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, boolean shortName) {
+ if (type == null) return "ANONYMOUS";
+ if (type.isArray()) return makeTypeName(type.getComponentType(), shortName) + "[]";
+ if (shortName) {
+ return stripPackageName(type.getName()).replace('$', '.');
+ } else {
+ return type.getName().replace('$', '.');
+ }
+ }
+
+ public String makeTypeName(Class type) {
+ return makeTypeName(type, shortTypeNames);
+ }
+
+ public String makePrimaryTypeName(Class type) {
+ return makeTypeName(type, 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);
+ }
+}