-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMethodDTO.java
More file actions
43 lines (38 loc) · 1.47 KB
/
MethodDTO.java
File metadata and controls
43 lines (38 loc) · 1.47 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
package dtos.context;
import java.util.List;
import java.util.stream.Collectors;
import liquidjava.processor.context.ObjectState;
import liquidjava.processor.context.RefinedFunction;
import liquidjava.rj_language.Predicate;
import liquidjava.rj_language.ast.formatter.ExpressionFormatter;
/**
* DTO for serializing RefinedFunction instances to JSON.
*/
public record MethodDTO(
String name,
String targetClass,
String returnRefinement,
List<VariableDTO> parameters,
List<StateRefinementDTO> stateRefinements
) {
public static MethodDTO from(RefinedFunction refinedFunction) {
return new MethodDTO(
refinedFunction.getName(),
refinedFunction.getTargetClass(),
format(refinedFunction.getRefReturn()),
refinedFunction.getArguments().stream().map(VariableDTO::from).filter(v -> v != null).collect(Collectors.toList()),
refinedFunction.getAllStates().stream().map(StateRefinementDTO::from).collect(Collectors.toList())
);
}
public record StateRefinementDTO(String from, String to) {
public static StateRefinementDTO from(ObjectState state) {
return new StateRefinementDTO(
state.hasFrom() ? format(state.getFrom()) : null,
state.hasTo() ? format(state.getTo()) : null
);
}
}
private static String format(Predicate predicate) {
return predicate == null ? "" : ExpressionFormatter.format(predicate);
}
}