-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionCall.java
More file actions
130 lines (102 loc) · 4.08 KB
/
Copy pathFunctionCall.java
File metadata and controls
130 lines (102 loc) · 4.08 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
130
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 FunctionCall extends Node implements Expression, TypeArgumentHolder {
protected @NonNull Optional<? extends Expression> object;
protected @NonNull Name name;
private @NonNull List<? extends Expression> arguments;
private @NonNull List<? extends TypeArgument> typeArguments;
public FunctionCall(Name name, List<? extends Expression> arguments) {
this(name, emptyList(), arguments);
}
public FunctionCall(Name name, Expression... arguments) {
this(name, List.of(arguments));
}
public FunctionCall(Name name, List<? extends TypeArgument> typeArguments, List<? extends Expression> arguments) {
this(Optional.empty(), name, typeArguments, arguments);
}
public FunctionCall(Name name, List<? extends TypeArgument> typeArguments, Expression... arguments) {
this(name, typeArguments, List.of(arguments));
}
public FunctionCall(Optional<? extends Expression> object, Name name, List<? extends Expression> arguments) {
this(object, name, emptyList(), arguments);
}
public FunctionCall(Optional<? extends Expression> object, Name name, Expression... arguments) {
this(object, name, List.of(arguments));
}
public FunctionCall(Expression object, Name name, List<? extends Expression> arguments) {
this(Optional.ofNullable(object), name, arguments);
}
public FunctionCall(Expression object, Name name, Expression... arguments) {
this(object, name, List.of(arguments));
}
public FunctionCall(Optional<? extends Expression> object, Name name, List<? extends TypeArgument> typeArguments, Expression... arguments) {
this(object, name, typeArguments, List.of(arguments));
}
public FunctionCall(Expression object, Name name, List<? extends TypeArgument> typeArguments, List<? extends Expression> arguments) {
this(Optional.ofNullable(object), name, typeArguments, arguments);
}
public FunctionCall(Expression object, Name name, List<? extends TypeArgument> typeArguments, Expression... arguments) {
this(object, name, typeArguments, List.of(arguments));
}
public FunctionCall(Optional<? extends Expression> object, Name name, List<? extends TypeArgument> typeArguments, List<? extends Expression> arguments) {
setObject(object);
setName(name);
setTypeArguments(typeArguments);
setArguments(arguments);
}
@Override
public Precedence precedence() {
return Precedence.PRIMARY;
}
@Override
public FunctionCall clone() {
return new FunctionCall(clone(getObject()), getName(), clone(getTypeArguments()), clone(getArguments()));
}
@Override
public String toCode() {
return getObject().map(object -> wrap(object).toCode() + ".").orElse("")
+ typeArgumentString()
+ getName() + "(" + joinNodes(", ", getArguments()) + ")";
}
@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 setArguments(@NonNull List<? extends Expression> arguments) {
this.arguments = newList(arguments);
}
public final void setArguments(Expression... arguments) {
setArguments(List.of(arguments));
}
public void setObject(@NonNull Optional<? extends Expression> object) {
this.object = object;
}
public final void setObject(Expression object) {
setObject(Optional.ofNullable(object));
}
public final void setObject() {
setObject(Optional.empty());
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
if(visitor.visitFunctionCall(this, parent, cast(replacer))) {
getObject().ifPresent(object -> object.<Expression>accept(visitor, this, this::setObject));
getName().accept(visitor, this, this::setName);
visitList(visitor, getTypeArguments());
visitList(visitor, getArguments());
}
}
}