It's a continuation of the one I wrote earlier (or yesterday).
Click here for the relevant article!
I wrote a Java source analysis tool in Java ... https://qiita.com/banana5388/items/cd8a549d1885aa6dd039
In the comment of the previous article, you pointed out that "let's start with something simple", so I started by simply getting the number of difference steps between the two source codes.
(Don't say redevelopment of the wheels !!!!!! It was fun to make something !!!) </ font>
So the input and output of what I will create this time is like this.
INPUT :Absolute path of comparison source and comparison destination
OUTPUT:Number of steps with different code
What I was thinking about for the time being is something like this.
For the time being, I implemented this as it is.
The implementation of the main part looks like this.
JavaCodeDifference.java
/**
*Compares two codes and returns the number of matching lines
*
* @param origCode Comparison source code (stored in a list for each line)
* @param destCode Comparison code (stored in a list for each line)
* @return Number of matching lines for comparison
*/
public static int countCodeDiff(List<String> origCode, List<String> destCode) {
int cnt = 0;
//Generating iterators for strings
//The method "getNotIncludeIgnoreCode" is based on the line-by-line code information stored in the list.
//Erase half-width spaces, full-width spaces, tab characters, and line feed characters, and add a line feed character at the end.
//It is a method that finally returns as one character string (String type).
StringCharacterIterator origCodeIterator = new StringCharacterIterator(getNotIncludeIgnoreCode(origCode));
StringCharacterIterator destCodeIterator = new StringCharacterIterator(getNotIncludeIgnoreCode(destCode));
//Execute until the character of either the comparison source or the comparison destination ends
while (origCodeIterator.current() != StringCharacterIterator.DONE &&
destCodeIterator.current() != StringCharacterIterator.DONE) {
//Increase the count when different code characters are included in the comparison source and comparison destination, and the comparison destination has a line break first.
if (origCodeIterator.current() == destCodeIterator.current()) {
destCodeIterator.next();
origCodeIterator.next();
} else {
if (destCodeIterator.current() == '\n') {
cnt++;
}
destCodeIterator.next();
}
}
return cnt;
}
Um, isn't it a good feeling? ??
I prepared the text for testing.
test1.java
aaaa
iiii
uuuu
test2.java
aaaa
iiii
uuuu
It's not a java file at all, but for the time being, it's for testing, so is this okay? Well, the output is. .. ..
> Number of different lines: 0
Yeah, it looks good.
Another test
test1.java
aaaa
iiii
uuuu
test2.java
aaa
iii
uuu
Well, the output is. .. ..
> Difference Code Line Count:3
This looks good too.
For the time being, I am satisfied because it is moving according to the specifications.
Rather, the specifications are rather loose ... I would like to reimplement it so that it can be used.
Yes. https://github.com/satodaiki/DiffTool
2018/12/2 First edition 2018/12/3 There was some error in the source, so I fixed it.
Recommended Posts