1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package org.xwiki.blame.internal; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import org.xwiki.blame.AnnotatedContent; |
28 |
|
import org.xwiki.blame.AnnotatedElement; |
29 |
|
|
30 |
|
import difflib.Chunk; |
31 |
|
import difflib.Delta; |
32 |
|
import difflib.DiffUtils; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@param |
38 |
|
@param |
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 95.5% |
Uncovered Elements: 3 (67) |
Complexity: 19 |
Complexity Density: 0.5 |
|
42 |
|
public class DefaultAnnotatedContent<R, E> implements AnnotatedContent<R, E> |
43 |
|
{ |
44 |
|
private final List<R> sourceRevisions; |
45 |
|
private final List<E> initialContent; |
46 |
|
private final List<E> currentRevisionContent; |
47 |
|
private R currentRevision; |
48 |
|
private final List<Integer> elementList; |
49 |
|
private final int size; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
51 |
1 |
DefaultAnnotatedContent(R revision, List<E> initialContent)... |
52 |
|
{ |
53 |
1 |
this.size = initialContent.size(); |
54 |
1 |
this.sourceRevisions = new ArrayList<R>(this.size); |
55 |
1 |
this.initialContent = initialContent; |
56 |
1 |
this.currentRevisionContent = new ArrayList<E>(initialContent); |
57 |
1 |
this.currentRevision = revision; |
58 |
1 |
this.elementList = new ArrayList<>(this.size); |
59 |
6 |
for (int i = 0; i < size; i++) { |
60 |
5 |
this.sourceRevisions.add(null); |
61 |
5 |
this.elementList.add(i); |
62 |
|
} |
63 |
|
} |
64 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
65 |
|
private class AnnotatedContentIterator implements Iterator<AnnotatedElement<R, E>> |
66 |
|
{ |
67 |
|
private int index = -1; |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
5 |
@Override... |
70 |
|
public boolean hasNext() |
71 |
|
{ |
72 |
5 |
return index < (size - 1); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
75 |
5 |
@Override... |
76 |
|
public AnnotatedElement<R, E> next() |
77 |
|
{ |
78 |
5 |
index += 1; |
79 |
5 |
return new DefaultAnnotatedElement<R, E>(sourceRevisions.get(index), initialContent.get(index)); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public void remove() |
84 |
|
{ |
85 |
0 |
throw new UnsupportedOperationException(); |
86 |
|
} |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
1 |
@Override... |
90 |
|
public Iterator<AnnotatedElement<R, E>> iterator() |
91 |
|
{ |
92 |
1 |
return new AnnotatedContentIterator(); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
4 |
@Override... |
96 |
|
public R getOldestRevision() |
97 |
|
{ |
98 |
4 |
return currentRevision; |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
101 |
4 |
@Override... |
102 |
|
public boolean isEntirelyAnnotated() |
103 |
|
{ |
104 |
11 |
for (int i = 0; i < this.size; i++) { |
105 |
10 |
if (this.sourceRevisions.get(i) == null) { |
106 |
3 |
return false; |
107 |
|
} |
108 |
|
} |
109 |
1 |
return true; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
@param |
117 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 5 |
Complexity Density: 0.83 |
|
118 |
3 |
void analyseRevision(R revision, List<E> previous)... |
119 |
|
{ |
120 |
3 |
if (currentRevision == null) { |
121 |
0 |
return; |
122 |
|
} |
123 |
|
|
124 |
3 |
if (previous == null || previous.isEmpty()) { |
125 |
1 |
resolveRemainingToCurrent(); |
126 |
|
} else { |
127 |
2 |
resolveToCurrent(DiffUtils.diff(currentRevisionContent, previous).getDeltas()); |
128 |
2 |
assert currentRevisionContent.equals(previous) : "Patch application failed"; |
129 |
|
} |
130 |
|
|
131 |
3 |
currentRevision = revision; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
141 |
2 |
private void resolveToCurrent(List<Delta<E>> deltas)... |
142 |
|
{ |
143 |
2 |
int lineOffset = 0; |
144 |
|
|
145 |
2 |
for (Delta<E> d : deltas) { |
146 |
3 |
Chunk<E> original = d.getOriginal(); |
147 |
3 |
Chunk<E> revised = d.getRevised(); |
148 |
|
|
149 |
3 |
int pos = original.getPosition() + lineOffset; |
150 |
|
|
151 |
8 |
for (int i = 0; i < original.size(); i++) { |
152 |
5 |
int origLine = elementList.remove(pos); |
153 |
5 |
currentRevisionContent.remove(pos); |
154 |
5 |
if (origLine != -1) { |
155 |
4 |
sourceRevisions.set(origLine, currentRevision); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
6 |
for (int i = 0; i < revised.size(); i++) { |
160 |
3 |
currentRevisionContent.add(pos + i, revised.getLines().get(i)); |
161 |
3 |
elementList.add(pos + i, -1); |
162 |
|
} |
163 |
|
|
164 |
3 |
lineOffset += revised.size() - original.size(); |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
171 |
1 |
private void resolveRemainingToCurrent()... |
172 |
|
{ |
173 |
6 |
for (int i = 0; i < this.size; i++) { |
174 |
5 |
if (sourceRevisions.get(i) == null) { |
175 |
1 |
sourceRevisions.set(i, currentRevision); |
176 |
|
} |
177 |
|
} |
178 |
|
} |
179 |
|
} |