Method: VDMMessage(int, String, ILexLocation)

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.interpreter.messages;
25:
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.overture.ast.intf.lex.ILexLocation;
30:
31: /**
32: * The root of all reported messages.
33: */
34:
35: public class VDMMessage
36: {
37:         public final int number;
38:         public final String message;
39:         public final ILexLocation location;
40:
41:         protected List<String> details = new Vector<String>();
42:
43:         public VDMMessage(int number)
44:         {
45:                 this.number = number;
46:                 this.message = "";
47:                 this.location = null;
48:         }
49:
50:         public VDMMessage(int number, String message, ILexLocation location)
51:         {
52:                 this.number = number;
53:                 this.message = message;
54:                 this.location = location;
55:         }
56:
57:         public void add(String det)
58:         {
59:                 details.add(det);
60:         }
61:
62:         @Override
63:         public String toString()
64:         {
65:                 return String.format("%04d: %s %s", number, message, location);
66:         }
67:
68:         // This one is used by the GUI to generate strings for the problem
69:         // view, with details but without the file location and number.
70:
71:         public String toProblemString()
72:         {
73:                 StringBuilder sb = new StringBuilder();
74:                 sb.append(message);
75:
76:                 sb.append(".");
77:                 for (String d : details)
78:                 {
79:                         sb.append(" ");
80:                         sb.append(d);
81:                 }
82:
83:                 return sb.toString();
84:         }
85:
86:         @Override
87:         public boolean equals(Object other)
88:         {
89:                 if (other instanceof VDMMessage)
90:                 {
91:                         VDMMessage omsg = (VDMMessage) other;
92:                         return omsg.number == number && omsg.message.equals(message)
93:                                         && omsg.location.equals(location);
94:                 }
95:
96:                 return false;
97:         }
98:
99:         @Override
100:         public int hashCode()
101:         {
102:                 return number;
103:         }
104: }