-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathNDictType.java
More file actions
62 lines (50 loc) · 1.48 KB
/
NDictType.java
File metadata and controls
62 lines (50 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Copyright 2009, Google Inc. All rights reserved.
* Licensed to PSF under a Contributor Agreement.
*/
package org.python.indexer.types;
import org.python.indexer.Indexer;
import org.python.indexer.NBinding;
import org.python.indexer.ast.NUrl;
public class NDictType extends NType {
private NType keyType;
private NType valueType;
public NDictType() {
this(new NUnknownType(), new NUnknownType());
}
public NDictType(NType key0, NType val0) {
keyType = key0;
valueType = val0;
getTable().addSuper(Indexer.idx.builtins.BaseDict.getTable());
getTable().setPath(Indexer.idx.builtins.BaseDict.getTable().getPath());
}
public void setKeyType(NType keyType) {
this.keyType = keyType;
}
public NType getKeyType() {
return keyType;
}
public void setValueType(NType valType) {
this.valueType = valType;
}
public NType getValueType() {
return valueType;
}
public void add(NType key, NType val) {
keyType = NUnionType.union(keyType, key);
valueType = NUnionType.union(valueType, val);
}
public NTupleType toTupleType(int n) {
NTupleType ret = new NTupleType();
for (int i = 0; i < n; i++) {
ret.add(keyType);
}
return ret;
}
@Override
public void printKids(CyclicTypeRecorder ctr, StringBuilder sb) {
keyType.print(ctr, sb);
sb.append(":");
valueType.print(ctr, sb);
}
}