diff options
author | aclement <aclement> | 2008-12-04 02:06:08 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-12-04 02:06:08 +0000 |
commit | 4ab5683130ed30b559b9437a14abe194f06aa20e (patch) | |
tree | eb83d025ea69a76fd9f0f3b5451efeab85ec1588 /asm | |
parent | c2a2fc097355c1f7c6940d71e266110bfc3cef12 (diff) | |
download | aspectj-4ab5683130ed30b559b9437a14abe194f06aa20e.tar.gz aspectj-4ab5683130ed30b559b9437a14abe194f06aa20e.zip |
249216: handle changes
Diffstat (limited to 'asm')
-rw-r--r-- | asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java | 19 | ||||
-rw-r--r-- | asm/src/org/aspectj/asm/internal/NameConvertor.java | 215 |
2 files changed, 133 insertions, 101 deletions
diff --git a/asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java b/asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java index aa4900fb9..d212926bb 100644 --- a/asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java +++ b/asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java @@ -103,7 +103,12 @@ public class JDTLikeHandleProvider implements IElementHandleProvider { // if (ipe.getKind() == IProgramElement.Kind.PACKAGE && ipe.getName().equals("DEFAULT")) { // // the delimiter will be in there, but skip the word DEFAULT as it is just a placeholder // } else { - handle.append(ipe.getName()).append(getParameters(ipe)); + if (ipe.getKind().isDeclareAnnotation()) { + // escape the @ (pr249216c9) + handle.append("declare \\@").append(ipe.getName().substring(9)).append(getParameters(ipe)); + } else { + handle.append(ipe.getName()).append(getParameters(ipe)); + } } // } } @@ -125,17 +130,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider { for (Iterator iter = parameterTypes.iterator(); iter.hasNext();) { char[] element = (char[]) iter.next(); sb.append(HandleProviderDelimiter.getDelimiter(ipe)); - if (element[0] == HandleProviderDelimiter.TYPE.getDelimiter()) { - // its an array - sb.append(HandleProviderDelimiter.ESCAPE.getDelimiter()); - sb.append(HandleProviderDelimiter.TYPE.getDelimiter()); - sb.append(NameConvertor.getTypeName(CharOperation.subarray(element, 1, element.length))); - } else if (element[0] == NameConvertor.PARAMETERIZED) { - // its a parameterized type - sb.append(NameConvertor.createShortName(element)); - } else { - sb.append(NameConvertor.getTypeName(element)); - } + sb.append(NameConvertor.createShortName(element, false, false)); } return sb.toString(); } diff --git a/asm/src/org/aspectj/asm/internal/NameConvertor.java b/asm/src/org/aspectj/asm/internal/NameConvertor.java index bd4609979..854039eff 100644 --- a/asm/src/org/aspectj/asm/internal/NameConvertor.java +++ b/asm/src/org/aspectj/asm/internal/NameConvertor.java @@ -10,53 +10,49 @@ *******************************************************************/ package org.aspectj.asm.internal; - public class NameConvertor { - private static final char BOOLEAN = 'Z'; - private static final char BYTE = 'B'; - private static final char CHAR = 'C'; - private static final char DOUBLE = 'D'; - private static final char FLOAT = 'F'; - private static final char INT = 'I'; - private static final char LONG = 'J'; - private static final char SHORT = 'S'; - private static final char ARRAY = '['; + private static final char BOOLEAN = 'Z'; + private static final char BYTE = 'B'; + private static final char CHAR = 'C'; + private static final char DOUBLE = 'D'; + private static final char FLOAT = 'F'; + private static final char INT = 'I'; + 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'}; - private static final char[] CHAR_NAME = new char[]{'c','h','a','r'}; - private static final char[] DOUBLE_NAME = new char[]{'d','o','u','b','l','e'}; - private static final char[] FLOAT_NAME = new char[]{'f','l','o','a','t'}; - private static final char[] INT_NAME = new char[]{'i','n','t'}; - private static final char[] LONG_NAME = new char[]{'l','o','n','g'}; - private static final char[] SHORT_NAME = new char[]{'s','h','o','r','t'}; - - private static final char[] SQUARE_BRACKETS = new char[]{'[',']'}; - 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[]{';'}; - - + + 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' }; + private static final char[] CHAR_NAME = new char[] { 'c', 'h', 'a', 'r' }; + private static final char[] DOUBLE_NAME = new char[] { 'd', 'o', 'u', 'b', 'l', 'e' }; + private static final char[] FLOAT_NAME = new char[] { 'f', 'l', 'o', 'a', 't' }; + private static final char[] INT_NAME = new char[] { 'i', 'n', 't' }; + private static final char[] LONG_NAME = new char[] { 'l', 'o', 'n', 'g' }; + private static final char[] SHORT_NAME = new char[] { 's', 'h', 'o', 'r', 't' }; + + private static final char[] SQUARE_BRACKETS = new char[] { '[', ']' }; + 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[] { ';' }; + /** - * Creates a readable name from the given char array, for example, - * given 'I' returns 'int'. Moreover, given - * 'Ljava/lang/String;<Ljava/lang/String;>' returns - * 'java.lang.String<java.lang.String>' + * Creates a readable name from the given char array, for example, given 'I' returns 'int'. Moreover, given + * 'Ljava/lang/String;<Ljava/lang/String;>' returns 'java.lang.String<java.lang.String>' */ public static char[] convertFromSignature(char[] c) { - int lt = CharOperation.indexOf('<',c); - int sc = CharOperation.indexOf(';',c); - int gt = CharOperation.indexOf('>',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) { + if (lt == -1 && sc == -1 && gt == -1) { // we have something like 'Ljava/lang/String' or 'I' return getFullyQualifiedTypeName(c); } else if (lt != -1 && (sc == -1 || lt <= sc) && (gt == -1 || lt <= gt)) { @@ -69,15 +65,15 @@ public class NameConvertor { // we have something like '>;' smallest = gt; } - char[] first = CharOperation.subarray(c,0,smallest); - char[] second = CharOperation.subarray(c,smallest+1,c.length); + 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 '>' to // close the generic signature return GREATER_THAN; } else if (first.length == 1 && second.length == 0) { return first; - } else if (second.length == 0 || (second.length == 1 && second[0] == ';')){ + } 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 convertFromSignature(first); @@ -85,36 +81,33 @@ public class NameConvertor { // if c = 'Ljava/lang/String;<I' then first = 'Ljava/Lang/String;' and // second = 'I'. Want to end up with 'Ljava.lang.String<I' and so add // the '<' back. - char[] inclLT = CharOperation.concat(convertFromSignature(first),LESS_THAN); - return CharOperation.concat(inclLT,convertFromSignature(second)); + char[] inclLT = CharOperation.concat(convertFromSignature(first), LESS_THAN); + return CharOperation.concat(inclLT, convertFromSignature(second)); } else if (smallest == gt) { - char[] inclLT = CharOperation.concat(convertFromSignature(first),GREATER_THAN); - return CharOperation.concat(inclLT,convertFromSignature(second)); + char[] inclLT = CharOperation.concat(convertFromSignature(first), GREATER_THAN); + return CharOperation.concat(inclLT, convertFromSignature(second)); } else if (second.length != 2) { // if c = 'Ljava/lang/Sting;LMyClass' then first = 'Ljava/lang/String' // and second = 'LMyClass'. Want to end up with 'java.lang.String,MyClass - // so want to add a ','. However, only want to do this if we're in the + // so want to add a ','. However, only want to do this if we're in the // middle of a '<...>' - char[] inclComma = CharOperation.concat(convertFromSignature(first),COMMA); - return CharOperation.concat(inclComma,convertFromSignature(second)); + char[] inclComma = CharOperation.concat(convertFromSignature(first), COMMA); + return CharOperation.concat(inclComma, convertFromSignature(second)); } - return CharOperation.concat(convertFromSignature(first),convertFromSignature(second)); + return CharOperation.concat(convertFromSignature(first), convertFromSignature(second)); } - - + /** - * Given a char array, returns the type name for this. For example - * 'I' returns 'int', 'Ljava/lang/String' returns 'java.lang.String' and - * '[Ljava/lang/String' returns 'java.lang.String[]' + * Given a char array, returns the type name for this. For example 'I' returns 'int', 'Ljava/lang/String' returns + * 'java.lang.String' and '[Ljava/lang/String' returns 'java.lang.String[]' * - * NOTE: Doesn't go any deaper so given 'Ljava/lang/String;<Ljava/lang/String;>' - * it would return 'java.lang.String;<Ljava.lang.String;>', however, only called - * with something like 'Ljava/lang/String' + * NOTE: Doesn't go any deaper so given 'Ljava/lang/String;<Ljava/lang/String;>' it would return + * 'java.lang.String;<Ljava.lang.String;>', however, only called with something like 'Ljava/lang/String' */ private static char[] getFullyQualifiedTypeName(char[] c) { if (c.length == 0) { return c; - } + } if (c[0] == BOOLEAN) { return BOOLEAN_NAME; } else if (c[0] == BYTE) { @@ -132,29 +125,45 @@ public class NameConvertor { } else if (c[0] == SHORT) { return SHORT_NAME; } else if (c[0] == ARRAY) { - return CharOperation.concat( - getFullyQualifiedTypeName(CharOperation.subarray(c,1,c.length)), - SQUARE_BRACKETS); + return CharOperation.concat(getFullyQualifiedTypeName(CharOperation.subarray(c, 1, c.length)), SQUARE_BRACKETS); } else { - char[] type = CharOperation.subarray(c,1,c.length); - CharOperation.replace(type,'/','.'); + char[] type = CharOperation.subarray(c, 1, c.length); + CharOperation.replace(type, '/', '.'); return type; } } - + + // public static char[] createShortName(char[] c) { + // return createShortName(c, false); + // } + /** - * Given 'Ppkg/MyGenericClass<Ljava/lang/String;Ljava/lang/Integer;>;' - * will return 'QMyGenericClass<QString;QInteger;>;' + * Given 'Ppkg/MyGenericClass<Ljava/lang/String;Ljava/lang/Integer;>;' will return 'QMyGenericClass<QString;QInteger;>;' */ - public static char[] createShortName(char[] c) { - int lt = CharOperation.indexOf('<',c); - int sc = CharOperation.indexOf(';',c); - int gt = CharOperation.indexOf('>',c); - + public static char[] createShortName(char[] c, boolean haveFullyQualifiedAtLeastOneThing, boolean needsFullyQualifiedFirstEntry) { + if (c[0] == '[') { + char[] ret = CharOperation.concat(new char[] { '\\', '[' }, createShortName(CharOperation.subarray(c, 1, c.length), + haveFullyQualifiedAtLeastOneThing, needsFullyQualifiedFirstEntry)); + return ret; + } else if (c[0] == '+') { + char[] ret = CharOperation.concat(new char[] { '+' }, createShortName(CharOperation.subarray(c, 1, c.length), + haveFullyQualifiedAtLeastOneThing, needsFullyQualifiedFirstEntry)); + return ret; + } else if (c[0] == '*') { + return c; // c is *>; + } + 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); + if (!needsFullyQualifiedFirstEntry) { + return getTypeName(c, true); + } else { + return getTypeName(c, haveFullyQualifiedAtLeastOneThing); + } } else if (lt != -1 && (sc == -1 || lt <= sc) && (gt == -1 || lt <= gt)) { // we have something like 'Ljava/lang/String<I' smallest = lt; @@ -165,50 +174,78 @@ public class NameConvertor { // we have something like '>;' smallest = gt; } - char[] first = CharOperation.subarray(c,0,smallest); - char[] second = CharOperation.subarray(c,smallest+1,c.length); + 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] == ';')){ + } 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); + return CharOperation.concat(createShortName(first, haveFullyQualifiedAtLeastOneThing, needsFullyQualifiedFirstEntry), + new char[] { ';' }); } else if (smallest == lt) { // if c = 'Ljava/lang/String;<I' then first = 'Ljava/Lang/String;' and // second = 'I'. Want to end up with 'LString<I' and so add // the '<' back. - char[] inclLT = CharOperation.concat(createShortName(first),BACKSLASH_LESSTHAN); - return CharOperation.concat(inclLT,createShortName(second)); + char[] inclLT = CharOperation.concat(createShortName(first, haveFullyQualifiedAtLeastOneThing, true), + BACKSLASH_LESSTHAN); + return CharOperation.concat(inclLT, createShortName(second, true, false)); } else if (smallest == gt) { - char[] inclLT = CharOperation.concat(createShortName(first),GREATER_THAN); - return CharOperation.concat(inclLT,createShortName(second)); + char[] inclLT = CharOperation.concat(createShortName(first, haveFullyQualifiedAtLeastOneThing, + needsFullyQualifiedFirstEntry), GREATER_THAN); + return CharOperation.concat(inclLT, createShortName(second, true, false)); } else { // if c = 'Ljava/lang/Sting;LMyClass;' then first = 'Ljava/lang/String' // and second = 'LMyClass;'. Want to end up with 'QString;QMyClass; // so add the ';' back - char[] firstTypeParam = CharOperation.concat(createShortName(first),SEMICOLON); - return CharOperation.concat(firstTypeParam,createShortName(second)); + char[] firstTypeParam = CharOperation.concat(createShortName(first, haveFullyQualifiedAtLeastOneThing, false), + SEMICOLON); + return CharOperation.concat(firstTypeParam, createShortName(second, true, false)); } } + // public static char[] getTypeName(char[] name) { + // return getTypeName(name, false); + // } + + private static final char[] WILDCARD = new char[] { '+' }; + + /** + * Convert a typename into its handle form. There are various cases to consider here - many are discussed in pr249216. The flag + * allreadyFQd indicates if we've already included a fq'd name in what we are creating - if we have then further references + * should not be fq'd and can be the short name (so java.util.Set becomes just Set). + * + */ + /** * Given 'Qjava/lang/String;' returns 'QString;' */ - public static char[] getTypeName(char[] name) { - int i = CharOperation.lastIndexOf('/',name); - if (i != -1) { + public static char[] getTypeName(char[] name, boolean haveFullyQualifiedAtLeastOneThing) { + if (!haveFullyQualifiedAtLeastOneThing) { if (name[0] == RESOLVED || name[0] == PARAMETERIZED) { - return CharOperation.concat(new char[]{UNRESOLVED}, - CharOperation.subarray(name,i+1,name.length)); + char[] sub = CharOperation.subarray(name, 1, name.length); + CharOperation.replace(sub, '/', '.'); + return CharOperation.concat(new char[] { UNRESOLVED }, sub); } else { - return CharOperation.concat(new char[]{name[0]}, - CharOperation.subarray(name,i+1,name.length)); + char[] sub = CharOperation.subarray(name, 1, name.length); + CharOperation.replace(sub, '/', '.'); + return CharOperation.concat(new char[] { name[0] }, sub); + } + } else { + int i = CharOperation.lastIndexOf('/', name); + if (i != -1) { + if (name[0] == RESOLVED || name[0] == PARAMETERIZED) { + return CharOperation.concat(new char[] { UNRESOLVED }, CharOperation.subarray(name, i + 1, name.length)); + } else { + return CharOperation.concat(new char[] { name[0] }, CharOperation.subarray(name, i + 1, name.length)); + } } } return name; } + } |