Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc7c714

Browse files
committed
Merge origin/master
2 parentsdcc29ee +f0f5d24 commitfc7c714

File tree

7 files changed

+154
-4
lines changed

7 files changed

+154
-4
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
build/
33
nbproject/
44
target/
5+
6+
*.iml

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This project uses a custom versioning scheme (and not [Semantic Versioning](http
77

88
##[Unreleased]
99

10+
###Changed
11+
12+
* UnifiedDiffReader improved for**new file mode** and better timestamp recognition
13+
1014
##[4.7]
1115

1216
###Changed

‎java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,31 @@ private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<Strin
9797
List<String>oldChunkLines =newArrayList<>();
9898
List<String>newChunkLines =newArrayList<>();
9999

100+
List<Integer>removePosition =newArrayList<>();
101+
List<Integer>addPosition =newArrayList<>();
102+
intremoveNum =0;
103+
intaddNum =0;
100104
for (String[]raw_line :rawChunk) {
101105
tag =raw_line[0];
102106
rest =raw_line[1];
103107
if (" ".equals(tag) ||"-".equals(tag)) {
108+
removeNum++;
104109
oldChunkLines.add(rest);
110+
if ("-".equals(tag)) {
111+
removePosition.add(old_ln -1 +removeNum);
112+
}
105113
}
106114
if (" ".equals(tag) ||"+".equals(tag)) {
115+
addNum++;
107116
newChunkLines.add(rest);
117+
if ("+".equals(tag)) {
118+
addPosition.add(new_ln -1 +addNum);
119+
}
108120
}
109121
}
110122
patch.addDelta(newChangeDelta<>(newChunk<>(
111-
old_ln -1,oldChunkLines),newChunk<>(
112-
new_ln -1,newChunkLines)));
123+
old_ln -1,oldChunkLines,removePosition),newChunk<>(
124+
new_ln -1,newChunkLines,addPosition)));
113125
rawChunk.clear();
114126
}
115127
}

