<s> package org . eclipse . jdt . core ; import java . util . ArrayList ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . parser . ScannerHelper ; import org . eclipse . jdt . internal . compiler . util . Util ; public final class Signature { public static final int ARRAY_TYPE_SIGNATURE = 4 ; public static final int BASE_TYPE_SIGNATURE = 2 ; private static final char [ ] BOOLEAN = "boolean" . toCharArray ( ) ; private static final char [ ] BYTE = "byte" . toCharArray ( ) ; public static final char C_ARRAY = org . eclipse . jdt . internal . compiler . util . Util . C_ARRAY ; public static final char C_BOOLEAN = org . eclipse . jdt . internal . compiler . util . Util . C_BOOLEAN ; public static final char C_BYTE = org . eclipse . jdt . internal . compiler . util . Util . C_BYTE ; public static final char C_CAPTURE = org . eclipse . jdt . internal . compiler . util . Util . C_CAPTURE ; public static final char C_CHAR = org . eclipse . jdt . internal . compiler . util . Util . C_CHAR ; public static final char C_COLON = org . eclipse . jdt . internal . compiler . util . Util . C_COLON ; public static final char C_DOLLAR = org . eclipse . jdt . internal . compiler . util . Util . C_DOLLAR ; public static final char C_DOT = org . eclipse . jdt . internal . compiler . util . Util . C_DOT ; public static final char C_DOUBLE = org . eclipse . jdt . internal . compiler . util . Util . C_DOUBLE ; public static final char C_EXCEPTION_START = org . eclipse . jdt . internal . compiler . util . Util . C_EXCEPTION_START ; public static final char C_EXTENDS = org . eclipse . jdt . internal . compiler . util . Util . C_EXTENDS ; public static final char C_FLOAT = org . eclipse . jdt . internal . compiler . util . Util . C_FLOAT ; public static final char C_GENERIC_END = org . eclipse . jdt . internal . compiler . util . Util . C_GENERIC_END ; public static final char C_GENERIC_START = org . eclipse . jdt . internal . compiler . util . Util . C_GENERIC_START ; public static final char C_INT = org . eclipse . jdt . internal . compiler . util . Util . C_INT ; public static final char C_INTERSECTION = '|' ; public static final char C_LONG = org . eclipse . jdt . internal . compiler . util . Util . C_LONG ; public static final char C_NAME_END = org . eclipse . jdt . internal . compiler . util . Util . C_NAME_END ; public static final char C_PARAM_END = org . eclipse . jdt . internal . compiler . util . Util . C_PARAM_END ; public static final char C_PARAM_START = org . eclipse . jdt . internal . compiler . util . Util . C_PARAM_START ; public static final char C_RESOLVED = org . eclipse . jdt . internal . compiler . util . Util . C_RESOLVED ; public static final char C_SEMICOLON = org . eclipse . jdt . internal . compiler . util . Util . C_SEMICOLON ; public static final char C_SHORT = org . eclipse . jdt . internal . compiler . util . Util . C_SHORT ; public static final char C_STAR = org . eclipse . jdt . internal . compiler . util . Util . C_STAR ; public static final char C_SUPER = org . eclipse . jdt . internal . compiler . util . Util . C_SUPER ; public static final char C_TYPE_VARIABLE = org . eclipse . jdt . internal . compiler . util . Util . C_TYPE_VARIABLE ; public static final char C_UNRESOLVED = org . eclipse . jdt . internal . compiler . util . Util . C_UNRESOLVED ; public static final char C_VOID = org . eclipse . jdt . internal . compiler . util . Util . C_VOID ; private static final char [ ] CAPTURE = "capture-of" . toCharArray ( ) ; public static final int CAPTURE_TYPE_SIGNATURE = 6 ; private static final char [ ] CHAR = "char" . toCharArray ( ) ; public static final int CLASS_TYPE_SIGNATURE = 1 ; private static final char [ ] DOUBLE = "double" . toCharArray ( ) ; private static final char [ ] EXTENDS = "extends" . toCharArray ( ) ; private static final char [ ] FLOAT = "float" . toCharArray ( ) ; private static final char [ ] INT = "int" . toCharArray ( ) ; public static final int INTERSECTION_TYPE_SIGNATURE = 7 ; private static final char [ ] LONG = "long" . toCharArray ( ) ; private static final char [ ] SHORT = "short" . toCharArray ( ) ; public static final String SIG_BOOLEAN = "Z" ; public static final String SIG_BYTE = "B" ; public static final String SIG_CHAR = "C" ; public static final String SIG_DOUBLE = "D" ; public static final String SIG_FLOAT = "F" ; public static final String SIG_INT = "I" ; public static final String SIG_LONG = "J" ; public static final String SIG_SHORT = "S" ; public static final String SIG_VOID = "V" ; private static final char [ ] SUPER = "super" . toCharArray ( ) ; public static final int TYPE_VARIABLE_SIGNATURE = 3 ; private static final char [ ] VOID = "void" . toCharArray ( ) ; public static final int WILDCARD_TYPE_SIGNATURE = 5 ; private static void appendArgumentSimpleNames ( char [ ] name , int start , int end , StringBuffer buffer ) { buffer . append ( '<' ) ; int depth = 0 ; int argumentStart = - 1 ; int argumentCount = 0 ; for ( int i = start ; i <= end ; i ++ ) { switch ( name [ i ] ) { case '<' : depth ++ ; if ( depth == 1 ) { argumentStart = i + 1 ; } break ; case '>' : if ( depth == 1 ) { if ( argumentCount > 0 ) buffer . append ( ',' ) ; appendSimpleName ( name , argumentStart , i - 1 , buffer ) ; argumentCount ++ ; } depth -- ; break ; case ',' : if ( depth == 1 ) { if ( argumentCount > 0 ) buffer . append ( ',' ) ; appendSimpleName ( name , argumentStart , i - 1 , buffer ) ; argumentCount ++ ; argumentStart = i + 1 ; } break ; } } buffer . append ( '>' ) ; } private static int appendArrayTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { return appendArrayTypeSignature ( string , start , fullyQualifyTypeNames , buffer , false ) ; } private static int appendArrayTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer , boolean isVarArgs ) { int length = string . length ; if ( start >= length - 1 ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( c != C_ARRAY ) { throw new IllegalArgumentException ( ) ; } int index = start ; c = string [ ++ index ] ; while ( c == C_ARRAY ) { if ( index >= length - 1 ) { throw new IllegalArgumentException ( ) ; } c = string [ ++ index ] ; } int e = appendTypeSignature ( string , index , fullyQualifyTypeNames , buffer ) ; for ( int i = 1 , dims = index - start ; i < dims ; i ++ ) { buffer . append ( '[' ) . append ( ']' ) ; } if ( isVarArgs ) { buffer . append ( '.' ) . append ( '.' ) . append ( '.' ) ; } else { buffer . append ( '[' ) . append ( ']' ) ; } return e ; } private static int appendCaptureTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { if ( start >= string . length - 1 ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( c != C_CAPTURE ) { throw new IllegalArgumentException ( ) ; } buffer . append ( CAPTURE ) . append ( ' ' ) ; return appendTypeArgumentSignature ( string , start + 1 , fullyQualifyTypeNames , buffer ) ; } private static int appendClassTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { if ( start >= string . length - 2 ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( c != C_RESOLVED && c != C_UNRESOLVED ) { throw new IllegalArgumentException ( ) ; } boolean resolved = ( c == C_RESOLVED ) ; boolean removePackageQualifiers = ! fullyQualifyTypeNames ; if ( ! resolved ) { removePackageQualifiers = false ; } int p = start + 1 ; int checkpoint = buffer . length ( ) ; int innerTypeStart = - 1 ; boolean inAnonymousType = false ; while ( true ) { if ( p >= string . length ) { throw new IllegalArgumentException ( ) ; } c = string [ p ] ; switch ( c ) { case C_SEMICOLON : return p ; case C_GENERIC_START : int e = appendTypeArgumentSignatures ( string , p , fullyQualifyTypeNames , buffer ) ; removePackageQualifiers = false ; p = e ; break ; case C_DOT : if ( removePackageQualifiers ) { buffer . setLength ( checkpoint ) ; } else { buffer . append ( '.' ) ; } break ; case '/' : if ( removePackageQualifiers ) { buffer . setLength ( checkpoint ) ; } else { buffer . append ( '/' ) ; } break ; case C_DOLLAR : innerTypeStart = buffer . length ( ) ; inAnonymousType = false ; if ( resolved ) { removePackageQualifiers = false ; buffer . append ( '.' ) ; } break ; default : if ( innerTypeStart != - 1 && ! inAnonymousType && Character . isDigit ( c ) ) { inAnonymousType = true ; buffer . setLength ( innerTypeStart ) ; buffer . insert ( checkpoint , "new " ) ; buffer . append ( "(){}" ) ; } if ( ! inAnonymousType ) buffer . append ( c ) ; innerTypeStart = - 1 ; } p ++ ; } } private static int appendIntersectionTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { if ( start >= string . length - 1 ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( c != C_INTERSECTION ) { throw new IllegalArgumentException ( ) ; } start = appendClassTypeSignature ( string , start + 1 , fullyQualifyTypeNames , buffer ) ; if ( start < string . length - 1 ) { start ++ ; if ( string [ start ] != C_COLON ) { throw new IllegalArgumentException ( "" ) ; } while ( string [ start ] == C_COLON ) { buffer . append ( " | " ) ; start = appendClassTypeSignature ( string , start + 1 , fullyQualifyTypeNames , buffer ) ; if ( start == string . length - 1 ) { return start ; } else if ( start > string . length - 1 ) { throw new IllegalArgumentException ( "" ) ; } start ++ ; } } return start ; } private static void appendSimpleName ( char [ ] name , int start , int end , StringBuffer buffer ) { int lastDot = - 1 , lastGenericStart = - 1 , lastGenericEnd = - 1 ; int depth = 0 ; if ( name [ start ] == '?' ) { buffer . append ( "?" ) ; int index = consumeWhitespace ( name , start + 1 , end + 1 ) ; switch ( name [ index ] ) { case 'e' : int checkPos = checkName ( EXTENDS , name , index , end ) ; if ( checkPos > 0 ) { buffer . append ( ' ' ) . append ( EXTENDS ) . append ( ' ' ) ; index = consumeWhitespace ( name , checkPos , end + 1 ) ; } break ; case 's' : checkPos = checkName ( SUPER , name , index , end + 1 ) ; if ( checkPos > 0 ) { buffer . append ( ' ' ) . append ( SUPER ) . append ( ' ' ) ; index = consumeWhitespace ( name , checkPos , end + 1 ) ; } break ; } start = index ; } lastDotLookup : for ( int i = end ; i >= start ; i -- ) { switch ( name [ i ] ) { case '.' : if ( depth == 0 ) { lastDot = i ; char c = name [ start ] ; if ( c == C_EXTENDS || c == C_SUPER ) { buffer . append ( c ) ; } break lastDotLookup ; } break ; case '<' : depth -- ; if ( depth == 0 ) lastGenericStart = i ; break ; case '>' : if ( depth == 0 ) lastGenericEnd = i ; depth ++ ; break ; } } int nameStart = lastDot < 0 ? start : lastDot + 1 ; int nameEnd = lastGenericStart < 0 ? end + 1 : lastGenericStart ; buffer . append ( name , nameStart , nameEnd - nameStart ) ; if ( lastGenericStart >= 0 ) { appendArgumentSimpleNames ( name , lastGenericStart , lastGenericEnd , buffer ) ; buffer . append ( name , lastGenericEnd + 1 , end - lastGenericEnd ) ; } } private static int appendTypeArgumentSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { if ( start >= string . length ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; switch ( c ) { case C_STAR : buffer . append ( '?' ) ; return start ; case C_EXTENDS : buffer . append ( "? extends " ) ; return appendTypeSignature ( string , start + 1 , fullyQualifyTypeNames , buffer ) ; case C_SUPER : buffer . append ( "? super " ) ; return appendTypeSignature ( string , start + 1 , fullyQualifyTypeNames , buffer ) ; default : return appendTypeSignature ( string , start , fullyQualifyTypeNames , buffer ) ; } } private static int appendTypeArgumentSignatures ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { if ( start >= string . length - 1 ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( c != C_GENERIC_START ) { throw new IllegalArgumentException ( ) ; } buffer . append ( '<' ) ; int p = start + 1 ; int count = 0 ; while ( true ) { if ( p >= string . length ) { throw new IllegalArgumentException ( ) ; } c = string [ p ] ; if ( c == C_GENERIC_END ) { buffer . append ( '>' ) ; return p ; } if ( count != 0 ) { buffer . append ( ',' ) ; } int e = appendTypeArgumentSignature ( string , p , fullyQualifyTypeNames , buffer ) ; count ++ ; p = e + 1 ; } } private static int appendTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer ) { return appendTypeSignature ( string , start , fullyQualifyTypeNames , buffer , false ) ; } private static int appendTypeSignature ( char [ ] string , int start , boolean fullyQualifyTypeNames , StringBuffer buffer , boolean isVarArgs ) { if ( start >= string . length ) { throw new IllegalArgumentException ( ) ; } char c = string [ start ] ; if ( isVarArgs ) { switch ( c ) { case C_ARRAY : return appendArrayTypeSignature ( string , start , fullyQualifyTypeNames , buffer , true ) ; case C_RESOLVED : case C_UNRESOLVED : case C_TYPE_VARIABLE : case C_BOOLEAN : case C_BYTE : case C_CHAR : case C_DOUBLE : case C_FLOAT : case C_INT : case C_LONG : case C_SHORT : case C_VOID : case C_STAR : case C_EXTENDS : case C_SUPER : case C_CAPTURE : case C_INTERSECTION : default : throw new IllegalArgumentException ( ) ; } } else { switch ( c ) { case C_ARRAY : return appendArrayTypeSignature ( string , start , fullyQualifyTypeNames , buffer ) ; case C_RESOLVED : case C_UNRESOLVED : return appendClassTypeSignature ( string , start , fullyQualifyTypeNames , buffer ) ; case C_TYPE_VARIABLE : int e = Util . scanTypeVariableSignature ( string , start ) ; buffer . append ( string , start + 1 , e - start - 1 ) ; return e ; case C_BOOLEAN : buffer . append ( BOOLEAN ) ; return start ; case C_BYTE : buffer . append ( BYTE ) ; return start ; case C_CHAR : buffer . append ( CHAR ) ; return start ; case C_DOUBLE : buffer . append ( DOUBLE ) ; return start ; case C_FLOAT : buffer . append ( FLOAT ) ; return start ; case C_INT : buffer . append ( INT ) ; return start ; case C_LONG : buffer . append ( LONG ) ; return start ; case C_SHORT : buffer . append ( SHORT ) ; return start ; case C_VOID : buffer . append ( VOID ) ; return start ; case C_CAPTURE : return appendCaptureTypeSignature ( string , start , fullyQualifyTypeNames , buffer ) ; case C_INTERSECTION : return appendIntersectionTypeSignature ( string , start , fullyQualifyTypeNames , buffer ) ; case C_STAR : case C_EXTENDS : case C_SUPER : return appendTypeArgumentSignature ( string , start , fullyQualifyTypeNames , buffer ) ; default : throw new IllegalArgumentException ( ) ; } } } private static int checkArrayDimension ( char [ ] typeName , int pos , int length ) { int genericBalance = 0 ; while ( pos < length ) { switch ( typeName [ pos ] ) { case '<' : genericBalance ++ ; break ; case ',' : if ( genericBalance == 0 ) return - 1 ; break ; case '>' : if ( genericBalance == 0 ) return - 1 ; genericBalance -- ; break ; case '[' : if ( genericBalance == 0 ) { return pos ; } } pos ++ ; } return - 1 ; } private static int checkName ( char [ ] name , char [ ] typeName , int pos , int length ) { if ( CharOperation . fragmentEquals ( name , typeName , pos , true ) ) { pos += name . length ; if ( pos == length ) return pos ; char currentChar = typeName [ pos ] ; switch ( currentChar ) { case ' ' : case '.' : case '<' : case '>' : case '[' : case ',' : return pos ; default : if ( ScannerHelper . isWhitespace ( currentChar ) ) return pos ; } } return - 1 ; } private static int checkNextChar ( char [ ] typeName , char expectedChar , int pos , int length , boolean isOptional ) { pos = consumeWhitespace ( typeName , pos , length ) ; if ( pos < length && typeName [ pos ] == expectedChar ) return pos + 1 ; if ( ! isOptional ) throw new IllegalArgumentException ( new String ( typeName ) ) ; return - 1 ; } private static int consumeWhitespace ( char [ ] typeName , int pos , int length ) { while ( pos < length ) { char currentChar = typeName [ pos ] ; if ( currentChar != ' ' && ! ScannerHelper . isWhitespace ( currentChar ) ) { break ; } pos ++ ; } return pos ; } public static char [ ] createArraySignature ( char [ ] typeSignature , int arrayCount ) { if ( arrayCount == 0 ) return typeSignature ; int sigLength = typeSignature . length ; char [ ] result = new char [ arrayCount + sigLength ] ; for ( int i = 0 ; i < arrayCount ; i ++ ) { result [ i ] = C_ARRAY ; } System . arraycopy ( typeSignature , 0 , result , arrayCount , sigLength ) ; return result ; } public static String createArraySignature ( String typeSignature , int arrayCount ) { return new String ( createArraySignature ( typeSignature . toCharArray ( ) , arrayCount ) ) ; } public static char [ ] createCharArrayTypeSignature ( char [ ] typeName , boolean isResolved ) { if ( typeName == null ) throw new IllegalArgumentException ( "null" ) ; int length = typeName . length ; if ( length == 0 ) throw new IllegalArgumentException ( new String ( typeName ) ) ; StringBuffer buffer = new StringBuffer ( 5 ) ; int pos = encodeTypeSignature ( typeName , 0 , isResolved , length , buffer ) ; pos = consumeWhitespace ( typeName , pos , length ) ; if ( pos < length ) throw new IllegalArgumentException ( new String ( typeName ) ) ; char [ ] result = new char [ length = buffer . length ( ) ] ; buffer . getChars ( 0 , length , result , 0 ) ; return result ; } public static String createIntersectionTypeSignature ( char [ ] [ ] typeSignatures ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( Signature . C_INTERSECTION ) ; for ( int i = 0 , max = typeSignatures . length ; i < max ; i ++ ) { if ( i > 0 ) { buffer . append ( Signature . C_COLON ) ; } buffer . append ( typeSignatures [ i ] ) ; } return String . valueOf ( buffer ) ; } public static String createIntersectionTypeSignature ( String [ ] typeSignatures ) { int typeSignaturesLenth = typeSignatures . length ; char [ ] [ ] signatures = new char [ typeSignaturesLenth ] [ ] ; for ( int i = 0 ; i < typeSignaturesLenth ; i ++ ) { signatures [ i ] = typeSignatures [ i ] . toCharArray ( ) ; } return createIntersectionTypeSignature ( signatures ) ; } public static char [ ] createMethodSignature ( char [ ] [ ] parameterTypes , char [ ] returnType ) { int parameterTypesLength = parameterTypes . length ; int parameterLength = 0 ; for ( int i = 0 ; i < parameterTypesLength ; i ++ ) { parameterLength += parameterTypes [ i ] . length ; } int returnTypeLength = returnType . length ; char [ ] result = new char [ 1 + parameterLength + 1 + returnTypeLength ] ; result [ 0 ] = C_PARAM_START ; int index = 1 ; for ( int i = 0 ; i < parameterTypesLength ; i ++ ) { char [ ] parameterType = parameterTypes [ i ] ; int length = parameterType . length ; System . arraycopy ( parameterType , 0 , result , index , length ) ; index += length ; } result [ index ] = C_PARAM_END ; System . arraycopy ( returnType , 0 , result , index + 1 , returnTypeLength ) ; return result ; } public static String createMethodSignature ( String [ ] parameterTypes , String returnType ) { int parameterTypesLenth = parameterTypes . length ; char [ ] [ ] parameters = new char [ parameterTypesLenth ] [ ] ; for ( int i = 0 ; i < parameterTypesLenth ; i ++ ) { parameters [ i ] = parameterTypes [ i ] . toCharArray ( ) ; } return new String ( createMethodSignature ( parameters , returnType . toCharArray ( ) ) ) ; } public static char [ ] createTypeParameterSignature ( char [ ] typeParameterName , char [ ] [ ] boundSignatures ) { int length = boundSignatures . length ; if ( length == 0 ) { return CharOperation . append ( typeParameterName , C_COLON ) ; } int boundsSize = 0 ; for ( int i = 0 ; i < length ; i ++ ) { boundsSize += boundSignatures [ i ] . length + 1 ; } int nameLength = typeParameterName . length ; char [ ] result = new char [ nameLength + boundsSize ] ; System . arraycopy ( typeParameterName , 0 , result , 0 , nameLength ) ; int index = nameLength ; for ( int i = 0 ; i < length ; i ++ ) { result [ index ++ ] = C_COLON ; int boundLength = boundSignatures [ i ] . length ; System . arraycopy ( boundSignatures [ i ] , 0 , result , index , boundLength ) ; index += boundLength ; } return result ; } public static String createTypeParameterSignature ( String typeParameterName , String [ ] boundSignatures ) { int length = boundSignatures . length ; char [ ] [ ] boundSignatureChars = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { boundSignatureChars [ i ] = boundSignatures [ i ] . toCharArray ( ) ; } return new String ( createTypeParameterSignature ( typeParameterName . toCharArray ( ) , boundSignatureChars ) ) ; } public static String createTypeSignature ( char [ ] typeName , boolean isResolved ) { return new String ( createCharArrayTypeSignature ( typeName , isResolved ) ) ; } public static String createTypeSignature ( String typeName , boolean isResolved ) { return createTypeSignature ( typeName == null ? null : typeName . toCharArray ( ) , isResolved ) ; } private static int encodeArrayDimension ( char [ ] typeName , int pos , int length , StringBuffer buffer ) { int checkPos ; while ( pos < length && ( checkPos = checkNextChar ( typeName , '[' , pos , length , true ) ) > 0 ) { pos = checkNextChar ( typeName , ']' , checkPos , length , false ) ; buffer . append ( C_ARRAY ) ; } return pos ; } private static int encodeQualifiedName ( char [ ] typeName , int pos , int length , StringBuffer buffer ) { int count = 0 ; char lastAppendedChar = 0 ; nameLoop : while ( pos < length ) { char currentChar = typeName [ pos ] ; switch ( currentChar ) { case '<' : case '>' : case '[' : case ',' : break nameLoop ; case '.' : buffer . append ( C_DOT ) ; lastAppendedChar = C_DOT ; count ++ ; break ; default : if ( currentChar == ' ' || ScannerHelper . isWhitespace ( currentChar ) ) { if ( lastAppendedChar == C_DOT ) { pos = consumeWhitespace ( typeName , pos , length ) - 1 ; break ; } int checkPos = checkNextChar ( typeName , '.' , pos , length , true ) ; if ( checkPos > 0 ) { buffer . append ( C_DOT ) ; lastAppendedChar = C_DOT ; count ++ ; pos = checkPos ; break ; } break nameLoop ; } buffer . append ( currentChar ) ; lastAppendedChar = currentChar ; count ++ ; break ; } pos ++ ; } if ( count == 0 ) throw new IllegalArgumentException ( new String ( typeName ) ) ; return pos ; } private static int encodeTypeSignature ( char [ ] typeName , int start , boolean isResolved , int length , StringBuffer buffer ) { int pos = start ; pos = consumeWhitespace ( typeName , pos , length ) ; if ( pos >= length ) throw new IllegalArgumentException ( new String ( typeName ) ) ; int checkPos ; char currentChar = typeName [ pos ] ; switch ( currentChar ) { case 'b' : checkPos = checkName ( BOOLEAN , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_BOOLEAN ) ; return pos ; } checkPos = checkName ( BYTE , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_BYTE ) ; return pos ; } break ; case 'd' : checkPos = checkName ( DOUBLE , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_DOUBLE ) ; return pos ; } break ; case 'f' : checkPos = checkName ( FLOAT , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_FLOAT ) ; return pos ; } break ; case 'i' : checkPos = checkName ( INT , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_INT ) ; return pos ; } break ; case 'l' : checkPos = checkName ( LONG , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_LONG ) ; return pos ; } break ; case 's' : checkPos = checkName ( SHORT , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_SHORT ) ; return pos ; } break ; case 'v' : checkPos = checkName ( VOID , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_VOID ) ; return pos ; } break ; case 'c' : checkPos = checkName ( CHAR , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; buffer . append ( C_CHAR ) ; return pos ; } else { checkPos = checkName ( CAPTURE , typeName , pos , length ) ; if ( checkPos > 0 ) { pos = consumeWhitespace ( typeName , checkPos , length ) ; if ( typeName [ pos ] != '?' ) { break ; } } else { break ; } } buffer . append ( C_CAPTURE ) ; case '?' : pos = consumeWhitespace ( typeName , pos + 1 , length ) ; checkPos = checkName ( EXTENDS , typeName , pos , length ) ; if ( checkPos > 0 ) { buffer . append ( C_EXTENDS ) ; pos = encodeTypeSignature ( typeName , checkPos , isResolved , length , buffer ) ; return pos ; } checkPos = checkName ( SUPER , typeName , pos , length ) ; if ( checkPos > 0 ) { buffer . append ( C_SUPER ) ; pos = encodeTypeSignature ( typeName , checkPos , isResolved , length , buffer ) ; return pos ; } buffer . append ( C_STAR ) ; return pos ; } checkPos = checkArrayDimension ( typeName , pos , length ) ; int end ; if ( checkPos > 0 ) { end = encodeArrayDimension ( typeName , checkPos , length , buffer ) ; } else { end = - 1 ; } buffer . append ( isResolved ? C_RESOLVED : C_UNRESOLVED ) ; while ( true ) { pos = encodeQualifiedName ( typeName , pos , length , buffer ) ; checkPos = checkNextChar ( typeName , '<' , pos , length , true ) ; if ( checkPos > 0 ) { buffer . append ( C_GENERIC_START ) ; if ( ( pos = checkNextChar ( typeName , '>' , checkPos , length , true ) ) > 0 ) { buffer . append ( C_GENERIC_END ) ; } else { pos = encodeTypeSignature ( typeName , checkPos , isResolved , length , buffer ) ; while ( ( checkPos = checkNextChar ( typeName , ',' , pos , length , true ) ) > 0 ) { pos = encodeTypeSignature ( typeName , checkPos , isResolved , length , buffer ) ; } pos = checkNextChar ( typeName , '>' , pos , length , false ) ; buffer . append ( C_GENERIC_END ) ; } } checkPos = checkNextChar ( typeName , '.' , pos , length , true ) ; if ( checkPos > 0 ) { buffer . append ( C_DOT ) ; pos = checkPos ; } else { break ; } } buffer . append ( C_NAME_END ) ; if ( end > 0 ) pos = end ; return pos ; } public static int getArrayCount ( char [ ] typeSignature ) throws IllegalArgumentException { try { int count = 0 ; while ( typeSignature [ count ] == C_ARRAY ) { ++ count ; } return count ; } catch ( ArrayIndexOutOfBoundsException e ) { throw new IllegalArgumentException ( ) ; } } public static int getArrayCount ( String typeSignature ) throws IllegalArgumentException { return getArrayCount ( typeSignature . toCharArray ( ) ) ; } public static char [ ] getElementType ( char [ ] typeSignature ) throws IllegalArgumentException { int count = getArrayCount ( typeSignature ) ; if ( count == 0 ) return typeSignature ; int length = typeSignature . length ; char [ ] result = new char [ length - count ] ; System . arraycopy ( typeSignature , count , result , 0 , length - count ) ; return result ; } public static String getElementType ( String typeSignature ) throws IllegalArgumentException { char [ ] signature = typeSignature . toCharArray ( ) ; char [ ] elementType = getElementType ( signature ) ; return signature == elementType ? typeSignature : new String ( elementType ) ; } public static char [ ] [ ] getIntersectionTypeBounds ( char [ ] intersectionTypeSignature ) throws IllegalArgumentException { if ( getTypeSignatureKind ( intersectionTypeSignature ) != INTERSECTION_TYPE_SIGNATURE ) { return CharOperation . NO_CHAR_CHAR ; } ArrayList args = new ArrayList ( ) ; int i = 1 ; int length = intersectionTypeSignature . length ; for ( ; ; ) { int e = Util . scanClassTypeSignature ( intersectionTypeSignature , i ) ; if ( e < 0 ) { throw new IllegalArgumentException ( "" ) ; } args . add ( CharOperation . subarray ( intersectionTypeSignature , i , e + 1 ) ) ; if ( e == length - 1 ) { int size = args . size ( ) ; char [ ] [ ] result = new char [ size ] [ ] ; args . toArray ( result ) ; return result ; } else if ( intersectionTypeSignature [ e + 1 ] != C_COLON ) { throw new IllegalArgumentException ( "" ) ; } i = e + 2 ; } } public static String [ ] getIntersectionTypeBounds ( String intersectionTypeSignature ) throws IllegalArgumentException { char [ ] [ ] args = getIntersectionTypeBounds ( intersectionTypeSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( args ) ; } public static int getParameterCount ( char [ ] methodSignature ) throws IllegalArgumentException { try { int count = 0 ; int i = CharOperation . indexOf ( C_PARAM_START , methodSignature ) ; if ( i < 0 ) { throw new IllegalArgumentException ( ) ; } else { i ++ ; } for ( ; ; ) { if ( methodSignature [ i ] == C_PARAM_END ) { return count ; } int e = Util . scanTypeSignature ( methodSignature , i ) ; if ( e < 0 ) { throw new IllegalArgumentException ( ) ; } else { i = e + 1 ; } count ++ ; } } catch ( ArrayIndexOutOfBoundsException e ) { throw new IllegalArgumentException ( ) ; } } public static int getParameterCount ( String methodSignature ) throws IllegalArgumentException { return getParameterCount ( methodSignature . toCharArray ( ) ) ; } public static char [ ] [ ] getParameterTypes ( char [ ] methodSignature ) throws IllegalArgumentException { try { int count = getParameterCount ( methodSignature ) ; char [ ] [ ] result = new char [ count ] [ ] ; if ( count == 0 ) { return result ; } int i = CharOperation . indexOf ( C_PARAM_START , methodSignature ) ; if ( i < 0 ) { throw new IllegalArgumentException ( ) ; } else { i ++ ; } int t = 0 ; for ( ; ; ) { if ( methodSignature [ i ] == C_PARAM_END ) { return result ; } int e = Util . scanTypeSignature ( methodSignature , i ) ; if ( e < 0 ) { throw new IllegalArgumentException ( ) ; } result [ t ] = CharOperation . subarray ( methodSignature , i , e + 1 ) ; t ++ ; i = e + 1 ; } } catch ( ArrayIndexOutOfBoundsException e ) { throw new IllegalArgumentException ( ) ; } } public static String [ ] getParameterTypes ( String methodSignature ) throws IllegalArgumentException { char [ ] [ ] parameterTypes = getParameterTypes ( methodSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( parameterTypes ) ; } public static char [ ] getQualifier ( char [ ] name ) { int firstGenericStart = CharOperation . indexOf ( C_GENERIC_START , name ) ; int lastDot = CharOperation . lastIndexOf ( C_DOT , name , 0 , firstGenericStart == - 1 ? name . length - 1 : firstGenericStart ) ; if ( lastDot == - 1 ) { return CharOperation . NO_CHAR ; } return CharOperation . subarray ( name , 0 , lastDot ) ; } public static String getQualifier ( String name ) { char [ ] qualifier = getQualifier ( name . toCharArray ( ) ) ; if ( qualifier . length == 0 ) return org . eclipse . jdt . internal . compiler . util . Util . EMPTY_STRING ; return new String ( qualifier ) ; } public static char [ ] getReturnType ( char [ ] methodSignature ) throws IllegalArgumentException { int paren = CharOperation . lastIndexOf ( C_PARAM_END , methodSignature ) ; if ( paren == - 1 ) { throw new IllegalArgumentException ( ) ; } int last = Util . scanTypeSignature ( methodSignature , paren + 1 ) ; return CharOperation . subarray ( methodSignature , paren + 1 , last + 1 ) ; } public static String getReturnType ( String methodSignature ) throws IllegalArgumentException { return new String ( getReturnType ( methodSignature . toCharArray ( ) ) ) ; } public static char [ ] getSignatureQualifier ( char [ ] typeSignature ) { if ( typeSignature == null ) return CharOperation . NO_CHAR ; char [ ] qualifiedType = Signature . toCharArray ( typeSignature ) ; int dotCount = 0 ; indexFound : for ( int i = 0 ; i < typeSignature . length ; i ++ ) { switch ( typeSignature [ i ] ) { case C_DOT : dotCount ++ ; break ; case C_GENERIC_START : break indexFound ; case C_DOLLAR : break indexFound ; } } if ( dotCount > 0 ) { for ( int i = 0 ; i < qualifiedType . length ; i ++ ) { if ( qualifiedType [ i ] == '.' ) { dotCount -- ; } if ( dotCount <= 0 ) { return CharOperation . subarray ( qualifiedType , 0 , i ) ; } } } return CharOperation . NO_CHAR ; } public static String getSignatureQualifier ( String typeSignature ) { return new String ( getSignatureQualifier ( typeSignature == null ? null : typeSignature . toCharArray ( ) ) ) ; } public static char [ ] getSignatureSimpleName ( char [ ] typeSignature ) { if ( typeSignature == null ) return CharOperation . NO_CHAR ; char [ ] qualifiedType = Signature . toCharArray ( typeSignature ) ; int dotCount = 0 ; indexFound : for ( int i = 0 ; i < typeSignature . length ; i ++ ) { switch ( typeSignature [ i ] ) { case C_DOT : dotCount ++ ; break ; case C_GENERIC_START : break indexFound ; case C_DOLLAR : break indexFound ; } } if ( dotCount > 0 ) { for ( int i = 0 ; i < qualifiedType . length ; i ++ ) { if ( qualifiedType [ i ] == '.' ) { dotCount -- ; } if ( dotCount <= 0 ) { return CharOperation . subarray ( qualifiedType , i + 1 , qualifiedType . length ) ; } } } return qualifiedType ; } public static String getSignatureSimpleName ( String typeSignature ) { return new String ( getSignatureSimpleName ( typeSignature == null ? null : typeSignature . toCharArray ( ) ) ) ; } public static char [ ] getSimpleName ( char [ ] name ) { int lastDot = - 1 , lastGenericStart = - 1 , lastGenericEnd = - 1 ; int depth = 0 ; int length = name . length ; lastDotLookup : for ( int i = length - 1 ; i >= 0 ; i -- ) { switch ( name [ i ] ) { case '.' : if ( depth == 0 ) { lastDot = i ; break lastDotLookup ; } break ; case '<' : depth -- ; if ( depth == 0 ) lastGenericStart = i ; break ; case '>' : if ( depth == 0 ) lastGenericEnd = i ; depth ++ ; break ; } } if ( lastGenericStart < 0 ) { if ( lastDot < 0 ) { return name ; } return CharOperation . subarray ( name , lastDot + 1 , length ) ; } StringBuffer buffer = new StringBuffer ( 10 ) ; int nameStart = lastDot < 0 ? 0 : lastDot + 1 ; buffer . append ( name , nameStart , lastGenericStart - nameStart ) ; appendArgumentSimpleNames ( name , lastGenericStart , lastGenericEnd , buffer ) ; buffer . append ( name , lastGenericEnd + 1 , length - lastGenericEnd - 1 ) ; char [ ] result = new char [ length = buffer . length ( ) ] ; buffer . getChars ( 0 , length , result , 0 ) ; return result ; } public static String getSimpleName ( String name ) { int lastDot = - 1 , lastGenericStart = - 1 , lastGenericEnd = - 1 ; int depth = 0 ; int length = name . length ( ) ; lastDotLookup : for ( int i = length - 1 ; i >= 0 ; i -- ) { switch ( name . charAt ( i ) ) { case '.' : if ( depth == 0 ) { lastDot = i ; break lastDotLookup ; } break ; case '<' : depth -- ; if ( depth == 0 ) lastGenericStart = i ; break ; case '>' : if ( depth == 0 ) lastGenericEnd = i ; depth ++ ; break ; } } if ( lastGenericStart < 0 ) { if ( lastDot < 0 ) { return name ; } return name . substring ( lastDot + 1 , length ) ; } StringBuffer buffer = new StringBuffer ( 10 ) ; char [ ] nameChars = name . toCharArray ( ) ; int nameStart = lastDot < 0 ? 0 : lastDot + 1 ; buffer . append ( nameChars , nameStart , lastGenericStart - nameStart ) ; appendArgumentSimpleNames ( nameChars , lastGenericStart , lastGenericEnd , buffer ) ; buffer . append ( nameChars , lastGenericEnd + 1 , length - lastGenericEnd - 1 ) ; return buffer . toString ( ) ; } public static char [ ] [ ] getSimpleNames ( char [ ] name ) { int length = name == null ? 0 : name . length ; if ( length == 0 ) return CharOperation . NO_CHAR_CHAR ; int wordCount = 1 ; countingWords : for ( int i = 0 ; i < length ; i ++ ) switch ( name [ i ] ) { case C_DOT : wordCount ++ ; break ; case C_GENERIC_START : break countingWords ; } char [ ] [ ] split = new char [ wordCount ] [ ] ; int last = 0 , currentWord = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( name [ i ] == C_GENERIC_START ) break ; if ( name [ i ] == C_DOT ) { split [ currentWord ] = new char [ i - last ] ; System . arraycopy ( name , last , split [ currentWord ++ ] , 0 , i - last ) ; last = i + 1 ; } } split [ currentWord ] = new char [ length - last ] ; System . arraycopy ( name , last , split [ currentWord ] , 0 , length - last ) ; return split ; } public static String [ ] getSimpleNames ( String name ) { return CharOperation . toStrings ( getSimpleNames ( name . toCharArray ( ) ) ) ; } public static char [ ] [ ] getThrownExceptionTypes ( char [ ] methodSignature ) throws IllegalArgumentException { int exceptionStart = CharOperation . indexOf ( C_EXCEPTION_START , methodSignature ) ; if ( exceptionStart == - 1 ) { int paren = CharOperation . lastIndexOf ( C_PARAM_END , methodSignature ) ; if ( paren == - 1 ) { throw new IllegalArgumentException ( ) ; } exceptionStart = Util . scanTypeSignature ( methodSignature , paren + 1 ) + 1 ; int length = methodSignature . length ; if ( exceptionStart == length ) return CharOperation . NO_CHAR_CHAR ; throw new IllegalArgumentException ( ) ; } int length = methodSignature . length ; int i = exceptionStart ; ArrayList exceptionList = new ArrayList ( 1 ) ; while ( i < length ) { if ( methodSignature [ i ] == C_EXCEPTION_START ) { exceptionStart ++ ; i ++ ; } else { throw new IllegalArgumentException ( ) ; } i = Util . scanTypeSignature ( methodSignature , i ) + 1 ; exceptionList . add ( CharOperation . subarray ( methodSignature , exceptionStart , i ) ) ; exceptionStart = i ; } char [ ] [ ] result ; exceptionList . toArray ( result = new char [ exceptionList . size ( ) ] [ ] ) ; return result ; } public static String [ ] getThrownExceptionTypes ( String methodSignature ) throws IllegalArgumentException { char [ ] [ ] parameterTypes = getThrownExceptionTypes ( methodSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( parameterTypes ) ; } public static char [ ] [ ] getTypeArguments ( char [ ] parameterizedTypeSignature ) throws IllegalArgumentException { int length = parameterizedTypeSignature . length ; if ( length < 2 || parameterizedTypeSignature [ length - 2 ] != C_GENERIC_END ) return CharOperation . NO_CHAR_CHAR ; int count = 1 ; int start = length - 2 ; while ( start >= 0 && count > 0 ) { switch ( parameterizedTypeSignature [ -- start ] ) { case C_GENERIC_START : count -- ; break ; case C_GENERIC_END : count ++ ; break ; } } if ( start < 0 ) throw new IllegalArgumentException ( ) ; ArrayList args = new ArrayList ( ) ; int p = start + 1 ; while ( true ) { if ( p >= parameterizedTypeSignature . length ) { throw new IllegalArgumentException ( ) ; } char c = parameterizedTypeSignature [ p ] ; if ( c == C_GENERIC_END ) { int size = args . size ( ) ; char [ ] [ ] result = new char [ size ] [ ] ; args . toArray ( result ) ; return result ; } int e = Util . scanTypeArgumentSignature ( parameterizedTypeSignature , p ) ; args . add ( CharOperation . subarray ( parameterizedTypeSignature , p , e + 1 ) ) ; p = e + 1 ; } } public static String [ ] getTypeArguments ( String parameterizedTypeSignature ) throws IllegalArgumentException { char [ ] [ ] args = getTypeArguments ( parameterizedTypeSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( args ) ; } public static char [ ] getTypeErasure ( char [ ] parameterizedTypeSignature ) throws IllegalArgumentException { int end = CharOperation . indexOf ( C_GENERIC_START , parameterizedTypeSignature ) ; if ( end == - 1 ) return parameterizedTypeSignature ; int length = parameterizedTypeSignature . length ; char [ ] result = new char [ length ] ; int pos = 0 ; int start = 0 ; int deep = 0 ; for ( int idx = end ; idx < length ; idx ++ ) { switch ( parameterizedTypeSignature [ idx ] ) { case C_GENERIC_START : if ( deep == 0 ) { int size = idx - start ; System . arraycopy ( parameterizedTypeSignature , start , result , pos , size ) ; end = idx ; pos += size ; } deep ++ ; break ; case C_GENERIC_END : deep -- ; if ( deep < 0 ) throw new IllegalArgumentException ( ) ; if ( deep == 0 ) start = idx + 1 ; break ; } } if ( deep > 0 ) throw new IllegalArgumentException ( ) ; int size = pos + length - start ; char [ ] resized = new char [ size ] ; System . arraycopy ( result , 0 , resized , 0 , pos ) ; System . arraycopy ( parameterizedTypeSignature , start , resized , pos , length - start ) ; return resized ; } public static String getTypeErasure ( String parameterizedTypeSignature ) throws IllegalArgumentException { char [ ] signature = parameterizedTypeSignature . toCharArray ( ) ; char [ ] erasure = getTypeErasure ( signature ) ; return signature == erasure ? parameterizedTypeSignature : new String ( erasure ) ; } public static char [ ] [ ] getTypeParameterBounds ( char [ ] formalTypeParameterSignature ) throws IllegalArgumentException { int p1 = CharOperation . indexOf ( C_COLON , formalTypeParameterSignature ) ; if ( p1 < 0 ) { throw new IllegalArgumentException ( ) ; } if ( p1 == formalTypeParameterSignature . length - 1 ) { return CharOperation . NO_CHAR_CHAR ; } int p2 = CharOperation . indexOf ( C_COLON , formalTypeParameterSignature , p1 + 1 ) ; char [ ] classBound ; if ( p2 < 0 ) { classBound = CharOperation . subarray ( formalTypeParameterSignature , p1 + 1 , formalTypeParameterSignature . length ) ; return new char [ ] [ ] { classBound } ; } if ( p2 == p1 + 1 ) { classBound = null ; } else { classBound = CharOperation . subarray ( formalTypeParameterSignature , p1 + 1 , p2 ) ; } char [ ] [ ] interfaceBounds = CharOperation . splitOn ( C_COLON , formalTypeParameterSignature , p2 + 1 , formalTypeParameterSignature . length ) ; if ( classBound == null ) { return interfaceBounds ; } int resultLength = interfaceBounds . length + 1 ; char [ ] [ ] result = new char [ resultLength ] [ ] ; result [ 0 ] = classBound ; System . arraycopy ( interfaceBounds , 0 , result , 1 , interfaceBounds . length ) ; return result ; } public static String [ ] getTypeParameterBounds ( String formalTypeParameterSignature ) throws IllegalArgumentException { char [ ] [ ] bounds = getTypeParameterBounds ( formalTypeParameterSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( bounds ) ; } public static char [ ] [ ] getTypeParameters ( char [ ] methodOrTypeSignature ) throws IllegalArgumentException { try { int length = methodOrTypeSignature . length ; if ( length == 0 ) return CharOperation . NO_CHAR_CHAR ; if ( methodOrTypeSignature [ 0 ] != C_GENERIC_START ) return CharOperation . NO_CHAR_CHAR ; ArrayList paramList = new ArrayList ( 1 ) ; int paramStart = 1 , i = 1 ; while ( i < length ) { if ( methodOrTypeSignature [ i ] == C_GENERIC_END ) { int size = paramList . size ( ) ; if ( size == 0 ) throw new IllegalArgumentException ( ) ; char [ ] [ ] result ; paramList . toArray ( result = new char [ size ] [ ] ) ; return result ; } i = CharOperation . indexOf ( C_COLON , methodOrTypeSignature , i ) ; if ( i < 0 || i >= length ) throw new IllegalArgumentException ( ) ; while ( methodOrTypeSignature [ i ] == ':' ) { i ++ ; switch ( methodOrTypeSignature [ i ] ) { case ':' : break ; case C_GENERIC_END : break ; case C_RESOLVED : try { i = Util . scanClassTypeSignature ( methodOrTypeSignature , i ) ; i ++ ; } catch ( IllegalArgumentException e ) { } break ; case C_ARRAY : try { i = Util . scanArrayTypeSignature ( methodOrTypeSignature , i ) ; i ++ ; } catch ( IllegalArgumentException e ) { } break ; case C_TYPE_VARIABLE : try { i = Util . scanTypeVariableSignature ( methodOrTypeSignature , i ) ; i ++ ; } catch ( IllegalArgumentException e ) { } break ; } } paramList . add ( CharOperation . subarray ( methodOrTypeSignature , paramStart , i ) ) ; paramStart = i ; } } catch ( ArrayIndexOutOfBoundsException e ) { } throw new IllegalArgumentException ( ) ; } public static String [ ] getTypeParameters ( String methodOrTypeSignature ) throws IllegalArgumentException { char [ ] [ ] params = getTypeParameters ( methodOrTypeSignature . toCharArray ( ) ) ; return CharOperation . toStrings ( params ) ; } public static int getTypeSignatureKind ( char [ ] typeSignature ) { if ( typeSignature . length < 1 ) { throw new IllegalArgumentException ( ) ; } char c = typeSignature [ 0 ] ; if ( c == C_GENERIC_START ) { int count = 1 ; for ( int i = 1 , length = typeSignature . length ; i < length ; i ++ ) { switch ( typeSignature [ i ] ) { case C_GENERIC_START : count ++ ; break ; case C_GENERIC_END : count -- ; break ; } if ( count == 0 ) { if ( i + 1 < length ) c = typeSignature [ i + 1 ] ; break ; } } } switch ( c ) { case C_ARRAY : return ARRAY_TYPE_SIGNATURE ; case C_RESOLVED : case C_UNRESOLVED : return CLASS_TYPE_SIGNATURE ; case C_TYPE_VARIABLE : return TYPE_VARIABLE_SIGNATURE ; case C_BOOLEAN : case C_BYTE : case C_CHAR : case C_DOUBLE : case C_FLOAT : case C_INT : case C_LONG : case C_SHORT : case C_VOID : return BASE_TYPE_SIGNATURE ; case C_STAR : case C_SUPER : case C_EXTENDS : return WILDCARD_TYPE_SIGNATURE ; case C_CAPTURE : return CAPTURE_TYPE_SIGNATURE ; case C_INTERSECTION : return INTERSECTION_TYPE_SIGNATURE ; default : throw new IllegalArgumentException ( ) ; } } public static int getTypeSignatureKind ( String typeSignature ) { return getTypeSignatureKind ( typeSignature . toCharArray ( ) ) ; } public static char [ ] getTypeVariable ( char [ ] formalTypeParameterSignature ) throws IllegalArgumentException { int p = CharOperation . indexOf ( C_COLON , formalTypeParameterSignature ) ; if ( p < 0 ) { throw new IllegalArgumentException ( ) ; } return CharOperation . subarray ( formalTypeParameterSignature , 0 , p ) ; } public static String getTypeVariable ( String formalTypeParameterSignature ) throws IllegalArgumentException { return new String ( getTypeVariable ( formalTypeParameterSignature . toCharArray ( ) ) ) ; } public static char [ ] removeCapture ( char [ ] methodOrTypeSignature ) { return CharOperation . remove ( methodOrTypeSignature , C_CAPTURE ) ; } public static String removeCapture ( String methodOrTypeSignature ) { char [ ] array = methodOrTypeSignature . toCharArray ( ) ; char [ ] result = removeCapture ( array ) ; if ( array == result ) return methodOrTypeSignature ; return new String ( result ) ; } public static char [ ] toCharArray ( char [ ] signature ) throws IllegalArgumentException { int sigLength = signature . length ; if ( sigLength == 0 ) { throw new IllegalArgumentException ( ) ; } if ( signature [ 0 ] == C_PARAM_START || signature [ 0 ] == C_GENERIC_START ) { return toCharArray ( signature , CharOperation . NO_CHAR , null , true , true ) ; } StringBuffer buffer = new StringBuffer ( signature . length + 10 ) ; appendTypeSignature ( signature , 0 , true , buffer ) ; char [ ] result = new char [ buffer . length ( ) ] ; buffer . getChars ( 0 , buffer . length ( ) , result , 0 ) ; return result ; } public static char [ ] toCharArray ( char [ ] methodSignature , char [ ] methodName , char [ ] [ ] parameterNames , boolean fullyQualifyTypeNames , boolean includeReturnType ) { return toCharArray ( methodSignature , methodName , parameterNames , fullyQualifyTypeNames , includeReturnType , false ) ; } public static char [ ] toCharArray ( char [ ] methodSignature , char [ ] methodName , char [ ] [ ] parameterNames , boolean fullyQualifyTypeNames , boolean includeReturnType , boolean isVargArgs ) { int firstParen = CharOperation . indexOf ( C_PARAM_START , methodSignature ) ; if ( firstParen == - 1 ) { throw new IllegalArgumentException ( ) ; } StringBuffer buffer = new StringBuffer ( methodSignature . length + 10 ) ; if ( includeReturnType ) { char [ ] rts = getReturnType ( methodSignature ) ; appendTypeSignature ( rts , 0 , fullyQualifyTypeNames , buffer ) ; buffer . append ( ' ' ) ; } if ( methodName != null ) { buffer . append ( methodName ) ; } buffer . append ( '(' ) ; char [ ] [ ] pts = getParameterTypes ( methodSignature ) ; int max = pts . length ; int index = max - 1 ; loop : for ( int i = index ; i >= 0 ; i -- ) { if ( pts [ i ] [ 0 ] == Signature . C_ARRAY ) { break loop ; } index -- ; } for ( int i = 0 ; i < max ; i ++ ) { if ( i == index ) { appendTypeSignature ( pts [ i ] , 0 , fullyQualifyTypeNames , buffer , isVargArgs ) ; } else { appendTypeSignature ( pts [ i ] , 0 , fullyQualifyTypeNames , buffer ) ; } if ( parameterNames != null ) { buffer . append ( ' ' ) ; buffer . append ( parameterNames [ i ] ) ; } if ( i != pts . length - 1 ) { buffer . append ( ',' ) ; buffer . append ( ' ' ) ; } } buffer . append ( ')' ) ; char [ ] result = new char [ buffer . length ( ) ] ; buffer . getChars ( 0 , buffer . length ( ) , result , 0 ) ; return result ; } public static char [ ] toQualifiedName ( char [ ] [ ] segments ) { int length = segments . length ; if ( length == 0 ) return CharOperation . NO_CHAR ; if ( length == 1 ) return segments [ 0 ] ; int resultLength = 0 ; for ( int i = 0 ; i < length ; i ++ ) { resultLength += segments [ i ] . length + 1 ; } resultLength -- ; char [ ] result = new char [ resultLength ] ; int index = 0 ; for ( int i = 0 ; i < length ; i ++ ) { char [ ] segment = segments [ i ] ; int segmentLength = segment . length ; System . arraycopy ( segment , 0 , result , index , segmentLength ) ; index += segmentLength ; if ( i != length - 1 ) { result [ index ++ ] = C_DOT ; } } return result ; } public static String toQualifiedName ( String [ ] segments ) { int length = segments . length ; char [ ] [ ] charArrays = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { charArrays [ i ] = segments [ i ] . toCharArray ( ) ; } return new String ( toQualifiedName ( charArrays ) ) ; } public static String toString ( String signature ) throws IllegalArgumentException { return new String ( toCharArray ( signature . toCharArray ( ) ) ) ; } public static String toString ( String methodSignature , String methodName , String [ ] parameterNames , boolean fullyQualifyTypeNames , boolean includeReturnType ) { return toString ( methodSignature , methodName , parameterNames , fullyQualifyTypeNames , includeReturnType , false ) ; } public static String toString ( String methodSignature , String methodName , String [ ] parameterNames , boolean fullyQualifyTypeNames , boolean includeReturnType , boolean isVarArgs ) { char [ ] [ ] params ; if ( parameterNames == null ) { params = null ; } else { int paramLength = parameterNames . length ; params = new char [ paramLength ] [ ] ; for ( int i = 0 ; i < paramLength ; i ++ ) { params [ i ] = parameterNames [ i ] . toCharArray ( ) ; } } return new String ( toCharArray ( methodSignature . toCharArray ( ) , methodName == null ? null : methodName . toCharArray ( ) , params , fullyQualifyTypeNames , includeReturnType , isVarArgs ) ) ; } private Signature ( ) { } } </s>