Hunk3.java
4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Decompiled with CFR 0_118.
*/
package com.day.util.diff;
import com.day.util.diff.DiffWriter;
import com.day.util.diff.Document;
import com.day.util.diff.Range;
import java.io.IOException;
public class Hunk3 {
static final String CVS_ID = "$URL$ $Rev$ $Date$";
public static final String[] MARKER_L = new String[]{"<<<<<<< ", ".mine"};
public static final String[] MARKER_R = new String[]{">>>>>>> ", ".theirs"};
public static final String[] MARKER_B = new String[]{"||||||| ", ".base"};
public static final String[] MARKER_M = new String[]{"=======", ""};
private final Range base;
private final Range left;
private final Range right;
private Hunk3 next;
public Hunk3(Range base, Range left, Range right, Hunk3 prev) {
this.base = base;
this.left = left;
this.right = right;
if (prev != null) {
prev.next = this;
}
}
public Hunk3 next() {
return this.next;
}
public Range getBaseRange() {
return this.base;
}
public Range getLeftRange() {
return this.left;
}
public Range getRightRange() {
return this.right;
}
public void write(DiffWriter out, boolean showBase) throws IOException {
int len;
int i;
boolean conflict;
boolean bl = conflict = this.left != null && this.right != null;
if (conflict) {
out.write(Hunk3.getMarker(MARKER_L, this.left.doc));
out.writeNewLine();
} else {
boolean bl2 = showBase = this.left == null && this.right == null;
}
if (this.left != null) {
len = Math.min(this.left.high, this.left.doc.getElements().length);
for (i = this.left.low; i < len; ++i) {
out.write(this.left.doc.getElements()[i].getString());
}
}
if (showBase) {
if (conflict) {
out.write(Hunk3.getMarker(MARKER_B, this.base.doc));
out.writeNewLine();
}
len = Math.min(this.base.high, this.base.doc.getElements().length);
for (i = this.base.low; i < len; ++i) {
out.write(this.base.doc.getElements()[i].getString());
}
}
if (conflict) {
out.write(Hunk3.getMarker(MARKER_M, null));
out.writeNewLine();
}
if (this.right != null) {
len = Math.min(this.right.high, this.right.doc.getElements().length);
for (i = this.right.low; i < len; ++i) {
out.write(this.right.doc.getElements()[i].getString());
}
}
if (conflict) {
out.write(Hunk3.getMarker(MARKER_R, this.right.doc));
out.writeNewLine();
}
}
public String toString() {
int i;
StringBuffer buf = new StringBuffer();
buf.append("@@ =").append(this.base).append(" -").append(this.left).append(" +").append(this.right).append(" @@\n");
if (this.left != null) {
for (i = 0; i < this.left.len(); ++i) {
this.addLineNumbers(buf, i);
buf.append("< ");
buf.append(this.left.doc.getElements()[i + this.left.low]);
}
}
if (this.base != null) {
for (i = 0; i < this.base.len(); ++i) {
this.addLineNumbers(buf, i);
buf.append("= ");
buf.append(this.base.doc.getElements()[i + this.base.low]);
}
}
if (this.right != null) {
for (i = 0; i < this.right.len(); ++i) {
this.addLineNumbers(buf, i);
buf.append("> ");
buf.append(this.right.doc.getElements()[i + this.right.low]);
}
}
return buf.toString();
}
private void addLineNumbers(StringBuffer buf, int i) {
buf.append("(").append(i + this.base.low);
if (this.left != null) {
buf.append(",").append(i + this.left.low);
}
if (this.right != null) {
buf.append(",").append(i + this.right.low);
}
buf.append(") ");
}
public static String getMarker(String[] fmt, Document doc) {
StringBuffer buf = new StringBuffer(fmt[0]);
if (doc != null && doc.getSource() != null && doc.getSource().getLabel() != null) {
buf.append(doc.getSource().getLabel());
} else {
buf.append(fmt[1]);
}
return buf.toString();
}
}