]> source.dussan.org Git - aspectj.git/commitdiff
351085
authoraclement <aclement>
Fri, 16 Sep 2011 00:58:28 +0000 (00:58 +0000)
committeraclement <aclement>
Fri, 16 Sep 2011 00:58:28 +0000 (00:58 +0000)
asm/src/org/aspectj/asm/internal/ProgramElement.java

index b38a8286b19bfd2132c9869be769f78e1d3fe7ef..497b25028be6490944f328f3ea9e3e31a865c532 100644 (file)
@@ -493,11 +493,42 @@ public class ProgramElement implements IProgramElement {
                if (getFullyQualifiedType) {
                        return returnType;
                }
-               int index = returnType.lastIndexOf(".");
-               if (index != -1) {
-                       return returnType.substring(index + 1);
+               return trim(returnType);
+       }
+
+       /**
+        * Trim down fully qualified types to their short form (e.g. a.b.c.D<e.f.G> becomes D<G>)
+        */
+       public static String trim(String fqname) {
+               int i = fqname.indexOf("<");
+               if (i == -1) {
+                       int lastdot = fqname.lastIndexOf('.');
+                       if (lastdot == -1) {
+                               return fqname;
+                       } else {
+                               return fqname.substring(lastdot + 1);
+                       }
+               }
+               char[] charArray = fqname.toCharArray();
+               StringBuilder candidate = new StringBuilder(charArray.length);
+               StringBuilder complete = new StringBuilder(charArray.length);
+               for (char c : charArray) {
+                       switch (c) {
+                       case '.':
+                               candidate.setLength(0);
+                               break;
+                       case '<':
+                       case ',':
+                       case '>':
+                               complete.append(candidate).append(c);
+                               candidate.setLength(0);
+                               break;
+                       default:
+                               candidate.append(c);
+                       }
                }
-               return returnType;
+               complete.append(candidate);
+               return complete.toString();
        }
 
        public String getName() {