codeshovel icon indicating copy to clipboard operation
codeshovel copied to clipboard

Handle nested classes

Open ataraxie opened this issue 7 years ago • 7 comments

Nested classes are not handled properly. For example, the Guava project makes use (or: used to make use) of nested classes heavily, with methods with the same name being present both in the parent class and the nested class. CodeShovel will in these case mismatch methods and overwrite output files.

ataraxie avatar Aug 07 '18 19:08 ataraxie

This has most likely been resolved with a recent commit.

ataraxie avatar Jan 09 '21 23:01 ataraxie

I was thinking it might also be nice to handle this kind of change as a Context change perhaps? Especially in a language like Python or TypeScript where you can have many kinds at the top level of the class, or a function in a function.

I noticed that the parent name is kept, but changes to the parent name are not reported to the user unless the filename is changed.

braxtonhall avatar Feb 15 '21 01:02 braxtonhall

Yeah that sounds really smart. You can totally go ahead if you think it makes sense for your use case :)

ataraxie avatar Feb 16 '21 01:02 ataraxie

Checked into this again and yes, this is closely related to your question in #52. The commit you mentioned made CodeShovel work for two nested methods in the Oracle. But please feel free to change this. Don't let it block your progress.

ataraxie avatar Feb 16 '21 02:02 ataraxie

okidoki as soon as #51 is merged I'll add in Context Change or Parent Change

braxtonhall avatar Feb 16 '21 23:02 braxtonhall

OK just some thinking: if a method is moved to another class in the same file, should this be the same or different than the parent getting renamed?

It seems like the same split as a movefromfile vs file rename, just within the file, so maybe we need two change types not just one.

For example if there's just a rename, I don't really care about this change. self and this still refer to the same thing. However pulling the function into another class has a bigger effect as identifiers in the function body refer to different things altogether.

braxtonhall avatar Feb 17 '21 21:02 braxtonhall

@braxtonhall this sounds like the way to go. If the containing class changes we'd want to know that, even if it happens to stay in the same file. Either way it's an extract method refactoring, so it would be correct to track it.

rtholmes avatar Feb 18 '21 00:02 rtholmes