-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPythonType.java
More file actions
64 lines (55 loc) · 1.62 KB
/
PythonType.java
File metadata and controls
64 lines (55 loc) · 1.62 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
63
64
package plang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A Python class.
*/
public class PythonType extends PythonObject {
private final String name;
private final PythonObject base;
/**
* Declares a new Python type. Equivalent to Python `class «name»(«base»):`
* @param name The name of this class.
* @param base The base class of this class. May be null.
* (In real Python, instead of null it would be the class called `object`, and
* it would be a list instead of a single value.)
*/
public PythonType(String name, PythonObject base) {
super(null); // In real Python, this would be the type called `type`
this.name = name;
this.base = base;
}
/**
* The name of this class.
*/
public String getName() {
return name;
}
/**
* The base type (superclass) of this class.
*/
public PythonObject getBase() {
return base;
}
@Override
protected List<PythonObject> buildMRO() {
ArrayList<PythonObject> temp = new ArrayList<>();
temp.add(this);
if(base != null)
temp.addAll(base.getMRO());
return temp;
}
/**
* Creates and returns a new instance of this class, i.e. a PythonObject whose type is
* this PythonType.
*/
public PythonObject instantiate() {
return new PythonObject(this);
//throw new UnsupportedOperationException("not implemented yet");
}
@Override
public String toString() {
return "PythonType<" + name + ">";
}
}