EOS 2  1.1.0
Einfache Objektbasierte Sprache
SystemType.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.baseparser;
2 
3 import de.lathanda.eos.vm.MJavaClass;
4 import de.lathanda.eos.vm.MType;
5 import de.lathanda.eos.vm.MissingTypeException;
6 import de.lathanda.eos.vm.ObjectSource;
7 
8 import java.util.LinkedList;
9 import java.util.TreeMap;
10 
11 
18 public class SystemType extends Type implements Comparable<Type>, AutoCompleteType {
19  protected final TreeMap<String, MethodType> getProperty = new TreeMap<>();
20  protected final TreeMap<String, MethodType> setProperty = new TreeMap<>();
21  protected final TreeMap<String, java.lang.reflect.Method> viewProperty = new TreeMap<>();
22  // type maps
23  private static final TreeMap<String, SystemType> nameType = new TreeMap<>();
24  private static final TreeMap<String, SystemType> idType = new TreeMap<>();
25  protected static SystemType CLASS;
26  // special types
27  private static SystemType WINDOW;
28  private static SystemMethodType WINDOW_ADD_FIGURE;
29  private static SystemType FIGURE;
30 
31  private final ObjectSource objSrc;
32  private final Class<?> cls;
33 
34  private final String name;
35  private SystemType(String id, String name, ObjectSource objSrc, Class<?> cls) {
36  super(id);
37  this.objSrc = objSrc;
38  this.cls = cls;
39  this.name = name;
40  }
41 
42  public static SystemType registerType(String id, String[] names, ObjectSource objSrc, Class<?> cls) {
43  SystemType type = new SystemType(id, names[0], objSrc, cls);
44  if (names != null) {
45  for (String name : names) {
46  nameType.put(name.trim().toLowerCase(), type);
47  }
48  }
49  idType.put(id, type);
50  switch (id) {
51  case "integer":
52  INTEGER = type;
53  break;
54  case "?":
55  UNKNOWN = type;
56  break;
57  case "class":
58  CLASS = type;
59  break;
60  case "#":
61  VOID = type;
62  break;
63  case "boolean":
64  BOOLEAN = type;
65  break;
66  case "real":
67  REAL = type;
68  break;
69  case "string":
70  STRING = type;
71  break;
72  case "color":
73  COLOR = type;
74  break;
75  case "linestyle":
76  LINESTYLE = type;
77  break;
78  case "fillstyle":
79  FILLSTYLE = type;
80  break;
81  case "alignment":
82  ALIGNMENT = type;
83  break;
84  case "window":
85  WINDOW = type;
86  try {
87  WINDOW_ADD_FIGURE = new SystemMethodType("1af", WINDOW, new SystemType[] { FIGURE }, VOID, "addFigure", "");
89  } catch (NoSuchMethodException e) { e.printStackTrace(); System.exit(-1);}
90  break;
91  case "figure":
92  FIGURE = type;
93  break;
94  }
95  return type;
96  }
97 
98  public static void registerSuper(String id, String superType) throws MissingTypeException {
99  Type t = idType.get(id);
100  if (t == null) {
101  throw new MissingTypeException(id);
102  }
103  if (superType != null) {
104  Type st = idType.get(superType);
105  if (st == null) {
106  throw new MissingTypeException(superType);
107  }
108  t.superType = st;
109  } else {
110  t.superType = null;
111  }
112  }
113 
114  // basic types
115  public static SystemType getFigure() {
116  return FIGURE;
117  }
118 
119  public static SystemType getWindow() {
120  return WINDOW;
121  }
122 
123  public static SystemType getClassType() {
124  return CLASS;
125  }
126 
127  public static SystemType getInstanceByID(String id) {
128  if (idType.containsKey(id)) {
129  return idType.get(id);
130  } else {
131  return UNKNOWN;
132  }
133  }
134 
135  public static SystemType getInstanceByName(String name) {
136  if (nameType.containsKey(name.toLowerCase())) {
137  return nameType.get(name.toLowerCase());
138  } else {
139  return UNKNOWN;
140  }
141  }
142 
143  public static LinkedList<Type> getAll() {
144  LinkedList<Type> allTypes = new LinkedList<>();
145  for (Type t : nameType.values()) {
146  allTypes.add(t);
147  }
148  return allTypes;
149  }
150 
156  public MethodType getAssignProperty(String name) {
157  String key = name.toLowerCase();
158  if (setProperty.containsKey(key)) {
159  return setProperty.get(key);
160  } else if (superType != null) {
161  return superType.getAssignProperty(name);
162  } else {
163  return null;
164  }
165  }
166 
172  public MethodType getReadProperty(String name) {
173  String key = name.toLowerCase();
174  if (getProperty.containsKey(key)) {
175  return getProperty.get(key);
176  } else if (superType != null) {
177  return superType.getReadProperty(name);
178  } else {
179  return null;
180  }
181  }
182  @Override
183  public LinkedList<PropertyViewer> getPropertyViewers(Object target) {
184  LinkedList<PropertyViewer> list = new LinkedList<>();
185  Type act = this;
186  while (act != null) {
187  for(var m:viewProperty.entrySet()) {
188  list.add(new PropertyViewer.SystemTypePropertyViewer(m.getKey(), m.getValue(), target));
189  }
190  act = act.superType;
191  }
192  return list;
193  }
194  @Override
195  public TreeMap<String, MethodType> getAllReadProperties() {
196  return getProperty;
197  }
198 
199  @Override
200  public TreeMap<String, MethodType> getAllAssignProperties() {
201  return setProperty;
202  }
203 
204  public void registerReadProperty(MethodType mt, String name) {
205  getProperty.put(name, mt);
206  }
207  public void registerViewProperty(String viewerMethod, String label) throws NoSuchMethodException {
208  java.lang.reflect.Method m = cls.getDeclaredMethod(viewerMethod, new Class<?>[] {});
209  viewProperty.put(label, m);
210  }
211  public void registerAssignProperty(SystemMethodType mt, String name) {
212  setProperty.put(name, mt);
213  }
214 
215  public Class<?> convertToClass() {
216  return cls;
217  }
218 
219  public boolean isAbstract() {
220  return objSrc == null;
221  }
222 
223  public MType getMType() {
224  return new MJavaClass(id, cls, objSrc);
225  }
226 
227  public static MethodType getAddFigureMethod() {
228  return WINDOW_ADD_FIGURE;
229  }
230 
231  @Override
232  public String toString() {
233  return name;
234  }
235 
236 
237 }
static SystemType getInstanceByName(String name)
static void registerSuper(String id, String superType)
Definition: SystemType.java:98
static SystemType getInstanceByID(String id)
static MethodType getAddFigureMethod()
void registerAssignProperty(SystemMethodType mt, String name)
TreeMap< String, MethodType > getAllAssignProperties()
void registerViewProperty(String viewerMethod, String label)
LinkedList< PropertyViewer > getPropertyViewers(Object target)
void registerReadProperty(MethodType mt, String name)
static SystemType registerType(String id, String[] names, ObjectSource objSrc, Class<?> cls)
Definition: SystemType.java:42
final TreeMap< String, java.lang.reflect.Method > viewProperty
Definition: SystemType.java:21
final TreeMap< String, MethodType > getProperty
Definition: SystemType.java:19
MethodType getAssignProperty(String name)
TreeMap< String, MethodType > getAllReadProperties()
static LinkedList< Type > getAll()
final TreeMap< String, MethodType > setProperty
Definition: SystemType.java:20
MethodType getReadProperty(String name)
static SystemType COLOR
Definition: Type.java:30
void registerMethod(MethodType mt)
Definition: Type.java:120
static SystemType INTEGER
Definition: Type.java:24
abstract MethodType getAssignProperty(String name)
static SystemType BOOLEAN
Definition: Type.java:26
static SystemType STRING
Definition: Type.java:27
static SystemType LINESTYLE
Definition: Type.java:29
static SystemType REAL
Definition: Type.java:25
static SystemType ALIGNMENT
Definition: Type.java:31
static SystemType FILLSTYLE
Definition: Type.java:28
static SystemType UNKNOWN
Definition: Type.java:23
abstract MethodType getReadProperty(String name)
static SystemType VOID
Definition: Type.java:22
Impressum