/** Renames the main type in <code>cu</code>. */ private void updateTypeName( ICompilationUnit cu, CompilationUnit astCU, String oldName, String newName, ASTRewrite rewriter) throws JavaModelException { if (newName != null) { String oldTypeName = Util.getNameWithoutJavaLikeExtension(oldName); String newTypeName = Util.getNameWithoutJavaLikeExtension(newName); AST ast = astCU.getAST(); // update main type name IType[] types = cu.getTypes(); for (int i = 0, max = types.length; i < max; i++) { IType currentType = types[i]; if (currentType.getElementName().equals(oldTypeName)) { AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) ((JavaElement) currentType).findNode(astCU); if (typeNode != null) { // rename type rewriter.replace(typeNode.getName(), ast.newSimpleName(newTypeName), null); // rename constructors Iterator bodyDeclarations = typeNode.bodyDeclarations().iterator(); while (bodyDeclarations.hasNext()) { Object bodyDeclaration = bodyDeclarations.next(); if (bodyDeclaration instanceof MethodDeclaration) { MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; if (methodDeclaration.isConstructor()) { SimpleName methodName = methodDeclaration.getName(); if (methodName.getIdentifier().equals(oldTypeName)) { rewriter.replace(methodName, ast.newSimpleName(newTypeName), null); } } } } } } } } }