[MonoDevelop] RefactoringCommands: Encapsulate Fields initial implementation

Miguel Ángel Pérez mangelp at gmail.com
Thu Apr 26 03:47:32 EDT 2007

Thanks for the comments!

2007/4/24, Lluis Sanchez <lluis at ximian.com>:
> El dt 24 de 04 del 2007 a les 13:40 +0200, en/na Miguel Ángel Pérez va
> escriure:
> > Hello all!
> >
> > I have been doing some coding with the encapsulate field command and i
> > have got an initial implementation that generates the code for the
> > property and changes the visibility for the field if its public or
> > protected to private.
> Thanks for the patch!
> >
> > To do the code generation I've created an internal helper class named
> > CodeGeneratorHelper in the class CodeRefactorer
> > (Monodevelop.Ide.Projects.CodeGeneration namespace) that implements
> > it.
> > I don't know if there is already some class that can generate CodeDom
> > namespace objects from an IMember so i have implemented something.
> >
> > What i haven't done is renaming the references to the property, since
> > is a thing that Lluis must know better than nobody, can you suggest
> > how it could be done?
> You can use CodeRefactorer.FindMemberReferences to get a list of
> references. However, this is not about renaming references, but about
> changing a field reference by a property reference, and this is a
> language-specific operation.
> >
> > I've also done some changes to BaseRefactorer class to allow a
> > parameter with the buffer to modify so the change is done to the
> > editor buffer instead of the file in disk. This makes necessary to
> > call the methods with an unboxing instead of using the interface
> > IRefactorer.
> > It's look like this class could be improved with changes like this
> > that helps in the operations needed to implement more refactoring
> > commands.
> CodeRefactorer has a TextFileProvider property which allows setting an
> ITextFileProvider implementation. This interface implementation will
> then be used by CodeRefactorer and RefactorerContext to get the files to
> read or modify.
> Notice that the follow method signature in BaseRefactorer is incorrect:
> public CodeTypeMember RenameMember (RefactorerContext ctx, IClass cls,
> IMember member, string newName, IEditableTextFile file)
> because the location of an IClass is language dependent. For example, if
> cls is a partial class, RenameMember should rename the class in all
> files that implement that class, so the 'file' parameter here doesn't
> help.

Right, I'll undo those changes.

If you want CodeRefactorer to modify files from the editor, you should
> create a ITextFileProvider implementation which returns such files. You
> can look in MonoDevelop.GtkCore for an example. Look for the class
> OpenDocumentFileProvider. Maybe we should move this class to
> MonoDevelop.Ide.Gui, so it can be reused.

I can copy the class somewhere so if it's moved i only have to include the
namespace to rehuse it.

I also agree with the comments by Ben. Also, it looks like the indenting
> of the code is not consistent, maybe you are mixing tabs and spaces for
> indenting?

Yes i have mixed tabs and spaces :S, I'll fix it in the next path.

For the next patch i will follow Ben comments and do some dialog to let the
user configure the behaviour and do some more intelligent refactoring work.

> Lluis.

-- Regards --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monodevelop-list/attachments/20070426/aa679391/attachment.html 

More information about the Monodevelop-list mailing list