-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass.java
More file actions
207 lines (173 loc) · 5.1 KB
/
Class.java
File metadata and controls
207 lines (173 loc) · 5.1 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package javaxt.utils.src;
import java.util.*;
import javaxt.json.*;
public class Class implements Member, Comparable {
private String name;
private String description;
private Class parent;
private ArrayList<Member> members;
private boolean isPublic = true;
private boolean isInterface = false;
private String namespace;
private ArrayList<String> extensions;
private ArrayList<String> interfaces;
private ArrayList<Config> config;
private Integer position;
public Class(String name){
this.name = name;
this.members = new ArrayList<>();
this.extensions = new ArrayList<>();
this.interfaces = new ArrayList<>();
this.config = new ArrayList<>();
}
public String getName(){
return name;
}
public void setDescription(String description){
this.description = description;
}
public String getDescription(){
return description;
}
public boolean isPublic(){
return isPublic;
}
public void setPublic(boolean isPublic){
this.isPublic = isPublic;
}
public boolean isInterface(){
return isInterface;
}
public void setInterface(boolean isInterface){
this.isInterface = isInterface;
}
public void setNamespace(String namespace){
this.namespace = namespace;
}
public String getNamespace(){
return namespace;
}
public void addSuper(String className){
extensions.add(className);
}
public ArrayList<String> getSuper(){
return extensions;
}
public void addInterface(String className){
interfaces.add(className);
}
public ArrayList<String> getInterfaces(){
return interfaces;
}
public void addMember(Member member){
if (member instanceof Class){
Class c = (Class) member;
c.namespace = this.toString();
}
members.add(member);
}
public ArrayList<Member> getMembers(){
return members;
}
public void addConfig(Config config){
this.config.add(config);
}
public ArrayList<Config> getConfig(){
return config;
}
public ArrayList<Class> getClasses(){
ArrayList<Class> classes = new ArrayList<>();
for (Member member : members){
if (member instanceof Class) classes.add((Class) member);
}
return classes;
}
public ArrayList<Constructor> getConstructors(){
ArrayList<Constructor> constructors = new ArrayList<>();
for (Member member : members){
if (member instanceof Method){
Method m = (Method) member;
if (m instanceof Constructor){
constructors.add((Constructor) m);
}
}
}
return constructors;
}
public ArrayList<Method> getMethods(){
ArrayList<Method> methods = new ArrayList<>();
for (Member member : members){
if (member instanceof Method){
Method m = (Method) member;
if (m instanceof Constructor){
//System.out.println("-->" + m.getName());
}
else{
methods.add(m);
}
}
}
return methods;
}
public ArrayList<Property> getProperties(){
ArrayList<Property> properties = new ArrayList<>();
for (Member member : members){
if (member instanceof Property) properties.add((Property) member);
}
return properties;
}
public void setParent(Class parent){
this.parent = parent;
}
public Class getParent(){
return parent;
}
public void setPosition(Integer position){
this.position = position;
}
public Integer getPosition(){
return position;
}
public JSONObject toJson(){
JSONObject json = new JSONObject();
json.set("name", name);
json.set("description", description);
JSONArray methods = new JSONArray();
for (Method m : getMethods()){
methods.add(m.toJson());
}
json.set("methods", methods);
JSONArray properties = new JSONArray();
for (Property p : getProperties()){
properties.add(p.toJson());
}
json.set("properties", properties);
JSONArray classes = new JSONArray();
for (Class c : getClasses()){
classes.add(c.toJson());
}
json.set("classes", classes);
return json;
}
public String toString(){
if (namespace==null || namespace.isBlank()) return name;
return namespace + "." + name;
}
public int hashCode(){
return toString().hashCode();
}
public boolean equals(Object obj){
if (obj!=null){
if (obj instanceof Class){
return toString().equals(obj.toString());
}
}
return false;
}
public int compareTo(Object obj){
if (obj instanceof Class){
return toString().compareTo(obj.toString());
}
return -1;
}
}