-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AstComparator.compare(File, File) only compares the first type of the file #154
Comments
FYI this usability issue was pointed out to me by @algomaster99, I simply looked at what caused it. I'd be happy to provide a PR to compare the entire compilation units of the files, if that's desirable for the project. |
Hi @slarse, @algomaster99 Thanks for reporting the issue.
Great, thanks. PRs are welcome. One idea would be to create the ITree for each type, then to put each tree as child of a new root node. That node is then passed to the diff algorithm. |
I'm not sure it has to be all too complicated. Just comparing the packages instead of the types kind of works: /**
* compares two java files
*/
public Diff compare(File f1, File f2) throws Exception {
// of course, we need a null check here, this is just to illustrate the concept!
return this.compare(getCtType(f1).getPackage(), getCtType(f2).getPackage());
} Although there is one very odd move operation from one unnamed package to another unnamed package, but I think that's just a matter of tweaking how operations are computed. In Spork, I build an ITree of the unnamed module using gumtree-spoon and then use a GumTree matcher directly on that, and there are no problems merging files with multiple type declarations. So, I don't think this should be too difficult. Thoughts? |
Great idea! |
Cool, I'll start working on a PR when time allows :) |
Great! |
yes, the API should be able to support modules |
When the input is a file, it doesn't matter, the module will always be the unnamed module. If the input is a directory, then it would potentially matter. But as far as I can tell, the method we're talking about here is not designed to take a directory as input, only a regular file. So, to summarize, if you want to support directories then it might be worthwile. If you only want to support regular files then comparing the root packages is sufficient. |
AstComparator.compare(File, File)
only compares the first type of the compilation unit. So, given a file with multiple type declarations, such as this:And compare it with this:
only
Klass
andKlazz
are actually compared. The cause of this is thatAstComparator.compare(File, File)
uses thegetCtType()
method, which only fetches a single type.That's pretty unexpected to me. Is this a bug, or intentional? It seems more appropriate to me to compare the compilation units as a whole.
The text was updated successfully, but these errors were encountered: