-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThisParameter.java
More file actions
90 lines (71 loc) · 2.28 KB
/
Copy pathThisParameter.java
File metadata and controls
90 lines (71 loc) · 2.28 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
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 ThisParameter extends Declaration {
protected @NonNull Type type;
protected @NonNull Optional<Name> qualifier;
public ThisParameter(Type type) {
this(type, emptyList());
}
public ThisParameter(Type type, List<Annotation> annotations) {
this(type, Optional.empty(), annotations);
}
public ThisParameter(Type type, Optional<Name> qualifier) {
this(type, qualifier, emptyList());
}
public ThisParameter(Type type, Name qualifier) {
this(type, Optional.ofNullable(qualifier));
}
public ThisParameter(Type type, Optional<Name> qualifier, List<Annotation> annotations) {
super(emptyList(), annotations, Optional.empty());
setType(type);
setQualifier(qualifier);
}
@Override
public ThisParameter clone() {
return new ThisParameter(getType().clone(), clone(getQualifier()), clone(getAnnotations()));
}
@Override
public String toCode() {
return annotationString(false) + getType().toCode() + " " + getQualifier().map(qualifier -> qualifier.toCode() + ".").orElse("") + "this";
}
@Override
public List<Modifier> getModifiers() {
return emptyList();
}
public void setQualifier(@NonNull Optional<Name> qualifier) {
this.qualifier = qualifier;
}
public final void setQualifier(Name qualifier) {
setQualifier(Optional.ofNullable(qualifier));
}
public final void setQualifier() {
setQualifier(Optional.empty());
}
@Override
public void setDocComment(@NonNull Optional<String> docComment) {
if(!docComment.isEmpty()) {
throw new IllegalArgumentException("Formal parameters cannot have doc comments");
}
}
@Override
public Optional<String> getDocComment() {
return Optional.empty();
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
if(visitor.visitThisParameter(this, parent, cast(replacer))) {
getType().accept(visitor, this, this::setType);
getQualifier().ifPresent(qualifier -> qualifier.<Name>accept(visitor, this, this::setQualifier));
visitList(visitor, getAnnotations());
}
}
}