<s> package org . eclipse . jdt . internal . codeassist ; import org . eclipse . core . runtime . IProgressMonitor ; import org . eclipse . jdt . core . CompletionFlags ; import org . eclipse . jdt . core . CompletionProposal ; import org . eclipse . jdt . core . CompletionRequestor ; import org . eclipse . jdt . core . Flags ; import org . eclipse . jdt . core . IAccessRule ; import org . eclipse . jdt . core . ICodeAssist ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IPackageFragmentRoot ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . env . IBinaryMethod ; import org . eclipse . jdt . internal . compiler . env . IBinaryType ; import org . eclipse . jdt . internal . core . BinaryType ; import org . eclipse . jdt . internal . core . JavaElement ; import org . eclipse . jdt . internal . core . JavaModelManager ; import org . eclipse . jdt . internal . core . NameLookup ; import org . eclipse . jdt . internal . core . SourceMapper ; public class InternalCompletionProposal extends CompletionProposal { private static Object NO_ATTACHED_SOURCE = new Object ( ) ; protected CompletionEngine completionEngine ; protected NameLookup nameLookup ; protected char [ ] declarationPackageName ; protected char [ ] declarationTypeName ; protected char [ ] packageName ; protected char [ ] typeName ; protected char [ ] [ ] parameterPackageNames ; protected char [ ] [ ] parameterTypeNames ; protected char [ ] originalSignature ; private boolean hasNoParameterNamesFromIndex = false ; private boolean updateCompletion = false ; protected int accessibility = IAccessRule . K_ACCESSIBLE ; protected boolean isConstructor = false ; private int completionKind ; private int completionLocation ; private int tokenStart = 0 ; private int tokenEnd = 0 ; private char [ ] completion = CharOperation . NO_CHAR ; private int replaceStart = 0 ; private int replaceEnd = 0 ; private int relevance = 1 ; private char [ ] declarationSignature = null ; private char [ ] declarationKey = null ; private char [ ] name = null ; private char [ ] signature = null ; private char [ ] key = null ; private CompletionProposal [ ] requiredProposals ; private int flags = Flags . AccDefault ; private int additionalFlags = CompletionFlags . Default ; private char [ ] [ ] parameterNames = null ; private boolean parameterNamesComputed = false ; protected char [ ] [ ] findConstructorParameterNames ( char [ ] declaringTypePackageName , char [ ] declaringTypeName , char [ ] selector , char [ ] [ ] paramTypeNames ) { if ( paramTypeNames == null || declaringTypeName == null ) return null ; char [ ] [ ] parameters = null ; int length = paramTypeNames . length ; char [ ] tName = CharOperation . concat ( declaringTypePackageName , declaringTypeName , '.' ) ; Object cachedType = this . completionEngine . typeCache . get ( tName ) ; IType type = null ; if ( cachedType != null ) { if ( cachedType != NO_ATTACHED_SOURCE && cachedType instanceof BinaryType ) { type = ( BinaryType ) cachedType ; } } else { NameLookup . Answer answer = this . nameLookup . findType ( new String ( tName ) , false , NameLookup . ACCEPT_CLASSES & NameLookup . ACCEPT_INTERFACES , true , false , false , null ) ; type = answer == null ? null : answer . type ; if ( type instanceof BinaryType ) { this . completionEngine . typeCache . put ( tName , type ) ; } else { type = null ; } } if ( type != null ) { String [ ] args = new String [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { args [ i ] = new String ( paramTypeNames [ i ] ) ; } IMethod method = type . getMethod ( new String ( selector ) , args ) ; if ( this . hasNoParameterNamesFromIndex ) { IPackageFragmentRoot packageFragmentRoot = ( IPackageFragmentRoot ) type . getAncestor ( IJavaElement . PACKAGE_FRAGMENT_ROOT ) ; if ( packageFragmentRoot . isArchive ( ) || this . completionEngine . openedBinaryTypes < getOpenedBinaryTypesThreshold ( ) ) { SourceMapper mapper = ( ( JavaElement ) method ) . getSourceMapper ( ) ; if ( mapper != null ) { try { char [ ] [ ] paramNames = mapper . getMethodParameterNames ( method ) ; if ( paramNames == null ) { if ( ! packageFragmentRoot . isArchive ( ) ) this . completionEngine . openedBinaryTypes ++ ; IBinaryType info = ( IBinaryType ) ( ( BinaryType ) type ) . getElementInfo ( ) ; char [ ] source = mapper . findSource ( type , info ) ; if ( source != null ) { mapper . mapSource ( type , source , info ) ; } paramNames = mapper . getMethodParameterNames ( method ) ; } if ( paramNames != null ) { parameters = paramNames ; } } catch ( JavaModelException e ) { } } } } else { try { IBinaryMethod info = ( IBinaryMethod ) ( ( JavaElement ) method ) . getElementInfo ( ) ; char [ ] [ ] argumentNames = info . getArgumentNames ( ) ; if ( argumentNames != null && argumentNames . length == length ) { parameters = argumentNames ; } } catch ( JavaModelException e ) { } try { parameters = new char [ length ] [ ] ; String [ ] params = method . getParameterNames ( ) ; for ( int i = 0 ; i < length ; i ++ ) { parameters [ i ] = params [ i ] . toCharArray ( ) ; } } catch ( JavaModelException e ) { parameters = null ; } } } if ( parameters == null ) { parameters = CompletionEngine . createDefaultParameterNames ( length ) ; } return parameters ; } protected char [ ] [ ] findMethodParameterNames ( char [ ] declaringTypePackageName , char [ ] declaringTypeName , char [ ] selector , char [ ] [ ] paramTypeNames ) { if ( paramTypeNames == null || declaringTypeName == null ) return null ; char [ ] [ ] parameters = null ; int length = paramTypeNames . length ; char [ ] tName = CharOperation . concat ( declaringTypePackageName , declaringTypeName , '.' ) ; Object cachedType = this . completionEngine . typeCache . get ( tName ) ; IType type = null ; if ( cachedType != null ) { if ( cachedType != NO_ATTACHED_SOURCE && cachedType instanceof BinaryType ) { type = ( BinaryType ) cachedType ; } } else { NameLookup . Answer answer = this . nameLookup . findType ( new String ( tName ) , false , NameLookup . ACCEPT_CLASSES & NameLookup . ACCEPT_INTERFACES , true , false , false , null ) ; type = answer == null ? null : answer . type ; if ( type instanceof BinaryType ) { this . completionEngine . typeCache . put ( tName , type ) ; } else { type = null ; } } if ( type != null ) { String [ ] args = new String [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { args [ i ] = new String ( paramTypeNames [ i ] ) ; } IMethod method = type . getMethod ( new String ( selector ) , args ) ; try { parameters = new char [ length ] [ ] ; String [ ] params = method . getParameterNames ( ) ; for ( int i = 0 ; i < length ; i ++ ) { parameters [ i ] = params [ i ] . toCharArray ( ) ; } } catch ( JavaModelException e ) { parameters = null ; } } if ( parameters == null ) { parameters = CompletionEngine . createDefaultParameterNames ( length ) ; } return parameters ; } protected char [ ] getDeclarationPackageName ( ) { return this . declarationPackageName ; } protected char [ ] getDeclarationTypeName ( ) { return this . declarationTypeName ; } private int getOpenedBinaryTypesThreshold ( ) { return JavaModelManager . getJavaModelManager ( ) . getOpenableCacheSize ( ) / 10 ; } protected char [ ] getPackageName ( ) { return this . packageName ; } protected char [ ] getTypeName ( ) { return this . typeName ; } protected char [ ] [ ] getParameterPackageNames ( ) { return this . parameterPackageNames ; } protected char [ ] [ ] getParameterTypeNames ( ) { return this . parameterTypeNames ; } protected void setDeclarationPackageName ( char [ ] declarationPackageName ) { this . declarationPackageName = declarationPackageName ; } protected void setDeclarationTypeName ( char [ ] declarationTypeName ) { this . declarationTypeName = declarationTypeName ; } protected void setPackageName ( char [ ] packageName ) { this . packageName = packageName ; } protected void setTypeName ( char [ ] typeName ) { this . typeName = typeName ; } protected void setParameterPackageNames ( char [ ] [ ] parameterPackageNames ) { this . parameterPackageNames = parameterPackageNames ; } protected void setParameterTypeNames ( char [ ] [ ] parameterTypeNames ) { this . parameterTypeNames = parameterTypeNames ; } protected void setAccessibility ( int kind ) { this . accessibility = kind ; } protected void setIsContructor ( boolean isConstructor ) { this . isConstructor = isConstructor ; } public void setOriginalSignature ( char [ ] originalSignature ) { this . originalSignature = originalSignature ; } public InternalCompletionProposal ( int kind , int completionLocation ) { if ( ( kind < FIRST_KIND ) || ( kind > LAST_KIND ) ) { throw new IllegalArgumentException ( ) ; } if ( this . completion == null || completionLocation < 0 ) { if ( this . completion == null || completionLocation != - 1 ) { throw new IllegalArgumentException ( ) ; } completionLocation = 0 ; } this . completionKind = kind ; this . completionLocation = completionLocation ; } public int getAdditionalFlags ( ) { return this . additionalFlags ; } public void setAdditionalFlags ( int additionalFlags ) { this . additionalFlags = additionalFlags ; } public int getKind ( ) { return this . completionKind ; } public int getCompletionLocation ( ) { return this . completionLocation ; } public int getTokenStart ( ) { return this . tokenStart ; } public int getTokenEnd ( ) { return this . tokenEnd ; } public void setTokenRange ( int startIndex , int endIndex ) { if ( startIndex < 0 || endIndex < startIndex ) { throw new IllegalArgumentException ( ) ; } this . tokenStart = startIndex ; this . tokenEnd = endIndex ; } public char [ ] getCompletion ( ) { if ( this . completionKind == METHOD_DECLARATION ) { findParameterNames ( null ) ; if ( this . updateCompletion ) { this . updateCompletion = false ; if ( this . parameterNames != null ) { int length = this . parameterNames . length ; StringBuffer completionBuffer = new StringBuffer ( this . completion . length ) ; int start = 0 ; int end = CharOperation . indexOf ( '%' , this . completion ) ; completionBuffer . append ( this . completion , start , end - start ) ; for ( int i = 0 ; i < length ; i ++ ) { completionBuffer . append ( this . parameterNames [ i ] ) ; start = end + 1 ; end = CharOperation . indexOf ( '%' , this . completion , start ) ; if ( end > - 1 ) { completionBuffer . append ( this . completion , start , end - start ) ; } else { completionBuffer . append ( this . completion , start , this . completion . length - start ) ; } } int nameLength = completionBuffer . length ( ) ; this . completion = new char [ nameLength ] ; completionBuffer . getChars ( 0 , nameLength , this . completion , 0 ) ; } } } return this . completion ; } public void setCompletion ( char [ ] completion ) { this . completion = completion ; } public int getReplaceStart ( ) { return this . replaceStart ; } public int getReplaceEnd ( ) { return this . replaceEnd ; } public void setReplaceRange ( int startIndex , int endIndex ) { if ( startIndex < 0 || endIndex < startIndex ) { throw new IllegalArgumentException ( ) ; } this . replaceStart = startIndex ; this . replaceEnd = endIndex ; } public int getRelevance ( ) { return this . relevance ; } public void setRelevance ( int rating ) { if ( rating <= 0 ) { throw new IllegalArgumentException ( ) ; } this . relevance = rating ; } public char [ ] getDeclarationSignature ( ) { return this . declarationSignature ; } public char [ ] getDeclarationKey ( ) { return this . declarationKey ; } public void setDeclarationSignature ( char [ ] signature ) { this . declarationSignature = signature ; } public void setDeclarationKey ( char [ ] key ) { this . declarationKey = key ; } public char [ ] getName ( ) { return this . name ; } public void setName ( char [ ] name ) { this . name = name ; } public char [ ] getSignature ( ) { return this . signature ; } public char [ ] getKey ( ) { return this . key ; } public void setSignature ( char [ ] signature ) { this . signature = signature ; } public void setKey ( char [ ] key ) { this . key = key ; } public int getFlags ( ) { return this . flags ; } public void setFlags ( int flags ) { this . flags = flags ; } public void setHasNoParameterNamesFromIndex ( boolean hasNoParameterNamesFromIndex ) { this . hasNoParameterNamesFromIndex = hasNoParameterNamesFromIndex ; } public CompletionProposal [ ] getRequiredProposals ( ) { return this . requiredProposals ; } public void setRequiredProposals ( CompletionProposal [ ] proposals ) { this . requiredProposals = proposals ; } public char [ ] [ ] findParameterNames ( IProgressMonitor monitor ) { if ( ! this . parameterNamesComputed ) { this . parameterNamesComputed = true ; switch ( this . completionKind ) { case ANONYMOUS_CLASS_DECLARATION : try { this . parameterNames = findMethodParameterNames ( this . declarationPackageName , this . declarationTypeName , CharOperation . lastSegment ( this . declarationTypeName , '.' ) , Signature . getParameterTypes ( this . originalSignature == null ? this . signature : this . originalSignature ) ) ; } catch ( IllegalArgumentException e ) { if ( this . parameterTypeNames != null ) { this . parameterNames = CompletionEngine . createDefaultParameterNames ( this . parameterTypeNames . length ) ; } else { this . parameterNames = null ; } } break ; case ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION : try { this . parameterNames = findConstructorParameterNames ( this . declarationPackageName , this . declarationTypeName , CharOperation . lastSegment ( this . declarationTypeName , '.' ) , Signature . getParameterTypes ( this . originalSignature == null ? this . signature : this . originalSignature ) ) ; } catch ( IllegalArgumentException e ) { if ( this . parameterTypeNames != null ) { this . parameterNames = CompletionEngine . createDefaultParameterNames ( this . parameterTypeNames . length ) ; } else { this . parameterNames = null ; } } break ; case METHOD_REF : case METHOD_REF_WITH_CASTED_RECEIVER : try { this . parameterNames = findMethodParameterNames ( this . declarationPackageName , this . declarationTypeName , this . name , Signature . getParameterTypes ( this . originalSignature == null ? this . signature : this . originalSignature ) ) ; } catch ( IllegalArgumentException e ) { if ( this . parameterTypeNames != null ) { this . parameterNames = CompletionEngine . createDefaultParameterNames ( this . parameterTypeNames . length ) ; } else { this . parameterNames = null ; } } break ; case CONSTRUCTOR_INVOCATION : try { this . parameterNames = findConstructorParameterNames ( this . declarationPackageName , this . declarationTypeName , this . name , Signature . getParameterTypes ( this . originalSignature == null ? this . signature : this . originalSignature ) ) ; } catch ( IllegalArgumentException e ) { if ( this . parameterTypeNames != null ) { this . parameterNames = CompletionEngine . createDefaultParameterNames ( this . parameterTypeNames . length ) ; } else { this . parameterNames = null ; } } break ; case METHOD_DECLARATION : try { this . parameterNames = findMethodParameterNames ( this . declarationPackageName , this . declarationTypeName , this . name , Signature . getParameterTypes ( this . originalSignature == null ? this . signature : this . originalSignature ) ) ; } catch ( IllegalArgumentException e ) { if ( this . parameterTypeNames != null ) { this . parameterNames = CompletionEngine . createDefaultParameterNames ( this . parameterTypeNames . length ) ; } else { this . parameterNames = null ; } } if ( this . parameterNames != null ) { this . updateCompletion = true ; } break ; } } return this . parameterNames ; } public void setParameterNames ( char [ ] [ ] parameterNames ) { this . parameterNames = parameterNames ; this . parameterNamesComputed = true ; } public int getAccessibility ( ) { return this . accessibility ; } public boolean isConstructor ( ) { return this . isConstructor ; } private int receiverStart ; private int receiverEnd ; private char [ ] receiverSignature ; public char [ ] getReceiverSignature ( ) { return this . receiverSignature ; } public int getReceiverStart ( ) { return this . receiverStart ; } public int getReceiverEnd ( ) { return this . receiverEnd ; } public void setReceiverSignature ( char [ ] signature ) { this . receiverSignature = signature ; } public void setReceiverRange ( int startIndex , int endIndex ) { this . receiverStart = startIndex ; this . receiverEnd = endIndex ; } public String toString ( ) { StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( '[' ) ; switch ( this . completionKind ) { case CompletionProposal . ANONYMOUS_CLASS_DECLARATION : buffer . append ( "" ) ; break ; case CompletionProposal . FIELD_REF : buffer . append ( "FIELD_REF" ) ; break ; case CompletionProposal . KEYWORD : buffer . append ( "KEYWORD" ) ; break ; case CompletionProposal . LABEL_REF : buffer . append ( "LABEL_REF" ) ; break ; case CompletionProposal . LOCAL_VARIABLE_REF : buffer . append ( "" ) ; break ; case CompletionProposal . METHOD_DECLARATION : buffer . append ( "" ) ; if ( this . isConstructor ) { buffer . append ( "" ) ; } break ; case CompletionProposal . METHOD_REF : buffer . append ( "METHOD_REF" ) ; if ( this . isConstructor ) { buffer . append ( "" ) ; } break ; case CompletionProposal . PACKAGE_REF : buffer . append ( "PACKAGE_REF" ) ; break ; case CompletionProposal . TYPE_REF : buffer . append ( "TYPE_REF" ) ; break ; case CompletionProposal . VARIABLE_DECLARATION : buffer . append ( "" ) ; break ; case CompletionProposal . POTENTIAL_METHOD_DECLARATION : buffer . append ( "" ) ; break ; case CompletionProposal . METHOD_NAME_REFERENCE : buffer . append ( "" ) ; break ; case CompletionProposal . ANNOTATION_ATTRIBUTE_REF : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_BLOCK_TAG : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_INLINE_TAG : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_FIELD_REF : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_METHOD_REF : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_TYPE_REF : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_PARAM_REF : buffer . append ( "" ) ; break ; case CompletionProposal . JAVADOC_VALUE_REF : buffer . append ( "" ) ; break ; case CompletionProposal . FIELD_IMPORT : buffer . append ( "FIELD_IMPORT" ) ; break ; case CompletionProposal . METHOD_IMPORT : buffer . append ( "" ) ; break ; case CompletionProposal . TYPE_IMPORT : buffer . append ( "TYPE_IMPORT" ) ; break ; case CompletionProposal . METHOD_REF_WITH_CASTED_RECEIVER : buffer . append ( "" ) ; break ; case CompletionProposal . FIELD_REF_WITH_CASTED_RECEIVER : buffer . append ( "" ) ; break ; case CompletionProposal . CONSTRUCTOR_INVOCATION : buffer . append ( "" ) ; break ; case CompletionProposal . ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION : buffer . append ( "" ) ; break ; default : buffer . append ( "PROPOSAL" ) ; break ; } buffer . append ( "" ) ; if ( this . completion != null ) buffer . append ( this . completion ) ; buffer . append ( ", declSign:" ) ; if ( this . declarationSignature != null ) buffer . append ( this . declarationSignature ) ; buffer . append ( ", sign:" ) ; if ( this . signature != null ) buffer . append ( this . signature ) ; buffer . append ( ", declKey:" ) ; if ( this . declarationKey != null ) buffer . append ( this . declarationKey ) ; buffer . append ( ", key:" ) ; if ( this . key != null ) buffer . append ( this . key ) ; buffer . append ( ", name:" ) ; if ( this . name != null ) buffer . append ( this . name ) ; buffer . append ( ", replace:[" ) ; buffer . append ( this . replaceStart ) ; buffer . append ( ',' ) ; buffer . append ( this . replaceEnd ) ; buffer . append ( "], token:[" ) ; buffer . append ( this . tokenStart ) ; buffer . append ( ',' ) ; buffer . append ( this . tokenEnd ) ; buffer . append ( "" ) ; buffer . append ( this . relevance ) ; buffer . append ( '}' ) ; return buffer . toString ( ) ; } } </s>