VmResource formattedResource =
workspaceRelations.createTemporaryFile(metadata, proposedFileName);
SourcePositionMapBuilder.MappingHandle mappingHandle;
try {
SourcePositionMapBuilder builder =
data.getConnectedTargetData().getSourcePositionMapBuilder();
// Unformatted text is a VM text.
StringMappingData vmTextData = result.getInputTextData();
// Formatter text is *like* original text in our case.
StringMappingData originalTextData = result.getFormattedTextData();
SourcePositionMapBuilder.ResourceSection vmResourceSection =
new SourcePositionMapBuilder.ResourceSection(data.getVmResource().getId(), 0, 0,
vmTextData.getEndLine(), vmTextData.getEndColumn());
SourcePositionMapBuilder.ResourceSection originalResourceSection =
new SourcePositionMapBuilder.ResourceSection(formattedResource.getId(), 0, 0,
originalTextData.getEndLine(), originalTextData.getEndColumn());
TextSectionMapping mapTable =
new TextSectionMappingImpl(originalTextData, vmTextData);
mappingHandle = builder.addMapping(originalResourceSection, vmResourceSection, mapTable);
} catch (SourcePositionMapBuilder.CannotAddException e) {
formattedResource.deleteResourceAndFile();
throw new RuntimeException(e);
}
metadata.mappingHandle = mappingHandle;