use of com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules in project tcMenu by davetcc.
the class GenerateCodeDialog method ensureIoFullyDeclared.
private void ensureIoFullyDeclared(CodePluginItem pluginItem) {
logger.log(INFO, "Checking for unmapped IO devices: " + pluginItem.getDescription());
var codeOptions = project.getGeneratorOptions();
// find any IO device declarations that do not match to an entry in the expanders
var anyIoWithoutEntries = pluginItem.getProperties().stream().filter(prop -> prop.getValidationRules() instanceof IoExpanderPropertyValidationRules).filter(prop -> codeOptions.getExpanderDefinitions().getDefinitionById(prop.getLatestValue()).isEmpty()).toList();
// nothing to do if list is empty
if (anyIoWithoutEntries.isEmpty()) {
logger.log(INFO, "All IO devices mapped");
return;
}
var allExpanders = new HashSet<>(codeOptions.getExpanderDefinitions().getAllExpanders());
// now we iterate through the unmapped expanders, which must be from prior to the automated support.
for (var customIo : anyIoWithoutEntries) {
if (StringHelper.isStringEmptyOrNull(customIo.getLatestValue())) {
// for empty strings, the previous assumption was using device IO. This is now explicitly defined
// as deviceIO
customIo.setLatestValue(InternalDeviceExpander.DEVICE_ID);
logger.log(INFO, "Device being mapped as internal: " + customIo.getLatestValue());
} else {
// otherwise, previously the assumption was using a custom defined expander in the sketch, now we'll
// actually add that to the sketch.
allExpanders.add(new CustomDeviceExpander(customIo.getLatestValue()));
logger.log(INFO, "Device being mapped as custom: " + customIo.getLatestValue());
}
}
project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(codeOptions).withExpanderDefinitions(new IoExpanderDefinitionCollection(allExpanders)).codeOptions());
logger.log(INFO, "Done mapping all IO devices");
}
Aggregations