This repository has been archived by the owner on Jan 13, 2020. It is now read-only.
forked from dddjava/jig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Specification.java
77 lines (63 loc) · 2.85 KB
/
Specification.java
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
package jig.domain.model.specification;
import jig.domain.model.identifier.TypeIdentifier;
import jig.domain.model.identifier.Identifiers;
import org.objectweb.asm.Opcodes;
import java.util.List;
public class Specification {
public TypeIdentifier typeIdentifier;
public TypeIdentifier parentTypeIdentifier;
public int classAccess;
public Identifiers interfaceIdentifiers;
public List<ClassDescriptor> annotationDescriptors;
public List<MethodSpecification> methodSpecifications;
public List<ClassDescriptor> fieldDescriptors;
public Specification(TypeIdentifier typeIdentifier,
TypeIdentifier parentTypeIdentifier,
int classAccess,
Identifiers interfaceIdentifiers,
List<ClassDescriptor> annotationDescriptors,
List<MethodSpecification> methodSpecifications,
List<ClassDescriptor> fieldDescriptors) {
this.typeIdentifier = typeIdentifier;
this.parentTypeIdentifier = parentTypeIdentifier;
this.classAccess = classAccess;
this.interfaceIdentifiers = interfaceIdentifiers;
this.annotationDescriptors = annotationDescriptors;
this.methodSpecifications = methodSpecifications;
this.fieldDescriptors = fieldDescriptors;
}
public boolean canExtend() {
return (classAccess & Opcodes.ACC_FINAL) == 0;
}
public boolean isEnum() {
return parentTypeIdentifier.equals(new TypeIdentifier(Enum.class));
}
public boolean hasOnlyOneFieldAndFieldTypeIs(String classDescriptor) {
if (isEnum()) return false;
if (fieldDescriptors.size() != 1) return false;
return fieldDescriptors.get(0).value.equals(classDescriptor);
}
public boolean hasTwoFieldsAndFieldTypeAre(String classDescriptor) {
if (isEnum()) return false;
if (fieldDescriptors.size() != 2) return false;
TypeIdentifier field1 = fieldDescriptors.get(0).toTypeIdentifier();
TypeIdentifier field2 = fieldDescriptors.get(1).toTypeIdentifier();
return (field1.equals(field2) && field1.equals(new ClassDescriptor(classDescriptor).toTypeIdentifier()));
}
public boolean hasMethod() {
return !methodSpecifications.isEmpty();
}
public boolean hasField() {
return !fieldDescriptors.isEmpty();
}
public boolean hasAnnotation(String annotation) {
return annotationDescriptors.stream().anyMatch(annotationDescriptor -> annotationDescriptor.value.equals(annotation));
}
public Identifiers fieldTypeIdentifiers() {
return fieldDescriptors.stream().map(ClassDescriptor::toTypeIdentifier).collect(Identifiers.collector());
}
public boolean isModel() {
// TODO 外部化
return typeIdentifier.value().contains(".domain.model.");
}
}