comparison src/org/tmatesoft/hg/core/HgException.java @ 403:2747b0723867

FIXMEs: work on exceptions and javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Mar 2012 14:50:51 +0100
parents 0ae53c32ecef
children 6437d261048a
comparison
equal deleted inserted replaced
402:1fcc7f7b6d65 403:2747b0723867
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; 19 import org.tmatesoft.hg.internal.ExceptionInfo;
20
21 import org.tmatesoft.hg.repo.HgRepository; 20 import org.tmatesoft.hg.repo.HgRepository;
22 import org.tmatesoft.hg.util.Path; 21 import org.tmatesoft.hg.util.Path;
23 22
24 /** 23 /**
25 * Root class for all hg4j exceptions. 24 * Root class for all hg4j exceptions.
27 * @author Artem Tikhomirov 26 * @author Artem Tikhomirov
28 * @author TMate Software Ltd. 27 * @author TMate Software Ltd.
29 */ 28 */
30 @SuppressWarnings("serial") 29 @SuppressWarnings("serial")
31 public class HgException extends Exception { 30 public class HgException extends Exception {
32 31
33 protected int revNumber = BAD_REVISION; 32 protected final ExceptionInfo<HgException> extras = new ExceptionInfo<HgException>(this);
34 protected Nodeid revision;
35 protected Path filename;
36 33
37 public HgException(String reason) { 34 public HgException(String reason) {
38 super(reason); 35 super(reason);
39 } 36 }
40 37
48 45
49 /** 46 /**
50 * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time 47 * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time
51 */ 48 */
52 public int getRevisionIndex() { 49 public int getRevisionIndex() {
53 return revNumber; 50 return extras.getRevisionIndex();
54 } 51 }
55 52
56 /** 53 /**
57 * @deprecated use {@link #getRevisionIndex()} 54 * @deprecated use {@link #getRevisionIndex()}
58 */ 55 */
60 public int getRevisionNumber() { 57 public int getRevisionNumber() {
61 return getRevisionIndex(); 58 return getRevisionIndex();
62 } 59 }
63 60
64 public HgException setRevisionIndex(int rev) { 61 public HgException setRevisionIndex(int rev) {
65 revNumber = rev; 62 return extras.setRevisionIndex(rev);
66 return this;
67 } 63 }
68 64
69 public boolean isRevisionIndexSet() { 65 public boolean isRevisionIndexSet() {
70 return revNumber != BAD_REVISION; 66 return extras.isRevisionIndexSet();
71 } 67 }
72 68
73 /** 69 /**
74 * @deprecated use {@link #setRevisionIndex(int)} 70 * @deprecated use {@link #setRevisionIndex(int)}
75 */ 71 */
80 76
81 /** 77 /**
82 * @return non-null only when revision was supplied at construction time 78 * @return non-null only when revision was supplied at construction time
83 */ 79 */
84 public Nodeid getRevision() { 80 public Nodeid getRevision() {
85 return revision; 81 return extras.getRevision();
86 } 82 }
87 83
88 public HgException setRevision(Nodeid r) { 84 public HgException setRevision(Nodeid r) {
89 revision = r; 85 return extras.setRevision(r);
90 return this;
91 } 86 }
92 87
93 public boolean isRevisionSet() { 88 public boolean isRevisionSet() {
94 return revision != null; 89 return extras.isRevisionSet();
95 } 90 }
96 91
97 /** 92 /**
98 * @return non-null only if file name was set at construction time 93 * @return non-null only if file name was set at construction time
99 */ 94 */
100 public Path getFileName() { 95 public Path getFileName() {
101 return filename; 96 return extras.getFileName();
102 } 97 }
103 98
104 public HgException setFileName(Path name) { 99 public HgException setFileName(Path name) {
105 filename = name; 100 return extras.setFileName(name);
106 return this;
107 }
108
109 protected void appendDetails(StringBuilder sb) {
110 if (filename != null) {
111 sb.append("path:'");
112 sb.append(filename);
113 sb.append('\'');
114 sb.append(';');
115 sb.append(' ');
116 }
117 sb.append("rev:");
118 if (revNumber != BAD_REVISION) {
119 sb.append(revNumber);
120 if (revision != null) {
121 sb.append(':');
122 }
123 }
124 if (revision != null) {
125 sb.append(revision.shortNotation());
126 }
127 } 101 }
128 102
129 @Override 103 @Override
130 public String toString() { 104 public String toString() {
131 StringBuilder sb = new StringBuilder(super.toString()); 105 StringBuilder sb = new StringBuilder(super.toString());
132 sb.append(' '); 106 sb.append(' ');
133 sb.append('('); 107 sb.append('(');
134 appendDetails(sb); 108 extras.appendDetails(sb);
135 sb.append(')'); 109 sb.append(')');
136 return sb.toString(); 110 return sb.toString();
137 } 111 }
138 // /* XXX CONSIDER capability to pass extra information about errors */ 112 // /* XXX CONSIDER capability to pass extra information about errors */
139 // public static class Status { 113 // public static class Status {