mauricioaniche/repodriller

getAddedLines and getRemovedLines

Opened this issue · 9 comments

In org.repodriller.domain.Modification.java there are getAdded() and getRemoved(), methods that return the number of added and removed lines.

However, there is no way to get the actual lines that are added and removed.
Indeed, this is done in other classes (DiffParser and DiffBlock).

Isn't it better to add these method in the Modification.java instead?

Looking through here, I'm a bit confused about why Modification doesn't make use of the various Diff classes.

It would make more sense to me if a Modification returned your choice of the raw diff or a list of DiffBlocks as available via DiffParser. If it returned the DiffBlocks then extracting the added/removed lines would become the problem of a DiffBlock.

In general I think it makes sense to minimize the use of raw diffs -- parsing them into a more powerful class as done by DiffParser seems like the way to go.

@mauricioaniche It's hard for me to understand the current design. Can you help out?

DiffParser indeed currently looks like a utility helper. No reason for that. We can definitely make Modification to return the more elegant diff objects provided by DiffParser.

But I guess what Davide wanted in this issue was a method that would return only the added lines. However, using the Diff objects, one can easily write a lambda for that (using the DiffLineType).

Yes, that's what I had in mind. If a Modification can return something semantically relevant instead of a raw diff, then the caller can easily extract the added and removed lines. I don't think Modification itself should need to do that.

@ishepard Would this meet your needs?

Yes indeed this is exactly what I wanted.

DiffParser and DiffBlock classes are hidden in the middle of repodriller. In my opinion, Modification should not return the raw diff, but it should use this helper classes to return a more elegant object. This would help a lot the life of miners ;)

@mauricioaniche This would be a breaking change. Thoughts?

We should not remove the return the raw diff as that would be a breaking change, indeed. However, we can add new methods to Modification that encapsulates the new DiffParser(..).parse(), so that users can easily find this feature. New methods are welcome!

@ayaankazerouni Did you do anything for this?