Package: DebuggerProperties

DebuggerProperties

nameinstructionbranchcomplexitylinemethod
DebuggerProperties()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDefaults()
M: 82 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.utils;
23:
24: import java.lang.reflect.Field;
25: import java.util.HashSet;
26: import java.util.Set;
27:
28: import org.overture.parser.config.Properties;
29:
30: public class DebuggerProperties
31: {
32:         public static class DebuggerProperty implements
33:                         Comparable<DebuggerProperty>
34:         {
35:                 public final String name;
36:                 public Boolean bValue;
37:                 public Integer iValue;
38:
39:                 public enum ValueType
40:                 {
41:                         Bool, Int
42:                 };
43:
44:                 public final ValueType type;
45:
46:                 public DebuggerProperty(String name, Boolean value)
47:                 {
48:                         this.name = name;
49:                         this.type = ValueType.Bool;
50:                         this.bValue = value;
51:                 }
52:
53:                 public DebuggerProperty(String name, Integer value)
54:                 {
55:                         this.name = name;
56:                         this.type = ValueType.Int;
57:                         this.iValue = value;
58:                 }
59:
60:                 public static DebuggerProperty load(String propertyString)
61:                                 throws Exception
62:                 {
63:                         try
64:                         {
65:                                 String[] parts = propertyString.split("=");
66:
67:                                 String name = parts[0].trim().replace('.', '_');
68:                                 parts[1] = parts[1].trim();
69:
70:                                 if (parts[1].equals("true") || parts[1].equals("false"))
71:                                 {
72:                                         return new DebuggerProperty(name, Boolean.valueOf(parts[1]));
73:                                 }
74:                                 return new DebuggerProperty(name, Integer.valueOf(parts[1]));
75:                         } catch (Exception e)
76:                         {
77:                                 throw new Exception("Invalid property string");
78:                         }
79:                 }
80:
81:                 @Override
82:                 public String toString()
83:                 {
84:                         String tmp = name.replace('_', '.');
85:                         switch (type)
86:                         {
87:                                 case Bool:
88:                                         return tmp + " = " + bValue;
89:                                 case Int:
90:                                         return tmp + " = " + iValue;
91:                                 default:
92:                                         return super.toString();
93:                         }
94:                 }
95:
96:                 public int compareTo(DebuggerProperty o)
97:                 {
98:                         return this.name.compareTo(o.name);
99:                 }
100:         }
101:
102:         public static Set<DebuggerProperty> getDefaults()
103:                         throws IllegalArgumentException, IllegalAccessException
104:         {
105:                 Object propertiesInstance = new Properties();
106:                 Set<DebuggerProperty> props = new HashSet<DebuggerProperty>();
107:
108:•                for (Field f : Properties.class.getFields())
109:                 {
110:•                        if (f.getType().getName().equals(Boolean.class.getName())
111:•                                        || f.getType().getName().equals("boolean"))
112:                         {
113:                                 DebuggerProperty p = new DebuggerProperty(f.getName(), f.getBoolean(propertiesInstance));
114:                                 props.add(p);
115:•                        } else if (f.getType().getName().equals(Integer.class.getName())
116:•                                        || f.getType().getName().equals("int"))
117:                         {
118:                                 DebuggerProperty p = new DebuggerProperty(f.getName(), f.getInt(propertiesInstance));
119:                                 props.add(p);
120:                         }
121:
122:                 }
123:
124:                 return props;
125:         }
126: }