EOS 2  1.1.0
Einfache Objektbasierte Sprache
Type.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.baseparser;
2 
3 import java.util.LinkedList;
4 import java.util.TreeMap;
5 
6 import de.lathanda.eos.vm.MType;
7 
14 public abstract class Type implements Comparable<Type>, AutoCompleteType {
15  protected Type superType;
16  // properties
17  protected final String id;
18 
19  protected final TreeMap<String, LinkedList<MethodType> > methods = new TreeMap<>();
20  protected final LinkedList<AutoCompleteEntry> autocompletes = new LinkedList<>();
21 
22  protected static SystemType VOID;
23  protected static SystemType UNKNOWN;
24  protected static SystemType INTEGER;
25  protected static SystemType REAL;
26  protected static SystemType BOOLEAN;
27  protected static SystemType STRING;
28  protected static SystemType FILLSTYLE;
29  protected static SystemType LINESTYLE;
30  protected static SystemType COLOR;
31  protected static SystemType ALIGNMENT;
32 
33  protected Type(String id) {
34  this.id = id;
35  }
36 
37  public boolean checkType(Type right) {
38  return !mergeTypes(right).isUnknown();
39  }
40 
41  public boolean isNumber() {
42  return this == INTEGER || this == REAL;
43  }
44 
45  public boolean isBoolean() {
46  return this == BOOLEAN;
47  }
48 
49  public boolean isVoid() {
50  return this == VOID;
51  }
52 
53  public boolean isInteger() {
54  return this == INTEGER;
55  }
56 
57  @Override
58  public boolean isUnknown() {
59  return this == UNKNOWN;
60  }
61 
62  public Type mergeTypes(Type right) {
63  if (this == right) {
64  return this;
65  } else if (right != null) {
66  if (this == INTEGER && right == REAL || this == REAL && right == INTEGER) {
67  return REAL;
68  } else {
69  return mergeTypes(right.superType);
70  }
71  } else {
72  return UNKNOWN;
73  }
74  }
75 
76  public static SystemType getVoid() {
77  return VOID;
78  }
79 
80  public static SystemType getUnknown() {
81  return UNKNOWN;
82  }
83 
84  public static SystemType getInteger() {
85  return INTEGER;
86  }
87 
88  public static SystemType getBoolean() {
89  return BOOLEAN;
90  }
91 
92  public static SystemType getDouble() {
93  return REAL;
94  }
95 
96  public static SystemType getString() {
97  return STRING;
98  }
99 
100  public static SystemType getColor() {
101  return COLOR;
102  }
103 
104  public static SystemType getLineStyle() {
105  return LINESTYLE;
106  }
107 
108  public static SystemType getFillStyle() {
109  return FILLSTYLE;
110  }
111 
112  public static SystemType getAlignment() {
113  return ALIGNMENT;
114  }
115 
117  autocompletes.add(ace);
118  }
119 
120  public void registerMethod(MethodType mt) {
121  LinkedList<MethodType> list;
122  String key = Signatures.createPreselectionSignature(mt.getName(), mt.getParameters().length);
123  if (methods.containsKey(key)) {
124  list = methods.get(key);
125  } else {
126  list = new LinkedList<>();
127  methods.put(key, list);
128  }
129  list.add(mt);
130  }
131 
140  public MethodType getMethod(String name, Type[] parameters) {
141  LinkedList<MethodType> list = getMethods(name, parameters.length);
142  for(MethodType mt:list) {
143  if(mt.checkType(parameters)) {
144  return mt;
145  }
146  }
147  return null;
148  }
149  private LinkedList<MethodType> getMethods(String name, int parameterCount) {
150  String key = Signatures.createPreselectionSignature(name, parameterCount);
151 
152  LinkedList<MethodType> list = new LinkedList<>();
153  if (methods.containsKey(key)) {
154  list.addAll(methods.get(key));
155  }
156  if (superType != null) {
157  list.addAll(superType.getMethods(name, parameterCount));
158  }
159  return list;
160  }
161 
162 
163  public boolean inherits(Type b) {
164  if (b == this) {
165  return true;
166  } else if (superType != null) {
167  return superType.inherits(b);
168  } else {
169  return false;
170  }
171  }
172 
173  public LinkedList<Type> getTypeList() {
174  LinkedList<Type> typelist = new LinkedList<Type>();
175  Type act = this;
176  while (act != null) {
177  typelist.add(act);
178  act = act.superType;
179  }
180  return typelist;
181  }
182 
183  @Override
184  public LinkedList<AutoCompleteInformation> getAutoCompletes() {
185  LinkedList<AutoCompleteInformation> completes = new LinkedList<>();
186  fillAutoCompletes(completes);
187  return completes;
188  }
189 
190  protected void fillAutoCompletes(LinkedList<AutoCompleteInformation> list) {
191  list.addAll(autocompletes);
192  if (superType != null) {
194  }
195  }
196 
197  @Override
198  public int compareTo(Type b) {
199  return this.id.compareTo(b.id);
200  }
201 
202  @Override
203  public String toString() {
204  return id;
205  }
206 
207  public String getID() {
208  return id;
209  }
210 
211  public Type getSuperType() {
212  return superType;
213  }
214 
215  public abstract MType getMType();
216 
217  public abstract boolean isAbstract();
218 
219  public abstract MethodType getReadProperty(String name);
220 
221  public abstract MethodType getAssignProperty(String name);
222 
223  public abstract TreeMap<String, MethodType> getAllReadProperties();
224 
225  public abstract TreeMap<String, MethodType> getAllAssignProperties();
226 
227  public abstract LinkedList<PropertyViewer> getPropertyViewers(Object target);
228 }
static String createPreselectionSignature(String name, int args)
Definition: Signatures.java:6
static SystemType COLOR
Definition: Type.java:30
boolean inherits(Type b)
Definition: Type.java:163
static SystemType getString()
Definition: Type.java:96
void registerMethod(MethodType mt)
Definition: Type.java:120
static SystemType INTEGER
Definition: Type.java:24
static SystemType getVoid()
Definition: Type.java:76
static SystemType getBoolean()
Definition: Type.java:88
final LinkedList< AutoCompleteEntry > autocompletes
Definition: Type.java:20
abstract MethodType getAssignProperty(String name)
final TreeMap< String, LinkedList< MethodType > > methods
Definition: Type.java:19
static SystemType getAlignment()
Definition: Type.java:112
static SystemType BOOLEAN
Definition: Type.java:26
static SystemType getUnknown()
Definition: Type.java:80
abstract TreeMap< String, MethodType > getAllAssignProperties()
MethodType getMethod(String name, Type[] parameters)
Definition: Type.java:140
static SystemType getFillStyle()
Definition: Type.java:108
static SystemType getDouble()
Definition: Type.java:92
static SystemType STRING
Definition: Type.java:27
static SystemType LINESTYLE
Definition: Type.java:29
boolean checkType(Type right)
Definition: Type.java:37
LinkedList< AutoCompleteInformation > getAutoCompletes()
Definition: Type.java:184
abstract boolean isAbstract()
Type mergeTypes(Type right)
Definition: Type.java:62
void registerAutoCompleteEntry(AutoCompleteEntry ace)
Definition: Type.java:116
static SystemType REAL
Definition: Type.java:25
static SystemType getInteger()
Definition: Type.java:84
static SystemType getLineStyle()
Definition: Type.java:104
static SystemType getColor()
Definition: Type.java:100
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
abstract LinkedList< PropertyViewer > getPropertyViewers(Object target)
abstract TreeMap< String, MethodType > getAllReadProperties()
LinkedList< Type > getTypeList()
Definition: Type.java:173
void fillAutoCompletes(LinkedList< AutoCompleteInformation > list)
Definition: Type.java:190
Impressum