* @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();
}
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(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
buf.append(".");
buf.append(getName());
sm.addSignature(buf, getParameterTypes());
String toString(StringMaker sm) {
StringBuffer buf = new StringBuffer();
buf.append(sm.makeModifiersString(getModifiers()));
- buf.append(sm.makePrimaryTypeName(getDeclaringType()));
+ buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
sm.addSignature(buf, getParameterTypes());
sm.addThrows(buf, getExceptionTypes());
return buf.toString();
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(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
buf.append(".");
buf.append(getName());
return buf.toString();
String toString(StringMaker sm) {
StringBuffer buf = new StringBuffer();
buf.append(sm.makeModifiersString(getModifiers()));
- buf.append(sm.makePrimaryTypeName(getDeclaringType()));
+ buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
buf.append(".");
buf.append(getName());
return buf.toString();
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(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
buf.append(".");
buf.append(getName());
sm.addSignature(buf, getParameterTypes());
abstract class SignatureImpl implements Signature {
int modifiers = -1;
String name;
+ String declaringTypeName;
Class declaringType;
SignatureImpl(int modifiers, String name, Class declaringType) {
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";
return name.substring(dot+1);
}
- String makeTypeName(Class type, boolean shortName) {
+ String makeTypeName(Class type, String typeName, boolean shortName) {
if (type == null) return "ANONYMOUS";
- if (type.isArray()) return makeTypeName(type.getComponentType(), shortName) + "[]";
+ if (type.isArray()) {
+ Class componentType = type.getComponentType();
+ return makeTypeName(componentType, componentType.getName(), shortName) + "[]";
+ }
if (shortName) {
- return stripPackageName(type.getName()).replace('$', '.');
+ return stripPackageName(typeName).replace('$', '.');
} else {
- return type.getName().replace('$', '.');
+ return typeName.replace('$', '.');
}
}
public String makeTypeName(Class type) {
- return makeTypeName(type, shortTypeNames);
+ return makeTypeName(type, type.getName(),shortTypeNames);
}
- public String makePrimaryTypeName(Class type) {
- return makeTypeName(type, shortPrimaryTypeNames);
+ public String makePrimaryTypeName(Class type, String typeName) {
+ return makeTypeName(type, typeName, shortPrimaryTypeNames);
}
public void addTypeNames(StringBuffer buf, Class[] types) {
import java.io.*;
import org.aspectj.lang.*;
+import org.aspectj.runtime.reflect.SignatureTest;
import junit.framework.*;
public static TestSuite suite() {
TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName());
suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing)
+ suite.addTestSuite(SignatureTest.class);
return suite;
}
System.setErr(systemErr);
}
}
+
+
static void checkSoftExceptionString(String s) {
assertTrue(-1 != s.indexOf("SoftException"));
assertTrue(-1 != s.indexOf("Caused by: java.lang.Error"));
--- /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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.runtime.reflect;
+
+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.
+ }
+}