<s> package org . eclipse . jdt . internal . core ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . classfmt . ClassFileConstants ; import org . eclipse . jdt . internal . compiler . env . IBinaryAnnotation ; import org . eclipse . jdt . internal . compiler . env . IBinaryMethod ; import org . eclipse . jdt . internal . compiler . env . IBinaryType ; import org . eclipse . jdt . internal . compiler . lookup . Binding ; import org . eclipse . jdt . internal . core . JavaModelManager . PerProjectInfo ; import org . eclipse . jdt . internal . core . util . Util ; class BinaryMethod extends BinaryMember implements IMethod { protected String [ ] parameterTypes ; protected String [ ] parameterNames ; protected String [ ] exceptionTypes ; protected String returnType ; protected BinaryMethod ( JavaElement parent , String name , String [ ] paramTypes ) { super ( parent , name ) ; if ( paramTypes == null ) { this . parameterTypes = CharOperation . NO_STRINGS ; } else { this . parameterTypes = paramTypes ; } } public boolean equals ( Object o ) { if ( ! ( o instanceof BinaryMethod ) ) return false ; return super . equals ( o ) && Util . equalArraysOrNull ( this . parameterTypes , ( ( BinaryMethod ) o ) . parameterTypes ) ; } public IAnnotation [ ] getAnnotations ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; IBinaryAnnotation [ ] binaryAnnotations = info . getAnnotations ( ) ; return getAnnotations ( binaryAnnotations , info . getTagBits ( ) ) ; } public IMemberValuePair getDefaultValue ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; Object defaultValue = info . getDefaultValue ( ) ; if ( defaultValue == null ) return null ; MemberValuePair memberValuePair = new MemberValuePair ( getElementName ( ) ) ; memberValuePair . value = Util . getAnnotationMemberValue ( this , memberValuePair , defaultValue ) ; return memberValuePair ; } public String [ ] getExceptionTypes ( ) throws JavaModelException { if ( this . exceptionTypes == null ) { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; char [ ] genericSignature = info . getGenericSignature ( ) ; if ( genericSignature != null ) { char [ ] dotBasedSignature = CharOperation . replaceOnCopy ( genericSignature , '/' , '.' ) ; this . exceptionTypes = Signature . getThrownExceptionTypes ( new String ( dotBasedSignature ) ) ; } if ( this . exceptionTypes == null || this . exceptionTypes . length == 0 ) { char [ ] [ ] eTypeNames = info . getExceptionTypeNames ( ) ; if ( eTypeNames == null || eTypeNames . length == 0 ) { this . exceptionTypes = CharOperation . NO_STRINGS ; } else { eTypeNames = ClassFile . translatedNames ( eTypeNames ) ; this . exceptionTypes = new String [ eTypeNames . length ] ; for ( int j = 0 , length = eTypeNames . length ; j < length ; j ++ ) { int nameLength = eTypeNames [ j ] . length ; char [ ] convertedName = new char [ nameLength + 2 ] ; System . arraycopy ( eTypeNames [ j ] , 0 , convertedName , 1 , nameLength ) ; convertedName [ 0 ] = 'L' ; convertedName [ nameLength + 1 ] = ';' ; this . exceptionTypes [ j ] = new String ( convertedName ) ; } } } } return this . exceptionTypes ; } public int getElementType ( ) { return METHOD ; } public int getFlags ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; return info . getModifiers ( ) ; } protected void getHandleMemento ( StringBuffer buff ) { ( ( JavaElement ) getParent ( ) ) . getHandleMemento ( buff ) ; char delimiter = getHandleMementoDelimiter ( ) ; buff . append ( delimiter ) ; escapeMementoName ( buff , getElementName ( ) ) ; for ( int i = 0 ; i < this . parameterTypes . length ; i ++ ) { buff . append ( delimiter ) ; escapeMementoName ( buff , this . parameterTypes [ i ] ) ; } if ( this . occurrenceCount > 1 ) { buff . append ( JEM_COUNT ) ; buff . append ( this . occurrenceCount ) ; } } protected char getHandleMementoDelimiter ( ) { return JavaElement . JEM_METHOD ; } public String getKey ( boolean forceOpen ) throws JavaModelException { return getKey ( this , forceOpen ) ; } public int getNumberOfParameters ( ) { return this . parameterTypes == null ? 0 : this . parameterTypes . length ; } public String [ ] getParameterNames ( ) throws JavaModelException { if ( this . parameterNames != null ) return this . parameterNames ; IType type = ( IType ) getParent ( ) ; SourceMapper mapper = getSourceMapper ( ) ; if ( mapper != null ) { char [ ] [ ] paramNames = mapper . getMethodParameterNames ( this ) ; if ( paramNames == null ) { IBinaryType info = ( IBinaryType ) ( ( BinaryType ) getDeclaringType ( ) ) . getElementInfo ( ) ; char [ ] source = mapper . findSource ( type , info ) ; if ( source != null ) { mapper . mapSource ( type , source , info ) ; } paramNames = mapper . getMethodParameterNames ( this ) ; } if ( paramNames != null ) { this . parameterNames = new String [ paramNames . length ] ; for ( int i = 0 ; i < paramNames . length ; i ++ ) { this . parameterNames [ i ] = new String ( paramNames [ i ] ) ; } return this . parameterNames ; } } IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; final int paramCount = Signature . getParameterCount ( new String ( info . getMethodDescriptor ( ) ) ) ; if ( paramCount != 0 ) { int modifiers = getFlags ( ) ; if ( ( modifiers & ClassFileConstants . AccSynthetic ) != 0 ) { return this . parameterNames = getRawParameterNames ( paramCount ) ; } JavadocContents javadocContents = null ; IType declaringType = getDeclaringType ( ) ; PerProjectInfo projectInfo = JavaModelManager . getJavaModelManager ( ) . getPerProjectInfoCheckExistence ( getJavaProject ( ) . getProject ( ) ) ; synchronized ( projectInfo . javadocCache ) { javadocContents = ( JavadocContents ) projectInfo . javadocCache . get ( declaringType ) ; if ( javadocContents == null ) { projectInfo . javadocCache . put ( declaringType , BinaryType . EMPTY_JAVADOC ) ; } } String methodDoc = null ; if ( javadocContents == null ) { long timeOut = 50 ; try { String option = getJavaProject ( ) . getOption ( JavaCore . TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC , true ) ; if ( option != null ) { timeOut = Long . parseLong ( option ) ; } } catch ( NumberFormatException e ) { } if ( timeOut == 0 ) { return this . parameterNames = getRawParameterNames ( paramCount ) ; } final class ParametersNameCollector { String javadoc ; public void setJavadoc ( String s ) { this . javadoc = s ; } public String getJavadoc ( ) { return this . javadoc ; } } final ParametersNameCollector nameCollector = new ParametersNameCollector ( ) ; Thread collect = new Thread ( ) { public void run ( ) { try { nameCollector . setJavadoc ( BinaryMethod . this . getAttachedJavadoc ( null ) ) ; } catch ( JavaModelException e ) { } synchronized ( nameCollector ) { nameCollector . notify ( ) ; } } } ; collect . start ( ) ; synchronized ( nameCollector ) { try { nameCollector . wait ( timeOut ) ; } catch ( InterruptedException e ) { } } methodDoc = nameCollector . getJavadoc ( ) ; } else if ( javadocContents != BinaryType . EMPTY_JAVADOC ) { try { methodDoc = javadocContents . getMethodDoc ( this ) ; } catch ( JavaModelException e ) { javadocContents = null ; } } if ( methodDoc != null ) { final int indexOfOpenParen = methodDoc . indexOf ( '(' ) ; if ( indexOfOpenParen != - 1 ) { final int indexOfClosingParen = methodDoc . indexOf ( ')' , indexOfOpenParen ) ; if ( indexOfClosingParen != - 1 ) { final char [ ] paramsSource = CharOperation . replace ( methodDoc . substring ( indexOfOpenParen + 1 , indexOfClosingParen ) . toCharArray ( ) , "&nbsp;" . toCharArray ( ) , new char [ ] { ' ' } ) ; final char [ ] [ ] params = splitParameters ( paramsSource , paramCount ) ; final int paramsLength = params . length ; this . parameterNames = new String [ paramsLength ] ; for ( int i = 0 ; i < paramsLength ; i ++ ) { final char [ ] param = params [ i ] ; int indexOfSpace = CharOperation . lastIndexOf ( ' ' , param ) ; if ( indexOfSpace != - 1 ) { this . parameterNames [ i ] = String . valueOf ( param , indexOfSpace + 1 , param . length - indexOfSpace - 1 ) ; } else { this . parameterNames [ i ] = "arg" + i ; } } return this . parameterNames ; } } } char [ ] [ ] argumentNames = info . getArgumentNames ( ) ; if ( argumentNames != null && argumentNames . length == paramCount ) { String [ ] names = new String [ paramCount ] ; for ( int i = 0 ; i < paramCount ; i ++ ) { names [ i ] = new String ( argumentNames [ i ] ) ; } return this . parameterNames = names ; } } return this . parameterNames = getRawParameterNames ( paramCount ) ; } private char [ ] [ ] splitParameters ( char [ ] parametersSource , int paramCount ) { char [ ] [ ] params = new char [ paramCount ] [ ] ; int paramIndex = 0 ; int index = 0 ; int balance = 0 ; int length = parametersSource . length ; int start = 0 ; while ( index < length ) { switch ( parametersSource [ index ] ) { case '<' : balance ++ ; index ++ ; while ( index < length && parametersSource [ index ] != '>' ) { index ++ ; } break ; case '>' : balance -- ; index ++ ; break ; case ',' : if ( balance == 0 && paramIndex < paramCount ) { params [ paramIndex ++ ] = CharOperation . subarray ( parametersSource , start , index ) ; start = index + 1 ; } index ++ ; break ; case '&' : if ( ( index + 4 ) < length ) { if ( parametersSource [ index + 1 ] == 'l' && parametersSource [ index + 2 ] == 't' && parametersSource [ index + 3 ] == ';' ) { balance ++ ; index += 4 ; } else if ( parametersSource [ index + 1 ] == 'g' && parametersSource [ index + 2 ] == 't' && parametersSource [ index + 3 ] == ';' ) { balance -- ; index += 4 ; } else { index ++ ; } } else { index ++ ; } break ; default : index ++ ; } } if ( paramIndex < paramCount ) { params [ paramIndex ++ ] = CharOperation . subarray ( parametersSource , start , index ) ; } if ( paramIndex != paramCount ) { System . arraycopy ( params , 0 , ( params = new char [ paramIndex ] [ ] ) , 0 , paramIndex ) ; } return params ; } public String [ ] getParameterTypes ( ) { return this . parameterTypes ; } public ITypeParameter getTypeParameter ( String typeParameterName ) { return new TypeParameter ( this , typeParameterName ) ; } public ITypeParameter [ ] getTypeParameters ( ) throws JavaModelException { String [ ] typeParameterSignatures = getTypeParameterSignatures ( ) ; int length = typeParameterSignatures . length ; if ( length == 0 ) return TypeParameter . NO_TYPE_PARAMETERS ; ITypeParameter [ ] typeParameters = new ITypeParameter [ length ] ; for ( int i = 0 ; i < typeParameterSignatures . length ; i ++ ) { String typeParameterName = Signature . getTypeVariable ( typeParameterSignatures [ i ] ) ; typeParameters [ i ] = new TypeParameter ( this , typeParameterName ) ; } return typeParameters ; } public String [ ] getTypeParameterSignatures ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; char [ ] genericSignature = info . getGenericSignature ( ) ; if ( genericSignature == null ) return CharOperation . NO_STRINGS ; char [ ] dotBasedSignature = CharOperation . replaceOnCopy ( genericSignature , '/' , '.' ) ; char [ ] [ ] typeParams = Signature . getTypeParameters ( dotBasedSignature ) ; return CharOperation . toStrings ( typeParams ) ; } public String [ ] getRawParameterNames ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; int paramCount = Signature . getParameterCount ( new String ( info . getMethodDescriptor ( ) ) ) ; return getRawParameterNames ( paramCount ) ; } private String [ ] getRawParameterNames ( int paramCount ) { String [ ] result = new String [ paramCount ] ; for ( int i = 0 ; i < paramCount ; i ++ ) { result [ i ] = "arg" + i ; } return result ; } public String getReturnType ( ) throws JavaModelException { if ( this . returnType == null ) { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; this . returnType = getReturnType ( info ) ; } return this . returnType ; } private String getReturnType ( IBinaryMethod info ) { char [ ] genericSignature = info . getGenericSignature ( ) ; char [ ] signature = genericSignature == null ? info . getMethodDescriptor ( ) : genericSignature ; char [ ] dotBasedSignature = CharOperation . replaceOnCopy ( signature , '/' , '.' ) ; String returnTypeName = Signature . getReturnType ( new String ( dotBasedSignature ) ) ; return new String ( ClassFile . translatedName ( returnTypeName . toCharArray ( ) ) ) ; } public String getSignature ( ) throws JavaModelException { IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; return new String ( info . getMethodDescriptor ( ) ) ; } public int hashCode ( ) { int hash = super . hashCode ( ) ; for ( int i = 0 , length = this . parameterTypes . length ; i < length ; i ++ ) { hash = Util . combineHashCodes ( hash , this . parameterTypes [ i ] . hashCode ( ) ) ; } return hash ; } public boolean isConstructor ( ) throws JavaModelException { if ( ! getElementName ( ) . equals ( this . parent . getElementName ( ) ) ) { return false ; } IBinaryMethod info = ( IBinaryMethod ) getElementInfo ( ) ; return info . isConstructor ( ) ; } public boolean isMainMethod ( ) throws JavaModelException { return this . isMainMethod ( this ) ; } public boolean isResolved ( ) { return false ; } public boolean isSimilar ( IMethod method ) { return areSimilarMethods ( getElementName ( ) , getParameterTypes ( ) , method . getElementName ( ) , method . getParameterTypes ( ) , null ) ; } public String readableName ( ) { StringBuffer buffer = new StringBuffer ( super . readableName ( ) ) ; buffer . append ( "(" ) ; String [ ] paramTypes = this . parameterTypes ; int length ; if ( paramTypes != null && ( length = paramTypes . length ) > 0 ) { for ( int i = 0 ; i < length ; i ++ ) { buffer . append ( Signature . toString ( paramTypes [ i ] ) ) ; if ( i < length - 1 ) { buffer . append ( ", " ) ; } } } buffer . append ( ")" ) ; return buffer . toString ( ) ; } public JavaElement resolved ( Binding binding ) { SourceRefElement resolvedHandle = new ResolvedBinaryMethod ( this . parent , this . name , this . parameterTypes , new String ( binding . computeUniqueKey ( ) ) ) ; resolvedHandle . occurrenceCount = this . occurrenceCount ; return resolvedHandle ; } protected void toStringInfo ( int tab , StringBuffer buffer , Object info , boolean showResolvedInfo ) { buffer . append ( tabString ( tab ) ) ; if ( info == null ) { toStringName ( buffer ) ; buffer . append ( " (not open)" ) ; } else if ( info == NO_INFO ) { toStringName ( buffer ) ; } else { IBinaryMethod methodInfo = ( IBinaryMethod ) info ; int flags = methodInfo . getModifiers ( ) ; if ( Flags . isStatic ( flags ) ) { buffer . append ( "static " ) ; } if ( ! methodInfo . isConstructor ( ) ) { buffer . append ( Signature . toString ( getReturnType ( methodInfo ) ) ) ; buffer . append ( ' ' ) ; } toStringName ( buffer , flags ) ; } } protected void toStringName ( StringBuffer buffer ) { toStringName ( buffer , 0 ) ; } protected void toStringName ( StringBuffer buffer , int flags ) { buffer . append ( getElementName ( ) ) ; buffer . append ( '(' ) ; String [ ] parameters = getParameterTypes ( ) ; int length ; if ( parameters != null && ( length = parameters . length ) > 0 ) { boolean isVarargs = Flags . isVarargs ( flags ) ; for ( int i = 0 ; i < length ; i ++ ) { try { if ( i < length - 1 ) { buffer . append ( Signature . toString ( parameters [ i ] ) ) ; buffer . append ( ", " ) ; } else if ( isVarargs ) { String parameter = parameters [ i ] . substring ( 1 ) ; buffer . append ( Signature . toString ( parameter ) ) ; buffer . append ( " ..." ) ; } else { buffer . append ( Signature . toString ( parameters [ i ] ) ) ; } } catch ( IllegalArgumentException e ) { buffer . append ( "" ) ; buffer . append ( parameters [ i ] ) ; } } } buffer . append ( ')' ) ; if ( this . occurrenceCount > 1 ) { buffer . append ( "#" ) ; buffer . append ( this . occurrenceCount ) ; } } public String getAttachedJavadoc ( IProgressMonitor monitor ) throws JavaModelException { JavadocContents javadocContents = ( ( BinaryType ) this . getDeclaringType ( ) ) . getJavadocContents ( monitor ) ; if ( javadocContents == null ) return null ; return javadocContents . getMethodDoc ( this ) ; } } </s>