-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContextHistoryConverter.java
More file actions
46 lines (41 loc) · 1.81 KB
/
ContextHistoryConverter.java
File metadata and controls
46 lines (41 loc) · 1.81 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
package utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import dtos.context.AliasDTO;
import dtos.context.ContextHistoryDTO;
import dtos.context.MethodDTO;
import dtos.context.GhostDTO;
import dtos.context.VariableDTO;
import dtos.diagnostics.SourcePositionDTO;
import liquidjava.processor.context.ContextHistory;
/**
* Utility class for converting LiquidJava context objects to DTOs.
*/
public class ContextHistoryConverter {
/**
* Converts a ContextHistory to its DTO type.
* @param contextHistory the context history to convert
* @return the corresponding DTO
*/
public static ContextHistoryDTO convertToDTO(ContextHistory contextHistory) {
return new ContextHistoryDTO(
contextHistory.getLocalVars().stream().map(VariableDTO::from).filter(v -> v != null).collect(Collectors.toList()),
contextHistory.getGlobalVars().stream().map(VariableDTO::from).filter(v -> v != null).collect(Collectors.toList()),
contextHistory.getGhosts().stream().map(GhostDTO::from).collect(Collectors.toList()),
contextHistory.getAliases().stream().map(AliasDTO::from).collect(Collectors.toList()),
contextHistory.getMethods().stream().map(MethodDTO::from).filter(f -> f != null).collect(Collectors.toList()),
parseFileScopes(contextHistory.getFileScopes())
);
}
private static Map<String, List<SourcePositionDTO>> parseFileScopes(Map<String, Set<String>> fileScopes) {
return fileScopes.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().stream().map(SourcePositionDTO::from).collect(Collectors.toList()),
(left, right) -> left,
HashMap::new
));
}
}