-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericType.java
More file actions
110 lines (87 loc) · 3.41 KB
/
Copy pathGenericType.java
File metadata and controls
110 lines (87 loc) · 3.41 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
package jtree.nodes;
import static jtree.util.Utils.*;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;
@EqualsAndHashCode
@Getter @Setter
public class GenericType extends ReferenceType implements TypeArgumentHolder {
protected @NonNull QualifiedName name;
protected @NonNull List<? extends TypeArgument> typeArguments;
private @NonNull Optional<GenericType> container;
public GenericType(QualifiedName name) {
this(name, emptyList());
}
public GenericType(QualifiedName name, Optional<GenericType> container) {
this(name, emptyList(), container);
}
public GenericType(QualifiedName name, GenericType container) {
this(name, Optional.ofNullable(container));
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments) {
this(name, typeArguments, emptyList());
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments, Optional<GenericType> container) {
this(name, typeArguments, container, emptyList());
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments, GenericType container) {
this(name, typeArguments, Optional.ofNullable(container));
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments, List<Annotation> annotations) {
this(name, typeArguments, Optional.empty(), annotations);
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments, GenericType container, List<Annotation> annotations) {
this(name, typeArguments, Optional.ofNullable(container), annotations);
}
public GenericType(QualifiedName name, List<? extends TypeArgument> typeArguments, Optional<GenericType> container, List<Annotation> annotations) {
super(annotations);
setName(name);
setContainer(container);
setTypeArguments(typeArguments);
}
@Override
public GenericType clone() {
return new GenericType(getName(), clone(getTypeArguments()), clone(getContainer()), clone(getAnnotations()));
}
@Override
public String toCode() {
return getContainer().map(container -> container.toCode() + ".").orElse("")
+ annotationString(false) + getName() + typeArgumentString();
}
@Override
public void setTypeArguments(@NonNull List<? extends TypeArgument> typeArguments) {
this.typeArguments = newList(typeArguments);
}
@Override
public final void setTypeArguments(TypeArgument... typeArguments) {
setTypeArguments(List.of(typeArguments));
}
public void setName(QualifiedName name) {
/*if(name.lastName().equals("var")) {
throw new IllegalArgumentException("\"var\" cannot be used as a type name");
}*/
this.name = name;
}
public void setContainer(@NonNull Optional<GenericType> container) {
this.container = container;
}
public final void setContainer(GenericType container) {
setContainer(Optional.ofNullable(container));
}
public final void setContainer() {
setContainer(Optional.empty());
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
if(visitor.visitGenericType(this, parent, cast(replacer))) {
getName().accept(visitor, this, this::setName);
getContainer().ifPresent(container -> container.<GenericType>accept(visitor, this, this::setContainer));
visitList(visitor, getTypeArguments());
visitList(visitor, getAnnotations());
}
}
}