]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 54721
authoracolyer <acolyer>
Fri, 19 Mar 2004 20:48:01 +0000 (20:48 +0000)
committeracolyer <acolyer>
Fri, 19 Mar 2004 20:48:01 +0000 (20:48 +0000)
  add this to API  (Signature.getDeclaringTypeName())

runtime/src/org/aspectj/lang/Signature.java
runtime/src/org/aspectj/runtime/reflect/AdviceSignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/ConstructorSignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/FieldSignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/InitializerSignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/MethodSignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
runtime/src/org/aspectj/runtime/reflect/StringMaker.java
runtime/testsrc/RuntimeModuleTests.java
runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java [new file with mode: 0644]

index 91e2f00a23e8931b3d66690311b570e9bbe2fa82..ae21d65a396805293853bcd346e0ca78c63b92e1 100644 (file)
@@ -92,4 +92,11 @@ public interface Signature {
      * @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();
 }
index 647fb652887946c63d1eb8f1a6cb5c04050346f3..029d4e6dedc8e2cbbb4319c133b1490faf919e6a 100644 (file)
@@ -45,7 +45,7 @@ class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
         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());
index a81d25831543e54a5ff3d44754e4204c8a17db17..c9576baaa57950c1d4136d9091638df0157ccae8 100644 (file)
@@ -32,7 +32,7 @@ class ConstructorSignatureImpl extends CodeSignatureImpl implements ConstructorS
     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();
index 4fbc7d2c8c5ef7885f1ea98f106f80a17c76d643..b04f23525e443fddebcf5772fed172f887b84598 100644 (file)
@@ -40,7 +40,7 @@ public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSign
         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();
index f2e7d5b0130d8e4a2ff68d687266ca9e5a10db8d..d7301d8acec0fad2af8531d720bf998e0223b315 100644 (file)
@@ -35,7 +35,7 @@ class InitializerSignatureImpl extends CodeSignatureImpl implements InitializerS
     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();
index b2652cc7978acd197ce188dc41b72bb1317d9d3c..1ec8c69147230e7dbb0179bfe6b2f9a6fe868506 100644 (file)
@@ -43,7 +43,7 @@ class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature {
         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());
index d5426eeaaaa3d239b77d63e4bc437d529233124a..b010acf26707d70cf520ad3448211deb860ac558 100644 (file)
@@ -22,6 +22,7 @@ import java.util.StringTokenizer;
 abstract class SignatureImpl implements Signature {
     int modifiers = -1;
     String name;
+    String declaringTypeName;
     Class declaringType;
     
     SignatureImpl(int modifiers, String name, Class declaringType) {
@@ -48,7 +49,12 @@ abstract class SignatureImpl implements Signature {
         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";
index a63ae9d6b7305f8a59dc17bac18fad7ea99156f2..e014defb442d1d3055d90035eeb8a9aeed5af995 100644 (file)
@@ -81,22 +81,25 @@ class StringMaker {
         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) {
index ff7560c8e6e762d44b5d74e374a01ca764189bcf..b8f2d7408ff2236b4e74f75e1df8c709f2865195 100644 (file)
@@ -16,6 +16,7 @@
 import java.io.*;
 
 import org.aspectj.lang.*;
+import org.aspectj.runtime.reflect.SignatureTest;
 
 import junit.framework.*;
 
@@ -24,6 +25,7 @@ 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);
         return suite;
     }
 
@@ -70,6 +72,8 @@ public class RuntimeModuleTests extends TestCase {
             System.setErr(systemErr);
         }
     }
+   
+    
     static void checkSoftExceptionString(String s) {        
         assertTrue(-1 != s.indexOf("SoftException"));
         assertTrue(-1 != s.indexOf("Caused by: java.lang.Error"));
diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java
new file mode 100644 (file)
index 0000000..b8170d6
--- /dev/null
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.
+       }
+}