return description;
}
+ @Deprecated
public static String replaceAllIllegalChars(final CharSequence stringBuilder) {
+ return defangUnicodeEscapes(stringBuilder);
+ }
+
+ /**
+ * Escape potential unicode references so that the resulting string is safe to put into a {@code .java} file. This
+ * processing is required to ensure this text we want to append does not end up with eligible backslashes. See
+ * <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.3">Java Language Specification</a>
+ * for more information.
+ *
+ * @param str Input string
+ * @return A string with all backslashes made ineligible
+ */
+ public static String replaceAllIllegalChars(final String str) {
+ final int backslash = str.indexOf('\\');
+ return backslash == -1 ? str : defangUnicodeEscapes(str);
+ }
+
+ private static String defangUnicodeEscapes(final CharSequence stringBuilder) {
+ // TODO: we should be able to receive the first offset from the non-deprecated method and perform a manual
+ // check for eligibility and escape -- that would be faster I think.
final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
return ret.isEmpty() ? "" : ret;
}
import org.opendaylight.mdsal.binding.model.api.TypeMember
import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Single
import org.opendaylight.mdsal.binding.model.api.YangSourceDefinition.Multiple
+import org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil
import org.opendaylight.mdsal.binding.model.util.TypeConstants
import org.opendaylight.mdsal.binding.model.util.Types
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
def private static void appendYangSnippet(StringBuilder sb, ModuleEffectiveStatement module,
DeclaredStatement<?> stmt) {
for (String str : YANG_FORMATTER.toYangTextSnippet(module, stmt)) {
- sb.append(encodeAngleBrackets(encodeJavadocSymbols(str)))
+ sb.append(BindingGeneratorUtil.replaceAllIllegalChars(encodeAngleBrackets(encodeJavadocSymbols(str))))
}
}
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
+ @Test
+ public void testMdsal529() throws Exception {
+ final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal529");
+ final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal529");
+ generateTestSources("/compilation/mdsal529", sourcesOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName,
final String returnTypeStr) throws NoSuchMethodException {
Method method = clazz.getMethod(methodName);
--- /dev/null
+module foo {
+ namespace foo;
+ prefix foo;
+
+ leaf foo {
+ type string;
+ default "\\u@\\h\\M% ";
+ }
+
+ leaf bar {
+ type string;
+ default "\\uu";
+ }
+
+ leaf baz {
+ type string;
+ default "\\a\\uu";
+ }
+
+ leaf xyzzy {
+ type string;
+ default '\uuuaaa';
+ }
+}
+