-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVariableDTO.java
More file actions
33 lines (31 loc) · 1.2 KB
/
VariableDTO.java
File metadata and controls
33 lines (31 loc) · 1.2 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
package dtos.context;
import dtos.diagnostics.SourcePositionDTO;
import liquidjava.processor.context.PlacementInCode;
import liquidjava.processor.context.RefinedVariable;
import liquidjava.utils.VariableFormatter;
/**
* DTO for serializing RefinedVariable instances to JSON.
*/
public record VariableDTO(
String name,
String internalName,
String type,
String refinement,
String mainRefinement,
SourcePositionDTO position,
SourcePositionDTO annotationPosition
) {
public static VariableDTO from(RefinedVariable refinedVariable) {
PlacementInCode placement = refinedVariable.getPlacementInCode();
if (placement == null) return null;
return new VariableDTO(
VariableFormatter.formatVariable(refinedVariable.getName()),
refinedVariable.getName(),
ContextHistoryDTO.stringifyType(refinedVariable.getType()),
VariableFormatter.formatText(refinedVariable.getRefinement().toString()),
VariableFormatter.formatText(refinedVariable.getMainRefinement().toString()),
SourcePositionDTO.from(placement.getPosition()),
SourcePositionDTO.from(placement.getAnnotationPosition())
);
}
}