diff --git a/R/S7.R b/R/S7.R index c38a7532..26931b44 100644 --- a/R/S7.R +++ b/R/S7.R @@ -19,6 +19,7 @@ traverse_S7_generic <- function(x) { # Recurse for nested environments get_replacements(target_value) } else { + name <- as.character(attr(target_value, "name", TRUE) %||% name) list(replacement(name, env, target_value)) } }) @@ -28,11 +29,15 @@ traverse_S7_generic <- function(x) { } traverse_S7_class <- function(x) { + class_name <- S7::prop(x, "name") prop_fun_replacements <- lapply(S7::prop(x, "properties"), function(p) { lapply(c("getter", "setter", "validator"), function(prop_fun) { if (!is.null(p[[prop_fun]])) { - replacement(prop_fun, env = p, target_value = p[[prop_fun]]) + replacement( + sprintf("%s@properties$%s$%s", class_name, p$name, prop_fun), + env = p, + target_value = p[[prop_fun]]) } }) }) @@ -40,8 +45,8 @@ traverse_S7_class <- function(x) { c( list( - replacement("constructor", env = x, target_value = S7::prop(x, "constructor")), - replacement("validator" , env = x, target_value = S7::prop(x, "validator")) + replacement(paste0(class_name, "@constructor"), env = x, target_value = S7::prop(x, "constructor")), + replacement(paste0(class_name, "@validator") , env = x, target_value = S7::prop(x, "validator")) ), prop_fun_replacements )