Repository navigation
Expand file tree
/
Copy pathClassNode.java
More file actions
129 lines (105 loc) · 3.13 KB
/
Copy pathClassNode.java
File metadata and controls
129 lines (105 loc) · 3.13 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
package act.util;
import org.osgl.$;
import org.osgl.util.C;
import org.osgl.util.E;
import java.lang.reflect.Modifier;
import java.util.Set;
public class ClassNode {
private ClassInfoRepository infoBase;
private String name;
private String canonicalName;
private int modifiers;
private ClassNode parent;
private Set<ClassNode> children = C.newSet();
private Set<ClassNode> interfaces = C.newSet();
ClassNode(String name, int modifiers, ClassInfoRepository infoBase) {
this(name, name.replace('$', '.'), modifiers, infoBase);
}
ClassNode(String name, String canonicalName, int modifiers, ClassInfoRepository infoBase) {
this(name, canonicalName, infoBase);
this.modifiers = modifiers;
}
ClassNode(String name, ClassInfoRepository infoBase) {
this(name, name.replace('$', '.'), infoBase);
}
ClassNode(String name, String canonicalName, ClassInfoRepository infoBase) {
E.NPE(name, infoBase);
this.name = name;
this.canonicalName = canonicalName;
this.infoBase = infoBase;
}
public String name() {
return name;
}
public String canonicalName() {
return canonicalName;
}
public ClassNode modifiers(int modifiers) {
this.modifiers = modifiers;
return this;
}
public int modifiers() {
return modifiers;
}
public boolean isPublic() {
return Modifier.isPublic(modifiers);
}
public boolean isAbstract() {
return Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers);
}
public boolean publicNotAbstract() {
return isPublic() && !isAbstract();
}
public ClassNode parent() {
return parent;
}
public ClassNode parent(String name) {
this.parent = infoBase.node(name);
this.parent.addChild(this);
return this;
}
public ClassNode addInterface(String name) {
ClassNode intf = infoBase.node(name);
this.interfaces.add(intf);
intf.addChild(this);
return this;
}
public ClassNode accept($.Function<ClassNode, ?> treeVisitor) {
for (ClassNode child : children) {
child.accept(treeVisitor);
}
treeVisitor.apply(this);
return this;
}
public ClassNode findPublicNotAbstract($.Function<ClassNode, ?> treeVisitor) {
return accept($.guardedVisitor(new $.Predicate<ClassNode>() {
@Override
public boolean test(ClassNode classNode) {
return classNode.publicNotAbstract();
}
}, treeVisitor));
}
@Override
public String toString() {
return name;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ClassNode) {
ClassNode that = (ClassNode) obj;
return $.eq(that.name, this.name);
}
return false;
}
private ClassNode addChild(ClassNode node) {
children.add(node);
return this;
}
}