980ae343bbaeb6855e9bd418f23842d726ae34fd
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / AuxiliaryGenUtils.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.mdsal.binding.javav2.generator.impl;
10
11 import static com.google.common.base.Preconditions.checkArgument;
12 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
13 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.replacePackageTopNamespace;
14 import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.BOOLEAN;
15
16 import com.google.common.annotations.Beta;
17 import com.google.common.annotations.VisibleForTesting;
18 import com.google.common.base.Splitter;
19 import com.google.common.base.Strings;
20 import com.google.common.collect.Iterables;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.regex.Pattern;
26 import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
27 import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForModule;
28 import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForNode;
29 import org.opendaylight.mdsal.binding.javav2.generator.impl.txt.yangTemplateForNodes;
30 import org.opendaylight.mdsal.binding.javav2.generator.impl.util.YangTextTemplate;
31 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
32 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
33 import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
34 import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer;
35 import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
36 import org.opendaylight.mdsal.binding.javav2.generator.util.YangSnippetCleaner;
37 import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
38 import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
39 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
40 import org.opendaylight.mdsal.binding.javav2.model.api.Constant;
41 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
42 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.EnumBuilder;
43 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedPropertyBuilder;
44 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTOBuilder;
45 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
46 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilderBase;
47 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
48 import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
49 import org.opendaylight.mdsal.binding.javav2.util.BindingMapping;
50 import org.opendaylight.yangtools.yang.common.QName;
51 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
52 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
53 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
54 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
55 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
56 import org.opendaylight.yangtools.yang.model.api.Module;
57 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
58 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
59 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
60 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
61 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
62 import org.opendaylight.yangtools.yang.model.api.Status;
63 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
64 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
65 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
66 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
67 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
68 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
69
70 /**
71  * Auxiliary util class for {@link GenHelperUtil} class
72  */
73 @Beta
74 final class AuxiliaryGenUtils {
75
76     private static final Splitter BSDOT_SPLITTER = Splitter.on(".");
77     private static final char NEW_LINE = '\n';
78     private static final Pattern UNICODE_CHAR_PATTERN = Pattern.compile("\\\\+u");
79
80     /**
81      * Constant with the concrete name of identifier.
82      */
83     private static final String AUGMENT_IDENTIFIER_NAME = "augment-identifier";
84
85     /**
86      * Constant with the concrete name of namespace.
87      */
88     private static final String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
89
90     private AuxiliaryGenUtils() {
91         throw new UnsupportedOperationException("Util class");
92     }
93
94     static void annotateDeprecatedIfNecessary(final Status status, final GeneratedTypeBuilder builder) {
95         if (status == Status.DEPRECATED) {
96             builder.addAnnotation("", "Deprecated");
97         }
98     }
99
100     public static boolean hasBuilderClass(final SchemaNode schemaNode, final BindingNamespaceType namespaceType) {
101         return (namespaceType.equals(BindingNamespaceType.Data)
102                 && (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode
103                 || schemaNode instanceof RpcDefinition || schemaNode instanceof NotificationDefinition
104                 || schemaNode instanceof ChoiceCaseNode));
105     }
106
107     static Constant qNameConstant(final GeneratedTypeBuilderBase<?> toBuilder, final String constantName,
108                                   final QName name) {
109         return toBuilder.addConstant(Types.typeForClass(QName.class), constantName, name);
110     }
111
112     /**
113      * Created a method signature builder as part of
114      * <code>interfaceBuilder</code>.
115      *
116      * The method signature builder is created for the getter method of
117      * <code>schemaNodeName</code>. Also <code>comment</code> and
118      * <code>returnType</code> information are added to the builder.
119      *
120      * @param interfaceBuilder
121      *            generated type builder for which the getter method should be
122      *            created
123      * @param schemaNodeName
124      *            string with schema node name. The name will be the part of the
125      *            getter method name.
126      * @param comment
127      *            string with comment for the getter method
128      * @param returnType
129      *            type which represents the return type of the getter method
130      * @param status
131      *            status from yang file, for deprecated annotation
132      * @return method signature builder which represents the getter method of
133      *         <code>interfaceBuilder</code>
134      */
135     static MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder,
136                                                   final String schemaNodeName, final String comment, final Type returnType, final Status status) {
137
138         final MethodSignatureBuilder getMethod = interfaceBuilder
139                 .addMethod(getterMethodName(schemaNodeName, returnType));
140         if (status == Status.DEPRECATED) {
141             getMethod.addAnnotation("", "Deprecated");
142         }
143         getMethod.setComment(encodeAngleBrackets(comment));
144         getMethod.setReturnType(returnType);
145         return getMethod;
146     }
147
148     /**
149      * Creates the name of the getter method name from <code>localName</code>.
150      *
151      * @param localName
152      *            string with the name of the getter method
153      * @param returnType
154      *            return type
155      * @return string with the name of the getter method for
156      *         <code>methodName</code> in JAVA method format
157      */
158     private static String getterMethodName(final String localName, final Type returnType) {
159         final StringBuilder method = new StringBuilder();
160         if (BOOLEAN.equals(returnType)) {
161             method.append("is");
162         } else {
163             method.append("get");
164         }
165         // underscore used as separator for distinction of method parts in convertIdentifier()
166         method.append('_').append(localName);
167         return JavaIdentifierNormalizer.normalizeSpecificIdentifier(method.toString(), JavaIdentifier.METHOD);
168     }
169
170     static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName,
171                                     final SchemaContext schemaContext, final boolean verboseClassComments,
172                                     final BindingNamespaceType namespaceType) {
173         final StringBuilder sb = new StringBuilder();
174         final String nodeDescription = encodeAngleBrackets(schemaNode.getDescription());
175         final String formattedDescription = YangTextTemplate.formatToParagraph(nodeDescription, 0);
176
177         if (!Strings.isNullOrEmpty(formattedDescription)) {
178             sb.append(formattedDescription);
179             sb.append(NEW_LINE);
180         }
181
182         final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
183         if (verboseClassComments) {
184             sb.append("<p>");
185             sb.append("This class represents the following YANG schema fragment defined in module <b>");
186             sb.append(module.getName());
187             sb.append("</b>");
188             sb.append(NEW_LINE);
189             sb.append("<pre>");
190             sb.append(NEW_LINE);
191             String formedYang = YangSnippetCleaner.clean(yangTemplateForNode.render(schemaNode, module).body());
192             sb.append(encodeAngleBrackets(formedYang));
193             sb.append("</pre>");
194             sb.append(NEW_LINE);
195             sb.append("The schema path to identify an instance is");
196             sb.append(NEW_LINE);
197             sb.append("<i>");
198             sb.append(YangTextTemplate.formatSchemaPath(module.getName(), schemaNode.getPath().getPathFromRoot()));
199             sb.append("</i>");
200             sb.append(NEW_LINE);
201
202             if (hasBuilderClass(schemaNode, namespaceType) && !(schemaNode instanceof OperationDefinition)) {
203                 final StringBuilder linkToBuilderClass = new StringBuilder();
204                 final String basePackageName = BindingMapping.getRootPackageName(module);
205
206                 linkToBuilderClass
207                         .append(replacePackageTopNamespace(basePackageName, fullyQualifiedName,
208                                 namespaceType, BindingNamespaceType.Builder))
209                         .append("Builder");
210                 sb.append(NEW_LINE);
211                 sb.append("<p>To create instances of this class use " + "{@link " + linkToBuilderClass + "}.");
212                 sb.append(NEW_LINE);
213                 sb.append("@see ");
214                 sb.append(linkToBuilderClass);
215                 sb.append(NEW_LINE);
216                 if (schemaNode instanceof ListSchemaNode) {
217                     final StringBuilder linkToKeyClass = new StringBuilder();
218
219                     final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
220                     final String className = namespace[namespace.length - 1];
221
222                     linkToKeyClass.append(BindingGeneratorUtil.packageNameForSubGeneratedType(basePackageName, schemaNode,
223                             BindingNamespaceType.Key))
224                             .append('.')
225                             .append(className)
226                             .append("Key");
227
228                     final List<QName> keyDef = ((ListSchemaNode)schemaNode).getKeyDefinition();
229                     if (keyDef != null && !keyDef.isEmpty()) {
230                         sb.append("@see ");
231                         sb.append(linkToKeyClass);
232                     }
233                     sb.append(NEW_LINE);
234                 }
235             }
236         }
237
238         return replaceAllIllegalChars(sb);
239     }
240
241     static String createDescription(final Module module, final boolean verboseClassComments) {
242         final StringBuilder sb = new StringBuilder();
243         final String moduleDescription = encodeAngleBrackets(module.getDescription());
244         final String formattedDescription = YangTextTemplate.formatToParagraph(moduleDescription, 0);
245
246         if (!Strings.isNullOrEmpty(formattedDescription)) {
247             sb.append(formattedDescription);
248             sb.append(NEW_LINE);
249         }
250
251         if (verboseClassComments) {
252             sb.append("<p>");
253             sb.append("This class represents the following YANG schema fragment defined in module <b>");
254             sb.append(module.getName());
255             sb.append("</b>");
256             sb.append(NEW_LINE);
257             sb.append("<pre>");
258             sb.append(NEW_LINE);
259             String formedYang = YangSnippetCleaner.clean(yangTemplateForModule.render(module).body());
260             sb.append(encodeAngleBrackets(formedYang));
261             sb.append("</pre>");
262         }
263
264         return replaceAllIllegalChars(sb);
265     }
266
267     static String createDescription(final Set<? extends SchemaNode> schemaNodes, final Module module, final
268             boolean verboseClassComments) {
269         final StringBuilder sb = new StringBuilder();
270
271         if (!isNullOrEmpty(schemaNodes)) {
272             final SchemaNode node = schemaNodes.iterator().next();
273
274             if (node instanceof RpcDefinition) {
275                 sb.append("Interface for implementing the following YANG RPCs defined in module <b>" + module.getName() + "</b>");
276             } else if (node instanceof NotificationDefinition) {
277                 sb.append("Interface for receiving the following YANG notifications defined in module <b>" + module.getName() + "</b>");
278             }
279         }
280         sb.append(NEW_LINE);
281
282         if (verboseClassComments) {
283             sb.append("<pre>");
284             sb.append(NEW_LINE);
285             sb.append(encodeAngleBrackets(yangTemplateForNodes.render(schemaNodes, module).body()));
286             sb.append("</pre>");
287             sb.append(NEW_LINE);
288         }
289
290         return replaceAllIllegalChars(sb);
291     }
292
293     private static boolean isNullOrEmpty(final Collection<?> list) {
294         return list == null || list.isEmpty();
295     }
296
297     /**
298      * Returns first unique name for the augment generated type builder. The
299      * generated type builder name for augment consists from name of augmented
300      * node and serial number of its augmentation.
301      *
302      * @param builders
303      *            map of builders which were created in the package to which the
304      *            augmentation belongs
305      * @param genTypeName
306      *            string with name of augmented node
307      * @return string with unique name for augmentation builder
308      */
309     static String augGenTypeName(final Map<String, GeneratedTypeBuilder> builders, final String genTypeName) {
310         int index = 1;
311         if (builders != null) {
312             while (builders.containsKey(genTypeName + index)) {
313                 index = index + 1;
314             }
315         }
316         return genTypeName + index;
317     }
318
319     /**
320      * @param unknownSchemaNodes unknown schema nodes
321      * @return nodeParameter of UnknownSchemaNode
322      */
323     static String getAugmentIdentifier(final List<UnknownSchemaNode> unknownSchemaNodes) {
324         for (final UnknownSchemaNode unknownSchemaNode : unknownSchemaNodes) {
325             final QName nodeType = unknownSchemaNode.getNodeType();
326             if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.getLocalName())
327                     && YANG_EXT_NAMESPACE.equals(nodeType.getNamespace().toString())) {
328                 return unknownSchemaNode.getNodeParameter();
329             }
330         }
331         return null;
332     }
333
334     /**
335      * Adds enumeration builder created from <code>enumTypeDef</code> to
336      * <code>typeBuilder</code>.
337      *
338      * Each <code>enumTypeDef</code> item is added to builder with its name and
339      * value.
340      *
341      * @param enumTypeDef
342      *            EnumTypeDefinition contains enum data
343      * @param enumName
344      *            string contains name which will be assigned to enumeration
345      *            builder
346      * @param typeBuilder
347      *            GeneratedTypeBuilder to which will be enum builder assigned
348      * @param module
349      *            Module in which type should be generated
350      * @return enumeration builder which contains data from
351      *         <code>enumTypeDef</code>
352      */
353     static EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
354             final Map<Module, ModuleContext> genCtx, final GeneratedTypeBuilder typeBuilder, final Module module) {
355         if (enumTypeDef != null && typeBuilder != null && enumTypeDef.getQName().getLocalName() != null) {
356             final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName.getLocalName(), genCtx.get(module));
357             final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
358             enumBuilder.setDescription(enumTypedefDescription);
359             enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
360             final ModuleContext ctx = genCtx.get(module);
361             ctx.addInnerTypedefType(enumTypeDef.getPath(), enumBuilder);
362             return enumBuilder;
363         }
364         return null;
365     }
366
367
368     /**
369      * Builds generated TO builders for <code>typeDef</code> of type
370      * {@link UnionTypeDefinition} or {@link BitsTypeDefinition} which are
371      * also added to <code>typeBuilder</code> as enclosing transfer object.
372      *
373      * If more then one generated TO builder is created for enclosing then all
374      * of the generated TO builders are added to <code>typeBuilder</code> as
375      * enclosing transfer objects.
376      *
377      * @param typeDef
378      *            type definition which can be of type <code>UnionType</code> or
379      *            <code>BitsTypeDefinition</code>
380      * @param typeBuilder
381      *            generated type builder to which is added generated TO created
382      *            from <code>typeDef</code>
383      * @param leaf
384      *            string with name for generated TO builder
385      * @param parentModule
386      *            parent module
387      * @return generated TO builder for <code>typeDef</code>
388      */
389     static GeneratedTOBuilder addTOToTypeBuilder(final TypeDefinition<?> typeDef, final GeneratedTypeBuilder
390             typeBuilder, final DataSchemaNode leaf, final Module parentModule, final TypeProvider typeProvider,
391             final SchemaContext schemaContext, ModuleContext context) {
392         final String classNameFromLeaf = leaf.getQName().getLocalName();
393         GeneratedTOBuilder genTOBuilder = null;
394         final String packageName = typeBuilder.getFullyQualifiedName();
395         if (typeDef instanceof UnionTypeDefinition) {
396             genTOBuilder = ((TypeProviderImpl) typeProvider)
397                     .provideGeneratedTOBuilderForUnionTypeDef(packageName, ((UnionTypeDefinition) typeDef),
398                             classNameFromLeaf, leaf, schemaContext,
399                             ((TypeProviderImpl) typeProvider).getGenTypeDefsContextMap(), context);
400         } else if (typeDef instanceof BitsTypeDefinition) {
401             genTOBuilder = (((TypeProviderImpl) typeProvider)).provideGeneratedTOBuilderForBitsTypeDefinition(
402                     packageName, typeDef, classNameFromLeaf, parentModule.getName(), context);
403         }
404         if (genTOBuilder != null) {
405             typeBuilder.addEnclosingTransferObject(genTOBuilder);
406             return genTOBuilder;
407         }
408         return null;
409
410     }
411
412     @SuppressWarnings({ "unchecked", "rawtypes" })
413     static Type createReturnTypeForUnion(final GeneratedTOBuilder genTOBuilder, final TypeDefinition<?> typeDef,
414             final GeneratedTypeBuilder typeBuilder, final Module parentModule, final TypeProvider typeProvider) {
415         final GeneratedTOBuilderImpl returnType = (GeneratedTOBuilderImpl) genTOBuilder;
416         final String typedefDescription = encodeAngleBrackets(typeDef.getDescription());
417
418         returnType.setDescription(typedefDescription);
419         returnType.setReference(typeDef.getReference());
420         returnType.setSchemaPath((List) typeDef.getPath().getPathFromRoot());
421         returnType.setModuleName(parentModule.getName());
422
423         genTOBuilder.setTypedef(true);
424         genTOBuilder.setIsUnion(true);
425         TypeProviderImpl.addUnitsToGenTO(genTOBuilder, typeDef.getUnits());
426
427         return returnType.toInstance();
428     }
429
430     static boolean isInnerType(final LeafSchemaNode leaf, final TypeDefinition<?> type) {
431         return leaf.getPath().equals(type.getPath()) || leaf.getPath().equals(type.getPath().getParent());
432
433     }
434
435     /**
436      * Generates for the <code>list</code> which contains any list keys special
437      * generated TO builder.
438      *
439      * @param packageName
440      *            string with package name to which the list belongs
441      * @param list
442      *            schema node of list
443      * @return generated TO builder which represents the keys of the
444      *         <code>list</code> or empty TO builder if <code>list</code> is null or list of
445      *         key definitions is null or empty.
446      */
447     static GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list,
448             ModuleContext context) {
449         GeneratedTOBuilder genTOBuilder = null;
450         if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
451             // underscore used as separator for distinction of class name parts
452             final String genTOName =
453                     new StringBuilder(list.getQName().getLocalName()).append('_').append(BindingNamespaceType.Key)
454                             .toString();
455             genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName, context);
456         }
457         return genTOBuilder;
458     }
459
460     static GeneratedTypeBuilder resolveListKeyTypeBuilder(final String packageName, final ListSchemaNode list,
461             ModuleContext context) {
462         GeneratedTypeBuilder genTypeBuilder = null;
463         if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
464             // underscore used as separator for distinction of class name parts
465             final String genTOName =
466                     new StringBuilder(list.getQName().getLocalName()).append('_').append(BindingNamespaceType.Key)
467                             .toString();
468             genTypeBuilder = new GeneratedTypeBuilderImpl(packageName, genTOName, context);
469         }
470         return genTypeBuilder;
471     }
472
473     /**
474      * Converts <code>leaf</code> schema node to property of generated TO
475      * builder.
476      *
477      * @param toBuilder
478      *            generated TO builder to which is <code>leaf</code> added as
479      *            property
480      * @param leaf
481      *            leaf schema node which is added to <code>toBuilder</code> as
482      *            property
483      * @param returnType
484      *            property type
485      * @param isReadOnly
486      *            boolean value which says if leaf property is|isn't read only
487      * @return boolean value
488      *         <ul>
489      *         <li>false - if <code>leaf</code>, <code>toBuilder</code> or leaf
490      *         name equals null or if leaf is added by <i>uses</i>.</li>
491      *         <li>true - other cases</li>
492      *         </ul>
493      */
494     static boolean resolveLeafSchemaNodeAsProperty(final String nodeName, final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
495         final Type returnType, final boolean isReadOnly) {
496
497         if (returnType == null) {
498             return false;
499         }
500         final String leafName = leaf.getQName().getLocalName();
501         final String leafGetterName;
502
503         if ("key".equals(leafName.toLowerCase())) {
504             StringBuilder sb = new StringBuilder(leafName)
505                     .append('_').append("RESERVED_WORD");
506             leafGetterName = sb.toString();
507         } else {
508             leafGetterName = leafName;
509         }
510
511         final String leafDesc = encodeAngleBrackets(leaf.getDescription());
512         final GeneratedPropertyBuilder propBuilder =
513                 toBuilder.addProperty(JavaIdentifierNormalizer.normalizeSpecificIdentifier(leafGetterName, JavaIdentifier.METHOD));
514         propBuilder.setReadOnly(isReadOnly);
515         propBuilder.setReturnType(returnType);
516         propBuilder.setComment(leafDesc);
517         toBuilder.addEqualsIdentity(propBuilder);
518         toBuilder.addHashIdentity(propBuilder);
519         toBuilder.addToStringProperty(propBuilder);
520         return true;
521     }
522
523     static void checkModuleAndModuleName(final Module module) {
524         checkArgument(module != null, "Module reference cannot be NULL.");
525         checkArgument(module.getName() != null, "Module name cannot be NULL.");
526     }
527
528     @VisibleForTesting
529     public static String replaceAllIllegalChars(final StringBuilder stringBuilder){
530         final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
531         return ret.isEmpty() ? "" : ret;
532     }
533 }