-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathClassInfo.java
More file actions
129 lines (105 loc) · 3.32 KB
/
Copy pathClassInfo.java
File metadata and controls
129 lines (105 loc) · 3.32 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
package org.example.model;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
public final class ClassInfo {
private final String name;
private final String superName;
private final List<String> interfaces;
private final Set<MethodInfo> methods;
private final int fieldCount;
private final ABCMetrics abcMetrics;
private final boolean isInterface;
private ClassInfo(Builder builder) {
this.name = Objects.requireNonNull(builder.name, "name cannot be null");
this.superName = builder.superName;
this.interfaces = List.copyOf(builder.interfaces);
this.methods = Set.copyOf(builder.methods);
this.fieldCount = builder.fieldCount;
this.abcMetrics = builder.abcMetrics;
this.isInterface = builder.isInterface;
}
public String getName() {
return name;
}
public String getSuperName() {
return superName;
}
public List<String> getInterfaces() {
return interfaces;
}
public Set<MethodInfo> getMethods() {
return methods;
}
public int getFieldCount() {
return fieldCount;
}
public ABCMetrics getAbcMetrics() {
return abcMetrics;
}
public boolean isInterface() {
return isInterface;
}
@Override
public String toString() {
return String.format("ClassInfo{name='%s', super='%s', interfaces=%s, methods=%d, fields=%d}",
name, superName, interfaces, methods.size(), fieldCount);
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private String name;
private String superName;
private final List<String> interfaces = new ArrayList<>();
private final Set<MethodInfo> methods = new HashSet<>();
private int fieldCount = 0;
private ABCMetrics abcMetrics = new ABCMetrics();
private boolean isInterface = false;
private Builder() {
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder superName(String superName) {
this.superName = superName;
return this;
}
public Builder addInterface(String interfaceName) {
if (interfaceName != null) {
this.interfaces.add(interfaceName);
}
return this;
}
public Builder addInterfaces(String[] interfaceNames) {
if (interfaceNames != null) {
for (String name : interfaceNames) {
addInterface(name);
}
}
return this;
}
public Builder addMethod(MethodInfo method) {
this.methods.add(method);
return this;
}
public Builder incrementFieldCount() {
this.fieldCount++;
return this;
}
public Builder abcMetrics(ABCMetrics abcMetrics) {
this.abcMetrics = abcMetrics;
return this;
}
public Builder isInterface(boolean isInterface) {
this.isInterface = isInterface;
return this;
}
public ClassInfo build() {
return new ClassInfo(this);
}
}
}