From dac2ff628bffa7a34c362ec65cd963df5f0e7b77 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 3 Jul 2006 14:37:24 +0000 Subject: [PATCH] new handle provider (pr141730): helper method --- util/src/org/aspectj/util/NameConvertor.java | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/util/src/org/aspectj/util/NameConvertor.java b/util/src/org/aspectj/util/NameConvertor.java index df1292581..28809378d 100644 --- a/util/src/org/aspectj/util/NameConvertor.java +++ b/util/src/org/aspectj/util/NameConvertor.java @@ -21,6 +21,10 @@ public class NameConvertor { private static final char LONG = 'J'; private static final char SHORT = 'S'; private static final char ARRAY = '['; + private static final char RESOLVED = 'L'; + private static final char UNRESOLVED = 'Q'; + + public static final char PARAMETERIZED = 'P'; private static final char[] BOOLEAN_NAME = new char[]{'b','o','o','l','e','a','n'}; private static final char[] BYTE_NAME = new char[]{'b','y','t','e'}; @@ -35,6 +39,8 @@ public class NameConvertor { private static final char[] GREATER_THAN = new char[]{'>'}; private static final char[] LESS_THAN = new char[]{'<'}; private static final char[] COMMA = new char[]{','}; + private static final char[] BACKSLASH_LESSTHAN = new char[]{'\\','<'}; + private static final char[] SEMICOLON = new char[]{';'}; /** @@ -135,5 +141,73 @@ public class NameConvertor { } } + /** + * Given 'Ppkg/MyGenericClass;' + * will return 'QMyGenericClass;' + */ + public static char[] createShortName(char[] c) { + int lt = CharOperation.indexOf('<',c); + int sc = CharOperation.indexOf(';',c); + int gt = CharOperation.indexOf('>',c); + + int smallest = 0; + if (lt == -1 && sc == -1 && gt == -1) { + // we have something like 'Ljava/lang/String' or 'I' + return getTypeName(c); + } else if (lt != -1 && (sc == -1 || lt <= sc) && (gt == -1 || lt <= gt)) { + // we have something like 'Ljava/lang/String;' + smallest = gt; + } + char[] first = CharOperation.subarray(c,0,smallest); + char[] second = CharOperation.subarray(c,smallest+1,c.length); + if (smallest == 0 && first.length == 0 && c[0] == '>') { + // c = {'>',';'} therefore we just want to return c to + // close the generic signature + return c; + } else if (first.length == 1 && second.length == 0) { + return first; + } else if (second.length == 0 || (second.length == 1 && second[0] == ';')){ + // we've reached the end of the array, therefore only care about + // the first part + return createShortName(first); + } else if (smallest == lt) { + // if c = 'Ljava/lang/String;