Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ExceptionInfo.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | 2747b0723867 |
children | 2bf6f917a7e5 |
comparison
equal
deleted
inserted
replaced
422:5d1cc7366d04 | 423:9c9c442b5f2e |
---|---|
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; | |
21 import static org.tmatesoft.hg.repo.HgRepository.TIP; | |
22 import static org.tmatesoft.hg.repo.HgRepository.WORKING_COPY; | |
20 | 23 |
21 import java.io.File; | 24 import java.io.File; |
22 | 25 |
23 import org.tmatesoft.hg.core.Nodeid; | 26 import org.tmatesoft.hg.core.Nodeid; |
24 import org.tmatesoft.hg.repo.HgRepository; | 27 import org.tmatesoft.hg.repo.HgRepository; |
31 * @author Artem Tikhomirov | 34 * @author Artem Tikhomirov |
32 * @author TMate Software Ltd. | 35 * @author TMate Software Ltd. |
33 */ | 36 */ |
34 public class ExceptionInfo<T> { | 37 public class ExceptionInfo<T> { |
35 protected final T owner; | 38 protected final T owner; |
36 protected int revNumber = BAD_REVISION; | 39 protected Integer revNumber = null; |
37 protected Nodeid revision; | 40 protected Nodeid revision; |
38 protected Path filename; | 41 protected Path filename; |
39 protected File localFile; | 42 protected File localFile; |
43 // next two make sense only when revNumber was set | |
44 private int rangeLeftBoundary = BAD_REVISION, rangeRightBoundary = BAD_REVISION; | |
40 | 45 |
41 /** | 46 /** |
42 * @param owner instance to return from setters | 47 * @param owner instance to return from setters |
43 */ | 48 */ |
44 public ExceptionInfo(T owner) { | 49 public ExceptionInfo(T owner) { |
47 | 52 |
48 /** | 53 /** |
49 * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time | 54 * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time |
50 */ | 55 */ |
51 public int getRevisionIndex() { | 56 public int getRevisionIndex() { |
52 return revNumber; | 57 return revNumber == null ? HgRepository.BAD_REVISION : revNumber; |
53 } | 58 } |
54 | 59 |
55 public T setRevisionIndex(int rev) { | 60 public T setRevisionIndex(int rev) { |
56 revNumber = rev; | 61 revNumber = rev; |
57 return owner; | 62 return owner; |
58 } | 63 } |
59 | 64 |
60 public boolean isRevisionIndexSet() { | 65 public boolean isRevisionIndexSet() { |
61 return revNumber != BAD_REVISION; | 66 return revNumber != null; |
62 } | 67 } |
63 | 68 |
64 /** | 69 /** |
65 * @return non-null only when revision was supplied at construction time | 70 * @return non-null only when revision was supplied at construction time |
66 */ | 71 */ |
98 * @return file object that causes troubles, or <code>null</code> if specific file is unknown | 103 * @return file object that causes troubles, or <code>null</code> if specific file is unknown |
99 */ | 104 */ |
100 public File getFile() { | 105 public File getFile() { |
101 return localFile; | 106 return localFile; |
102 } | 107 } |
108 | |
109 public T setRevisionIndexBoundary(int revisionIndex, int rangeLeft, int rangeRight) { | |
110 setRevisionIndex(revisionIndex); | |
111 rangeLeftBoundary = rangeLeft; | |
112 rangeRightBoundary = rangeRight; | |
113 return owner; | |
114 } | |
103 | 115 |
104 public StringBuilder appendDetails(StringBuilder sb) { | 116 public StringBuilder appendDetails(StringBuilder sb) { |
105 if (filename != null) { | 117 if (filename != null) { |
106 sb.append("path:'"); | 118 sb.append("path:'"); |
107 sb.append(filename); | 119 sb.append(filename); |
108 sb.append('\''); | 120 sb.append('\''); |
109 sb.append(';'); | 121 sb.append(';'); |
110 sb.append(' '); | 122 sb.append(' '); |
111 } | 123 } |
112 sb.append("rev:"); | 124 sb.append("rev:"); |
113 if (revNumber != BAD_REVISION) { | 125 boolean needNodeid = true; |
114 sb.append(revNumber); | 126 if (isRevisionIndexSet()) { |
115 if (revision != null) { | 127 if (rangeLeftBoundary != BAD_REVISION || rangeRightBoundary != BAD_REVISION) { |
116 sb.append(':'); | 128 String sr; |
129 switch (getRevisionIndex()) { | |
130 case BAD_REVISION: | |
131 sr = "UNKNOWN"; break; | |
132 case TIP: | |
133 sr = "TIP"; break; | |
134 case WORKING_COPY: | |
135 sr = "WORKING-COPY"; break; | |
136 case NO_REVISION: | |
137 sr = "NO REVISION"; break; | |
138 default: | |
139 sr = String.valueOf(getRevisionIndex()); | |
140 } | |
141 sb.append(String.format("%s is not from [%d..%d]", sr, rangeLeftBoundary, rangeRightBoundary)); | |
142 } else { | |
143 sb.append(getRevisionIndex()); | |
144 if (isRevisionIndexSet()) { | |
145 sb.append(':'); | |
146 sb.append(getRevision().shortNotation()); | |
147 needNodeid = false; | |
148 } | |
117 } | 149 } |
118 } | 150 } |
119 if (revision != null) { | 151 if (isRevisionSet() && needNodeid) { |
120 sb.append(revision.shortNotation()); | 152 sb.append(getRevision().shortNotation()); |
121 } | 153 } |
122 if (localFile != null) { | 154 if (localFile != null) { |
123 sb.append(';'); | 155 sb.append(';'); |
124 sb.append(' '); | 156 sb.append(' '); |
125 sb.append(" file:"); | 157 sb.append(" file:"); |