You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2021/12/05 15:44:21 UTC
[GitHub] [groovy] mgroovy commented on a change in pull request #1660: GROOVY-10259: Groovy4 NV Macros: Rename NV* -> SV*
mgroovy commented on a change in pull request #1660:
URL: https://github.com/apache/groovy/pull/1660#discussion_r762579784
##########
File path: src/main/java/groovy/lang/NamedValue.java
##########
@@ -0,0 +1,24 @@
+package groovy.lang;
+
+public class NamedValue<T> {
Review comment:
Yes, semantically it is quite different. The implementation we use also shows that, since toString auto-quotes String/GString/Character (making the output much easier to read), and is exception safe (so NV macros can be used e.g. when supplying the message string of an exception), e.g.:
throw new SqlExecutorException(innerException, "updateValueAtPosition failed for ${NVL(table,schema,pos,val,updateSql)}")
String toString() {
name + "=" + safeQuote(val)
}
static String safeQuote(final Object o) {
if(null == o) {
return null
}
else if(o instanceof GString) {
return '"' + o + '"'
}
else if(o instanceof String) {
return "'" + o + "'"
}
else if(o instanceof Character) {
return "C'" + o + "'"
}
else {
try {
return o.toString()
}
catch(Throwable throwable0) {
try {
return "NV(${o.getClass().getSimpleName()}.toString() threw ${throwable0.getClass().getSimpleName()})"
}
catch(Throwable throwable1) {
return "NV(o.getClass() threw ${throwable1.getClass().getSimpleName()})"
}
}
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org