<s> package org . eclipse . jdt . internal . core ; import java . util . Iterator ; import java . util . List ; import org . eclipse . jdt . core . ICompilationUnit ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IJavaModelStatus ; import org . eclipse . jdt . core . IJavaModelStatusConstants ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . core . dom . MethodDeclaration ; import org . eclipse . jdt . core . dom . SimpleName ; import org . eclipse . jdt . core . dom . SingleVariableDeclaration ; import org . eclipse . jdt . core . dom . rewrite . ASTRewrite ; import org . eclipse . jdt . internal . core . util . Messages ; import org . eclipse . jdt . internal . core . util . Util ; public class CreateMethodOperation extends CreateTypeMemberOperation { protected String [ ] parameterTypes ; public CreateMethodOperation ( IType parentElement , String source , boolean force ) { super ( parentElement , source , force ) ; } protected String [ ] convertASTMethodTypesToSignatures ( ) { if ( this . parameterTypes == null ) { if ( this . createdNode != null ) { MethodDeclaration methodDeclaration = ( MethodDeclaration ) this . createdNode ; List parameters = methodDeclaration . parameters ( ) ; int size = parameters . size ( ) ; this . parameterTypes = new String [ size ] ; Iterator iterator = parameters . iterator ( ) ; for ( int i = 0 ; i < size ; i ++ ) { SingleVariableDeclaration parameter = ( SingleVariableDeclaration ) iterator . next ( ) ; String typeSig = Util . getSignature ( parameter . getType ( ) ) ; int extraDimensions = parameter . getExtraDimensions ( ) ; if ( methodDeclaration . isVarargs ( ) && i == size - 1 ) extraDimensions ++ ; this . parameterTypes [ i ] = Signature . createArraySignature ( typeSig , extraDimensions ) ; } } } return this . parameterTypes ; } protected ASTNode generateElementAST ( ASTRewrite rewriter , ICompilationUnit cu ) throws JavaModelException { ASTNode node = super . generateElementAST ( rewriter , cu ) ; if ( node . getNodeType ( ) != ASTNode . METHOD_DECLARATION ) throw new JavaModelException ( new JavaModelStatus ( IJavaModelStatusConstants . INVALID_CONTENTS ) ) ; return node ; } protected IJavaElement generateResultHandle ( ) { String [ ] types = convertASTMethodTypesToSignatures ( ) ; String name = getASTNodeName ( ) ; return getType ( ) . getMethod ( name , types ) ; } private String getASTNodeName ( ) { return ( ( MethodDeclaration ) this . createdNode ) . getName ( ) . getIdentifier ( ) ; } public String getMainTaskName ( ) { return Messages . operation_createMethodProgress ; } protected SimpleName rename ( ASTNode node , SimpleName newName ) { MethodDeclaration method = ( MethodDeclaration ) node ; SimpleName oldName = method . getName ( ) ; method . setName ( newName ) ; return oldName ; } protected IJavaModelStatus verifyNameCollision ( ) { if ( this . createdNode != null ) { IType type = getType ( ) ; String name ; if ( ( ( MethodDeclaration ) this . createdNode ) . isConstructor ( ) ) name = type . getElementName ( ) ; else name = getASTNodeName ( ) ; String [ ] types = convertASTMethodTypesToSignatures ( ) ; if ( type . getMethod ( name , types ) . exists ( ) ) { return new JavaModelStatus ( IJavaModelStatusConstants . NAME_COLLISION , Messages . bind ( Messages . status_nameCollision , name ) ) ; } } return JavaModelStatus . VERIFIED_OK ; } } </s>