‎java-diff-utils/src/main/java/com/github/difflib/patch/Chunk.java‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ public final class Chunk<T> {
3737

3838
privatefinalintposition;
3939
privateList<T>lines;
40+
privatefinalList<Integer>changePosition;
4041

4142
/**
4243
* Creates a chunk and saves a copy of affected lines
4344
*
4445
* @param position the start position
4546
* @param lines the affected lines
47+
* @param changePosition the positions of changed lines
4648
*/
47-
publicChunk(intposition,List<T>lines) {
49+
publicChunk(intposition,List<T>lines,List<Integer>changePosition) {
4850
this.position =position;
4951
this.lines =newArrayList<>(lines);
52+
this.changePosition =changePosition;
5053
}
5154

5255
/**
@@ -55,9 +58,31 @@ public Chunk(int position, List<T> lines) {
5558
* @param position the start position
5659
* @param lines the affected lines
5760
*/
58-
publicChunk(intposition,T[]lines) {
61+
publicChunk(intposition,List<T>lines) {
62+
this(position,lines,null);
63+
}
64+
65+
/**
66+
* Creates a chunk and saves a copy of affected lines
67+
*
68+
* @param position the start position
69+
* @param lines the affected lines
70+
* @param changePosition the positions of changed lines
71+
*/
72+
publicChunk(intposition,T[]lines,List<Integer>changePosition) {
5973
this.position =position;
6074
this.lines =Arrays.asList(lines);
75+
this.changePosition =changePosition;
76+
}
77+
78+
/**
79+
* Creates a chunk and saves a copy of affected lines
80+
*
81+
* @param position the start position
82+
* @param lines the affected lines
83+
*/
84+
publicChunk(intposition,T[]lines) {
85+
this(position,lines,null);
6186
}
6287

6388
/**
@@ -96,6 +121,13 @@ public List<T> getLines() {
96121
returnlines;
97122
}
98123

124+
/**
125+
* @return the positions of changed lines of chunk in the text
126+
*/
127+
publicList<Integer>getChangePosition() {
128+
returnchangePosition;
129+
}
130+
99131
publicintsize() {
100132
returnlines.size();
101133
}

‎java-diff-utils/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packagecom.github.difflib;
22

3+
importcom.github.difflib.patch.Chunk;
34
importcom.github.difflib.patch.Patch;
45
importcom.github.difflib.patch.PatchFailedException;
56
importjava.io.BufferedReader;
@@ -8,9 +9,11 @@
89
importjava.io.IOException;
910
importjava.util.ArrayList;
1011
importjava.util.Arrays;
12+
importjava.util.Collections;
1113
importjava.util.List;
1214
importstaticjava.util.stream.Collectors.joining;
1315
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
16+
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
1417
importstaticorg.junit.jupiter.api.Assertions.fail;
1518
importorg.junit.jupiter.api.Test;
1619

@@ -126,6 +129,44 @@ public void testNewFileCreation() {
126129
UnifiedDiffUtils.parseUnifiedDiff(udiff);
127130
}
128131

132+
/**
133+
* Issue 89
134+
*/
135+
@Test
136+
publicvoidtestChagngePosition()throwsIOException {
137+
finalList<String>patchLines =fileToLines(TestConstants.MOCK_FOLDER +"issue89_patch.txt");
138+
finalPatch<String>patch =UnifiedDiffUtils.parseUnifiedDiff(patchLines);
139+
List<Integer>realRemoveListOne =Collections.singletonList(3);
140+
List<Integer>realAddListOne =Arrays.asList(3,7,8,9,10,11,12,13,14);
141+
validateChangePosition(patch,0,realRemoveListOne,realAddListOne);
142+
List<Integer>realRemoveListTwo =newArrayList<>();
143+
List<Integer>realAddListTwo =Arrays.asList(27,28);
144+
validateChangePosition(patch,1,realRemoveListTwo,realAddListTwo);
145+
146+
}
147+
148+
privatevoidvalidateChangePosition(Patch<String>patch,intindex,List<Integer>realRemoveList,
149+
List<Integer>realAddList ) {
150+
finalChunkoriginChunk =patch.getDeltas().get(index).getSource();
151+
List<Integer>removeList =originChunk.getChangePosition();
152+
assertEquals(realRemoveList.size(),removeList.size());
153+
for (Integerele:realRemoveList) {
154+
assertTrue(realRemoveList.contains(ele));
155+
}
156+
for (Integerele:removeList) {
157+
assertTrue(realAddList.contains(ele));
158+
}
159+
finalChunktargetChunk =patch.getDeltas().get(index).getTarget();
160+
List<Integer>addList =targetChunk.getChangePosition();
161+
assertEquals(realAddList.size(),addList.size());
162+
for (Integerele:realAddList) {
163+
assertTrue(addList.contains(ele));
164+
}
165+
for (Integerele:addList) {
166+
assertTrue(realAddList.contains(ele));
167+
}
168+
}
169+
129170
privatevoidverify(List<String>origLines,List<String>revLines,
130171
StringoriginalFile,StringrevisedFile) {
131172
Patch<String>patch =DiffUtils.diff(origLines,revLines);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- Origin.java2020-06-11 11:06:21.000000000 +0800
2+
+++ Update.java2020-06-11 10:59:48.000000000 +0800
3+
@@ -1,9 +1,17 @@
4+
package checkstyle_demo.PatchSuppression.MultiChangeInOneFile;
5+
6+
-public class Origin {
7+
+public class Update {
8+
public void test1() {
9+
10+
}
11+
+
12+
+ public void test2() {
13+
+
14+
+ }
15+
+
16+
+ public void test3() {
17+
+
18+
+ }
19+
}
20+
21+
class BasicTest {
22+
@@ -16,5 +24,7 @@
23+
class Test2 {
24+
public void test1() {
25+
System.out.println();
26+
+ System.out.println();
27+
+ System.out.println();
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package checkstyle_demo.PatchSuppression.MultiChangeInOneFile;
2+
3+
public class issue89_revised {
4+
public void test1() {
5+
6+
}
7+
8+
public void test2() {
9+
10+
}
11+
12+
public void test3() {
13+
14+
}
15+
}
16+
17+
class Test {
18+
private int i;
19+
void foo() {
20+
i++;
21+
}
22+
}
23+
24+
class Test2 {
25+
public void test1() {
26+
System.out.println();
27+
System.out.println();
28+
System.out.println();
29+
}
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp