e77164a7d6da7436cd4ba2a3b5882c4447dbd20e
[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         return method.append(JavaIdentifierNormalizer.normalizeSpecificIdentifier(localName, JavaIdentifier.CLASS)).toString();
166     }
167
168     static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName,
169                                     final SchemaContext schemaContext, final boolean verboseClassComments,
170                                     final BindingNamespaceType namespaceType) {
171         final StringBuilder sb = new StringBuilder();
172         final String nodeDescription = encodeAngleBrackets(schemaNode.getDescription());
173         final String formattedDescription = YangTextTemplate.formatToParagraph(nodeDescription, 0);
174
175         if (!Strings.isNullOrEmpty(formattedDescription)) {
176             sb.append(formattedDescription);
177             sb.append(NEW_LINE);
178         }
179
180         final Module module = SchemaContextUtil.findParentModule(schemaContext, schemaNode);
181         if (verboseClassComments) {
182             sb.append("<p>");
183             sb.append("This class represents the following YANG schema fragment defined in module <b>");
184             sb.append(module.getName());
185             sb.append("</b>");
186             sb.append(NEW_LINE);
187             sb.append("<pre>");
188             sb.append(NEW_LINE);
189             String formedYang = YangSnippetCleaner.clean(yangTemplateForNode.render(schemaNode, module).body());
190             sb.append(encodeAngleBrackets(formedYang));
191             sb.append("</pre>");
192             sb.append(NEW_LINE);
193             sb.append("The schema path to identify an instance is");
194             sb.append(NEW_LINE);
195             sb.append("<i>");
196             sb.append(YangTextTemplate.formatSchemaPath(module.getName(), schemaNode.getPath().getPathFromRoot()));
197             sb.append("</i>");
198             sb.append(NEW_LINE);
199
200             if (hasBuilderClass(schemaNode, namespaceType) && !(schemaNode instanceof OperationDefinition)) {
201                 final StringBuilder linkToBuilderClass = new StringBuilder();
202                 final String basePackageName = BindingMapping.getRootPackageName(module);
203
204                 linkToBuilderClass
205                         .append(replacePackageTopNamespace(basePackageName, fullyQualifiedName,
206                                 namespaceType, BindingNamespaceType.Builder))
207                         .append("Builder");
208                 sb.append(NEW_LINE);
209                 sb.append("<p>To create instances of this class use " + "{@link " + linkToBuilderClass + "}.");
210                 sb.append(NEW_LINE);
211                 sb.append("@see ");
212                 sb.append(linkToBuilderClass);
213                 sb.append(NEW_LINE);
214                 if (schemaNode instanceof ListSchemaNode) {
215                     final StringBuilder linkToKeyClass = new StringBuilder();
216
217                     final String[] namespace = Iterables.toArray(BSDOT_SPLITTER.split(fullyQualifiedName), String.class);
218                     final String className = namespace[namespace.length - 1];
219
220                     linkToKeyClass.append(BindingGeneratorUtil.packageNameForSubGeneratedType(basePackageName, schemaNode,
221                             BindingNamespaceType.Key))
222                             .append('.')
223                             .append(className)
224                             .append("Key");
225
226                     final List<QName> keyDef = ((ListSchemaNode)schemaNode).getKeyDefinition();
227                     if (keyDef != null && !keyDef.isEmpty()) {
228                         sb.append("@see ");
229                         sb.append(linkToKeyClass);
230                     }
231                     sb.append(NEW_LINE);
232                 }
233             }
234         }
235
236         return replaceAllIllegalChars(sb);
237     }
238
239     static String createDescription(final Module module, final boolean verboseClassComments) {
240         final StringBuilder sb = new StringBuilder();
241         final String moduleDescription = encodeAngleBrackets(module.getDescription());
242         final String formattedDescription = YangTextTemplate.formatToParagraph(moduleDescription, 0);
243
244         if (!Strings.isNullOrEmpty(formattedDescription)) {
245             sb.append(formattedDescription);
246             sb.append(NEW_LINE);
247         }
248
249         if (verboseClassComments) {
250             sb.append("<p>");
251             sb.append("This class represents the following YANG schema fragment defined in module <b>");
252             sb.append(module.getName());
253             sb.append("</b>");
254             sb.append(NEW_LINE);
255             sb.append("<pre>");
256             sb.append(NEW_LINE);
257             String formedYang = YangSnippetCleaner.clean(yangTemplateForModule.render(module).body());
258             sb.append(encodeAngleBrackets(formedYang));
259             sb.append("</pre>");
260         }
261
262         return replaceAllIllegalChars(sb);
263     }
264
265     static String createDescription(final Set<? extends SchemaNode> schemaNodes, final Module module, final
266             boolean verboseClassComments) {
267         final StringBuilder sb = new StringBuilder();
268
269         if (!isNullOrEmpty(schemaNodes)) {
270             final SchemaNode node = schemaNodes.iterator().next();
271
272             if (node instanceof RpcDefinition) {
273                 sb.append("Interface for implementing the following YANG RPCs defined in module <b>" + module.getName() + "</b>");
274             } else if (node instanceof NotificationDefinition) {
275                 sb.append("Interface for receiving the following YANG notifications defined in module <b>" + module.getName() + "</b>");
276             }
277         }
278         sb.append(NEW_LINE);
279
280         if (verboseClassComments) {
281             sb.append("<pre>");
282             sb.append(NEW_LINE);
283             sb.append(encodeAngleBrackets(yangTemplateForNodes.render(schemaNodes, module).body()));
284             sb.append("</pre>");
285             sb.append(NEW_LINE);
286         }
287
288         return replaceAllIllegalChars(sb);
289     }
290
291     private static boolean isNullOrEmpty(final Collection<?> list) {
292         return list == null || list.isEmpty();
293     }
294
295     /**
296      * Returns first unique name for the augment generated type builder. The
297      * generated type builder name for augment consists from name of augmented
298      * node and serial number of its augmentation.
299      *
300      * @param builders
301      *            map of builders which were created in the package to which the
302      *            augmentation belongs
303      * @param genTypeName
304      *            string with name of augmented node
305      * @return string with unique name for augmentation builder
306      */
307     static String augGenTypeName(final Map<String, GeneratedTypeBuilder> builders, final String genTypeName) {
308         int index = 1;
309         if (builders != null) {
310             while (builders.containsKey(genTypeName + index)) {
311                 index = index + 1;
312             }
313         }
314         return genTypeName + index;
315     }
316
317     /**
318      * @param unknownSchemaNodes unknown schema nodes
319      * @return nodeParameter of UnknownSchemaNode
320      */
321     static String getAugmentIdentifier(final List<UnknownSchemaNode> unknownSchemaNodes) {
322         for (final UnknownSchemaNode unknownSchemaNode : unknownSchemaNodes) {
323             final QName nodeType = unknownSchemaNode.getNodeType();
324             if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.getLocalName())
325                     && YANG_EXT_NAMESPACE.equals(nodeType.getNamespace().toString())) {
326                 return unknownSchemaNode.getNodeParameter();
327             }
328         }
329         return null;
330     }
331
332     /**
333      * Adds enumeration builder created from <code>enumTypeDef</code> to
334      * <code>typeBuilder</code>.
335      *
336      * Each <code>enumTypeDef</code> item is added to builder with its name and
337      * value.
338      *
339      * @param enumTypeDef
340      *            EnumTypeDefinition contains enum data
341      * @param enumName
342      *            string contains name which will be assigned to enumeration
343      *            builder
344      * @param typeBuilder
345      *            GeneratedTypeBuilder to which will be enum builder assigned
346      * @param module
347      *            Module in which type should be generated
348      * @return enumeration builder which contains data from
349      *         <code>enumTypeDef</code>
350      */
351     static EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
352             final Map<Module, ModuleContext> genCtx, final GeneratedTypeBuilder typeBuilder, final Module module) {
353         if (enumTypeDef != null && typeBuilder != null && enumTypeDef.getQName().getLocalName() != null) {
354             final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName.getLocalName(), genCtx.get(module));
355             final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
356             enumBuilder.setDescription(enumTypedefDescription);
357             enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
358             final ModuleContext ctx = genCtx.get(module);
359             ctx.addInnerTypedefType(enumTypeDef.getPath(), enumBuilder);
360             return enumBuilder;
361         }
362         return null;
363     }
364
365
366     /**
367      * Builds generated TO builders for <code>typeDef</code> of type
368      * {@link UnionTypeDefinition} or {@link BitsTypeDefinition} which are
369      * also added to <code>typeBuilder</code> as enclosing transfer object.
370      *
371      * If more then one generated TO builder is created for enclosing then all
372      * of the generated TO builders are added to <code>typeBuilder</code> as
373      * enclosing transfer objects.
374      *
375      * @param typeDef
376      *            type definition which can be of type <code>UnionType</code> or
377      *            <code>BitsTypeDefinition</code>
378      * @param typeBuilder
379      *            generated type builder to which is added generated TO created
380      *            from <code>typeDef</code>
381      * @param leaf
382      *            string with name for generated TO builder
383      * @param parentModule
384      *            parent module
385      * @return generated TO builder for <code>typeDef</code>
386      */
387     static GeneratedTOBuilder addTOToTypeBuilder(final TypeDefinition<?> typeDef, final GeneratedTypeBuilder
388             typeBuilder, final DataSchemaNode leaf, final Module parentModule, final TypeProvider typeProvider,
389             final SchemaContext schemaContext, ModuleContext context, final Map<Module, ModuleContext> genCtx) {
390         final String classNameFromLeaf = leaf.getQName().getLocalName();
391         GeneratedTOBuilder genTOBuilder = null;
392         final String packageName = typeBuilder.getFullyQualifiedName();
393         if (typeDef instanceof UnionTypeDefinition) {
394             genTOBuilder = ((TypeProviderImpl) typeProvider)
395                     .provideGeneratedTOBuilderForUnionTypeDef(packageName, ((UnionTypeDefinition) typeDef),
396                             classNameFromLeaf, leaf, schemaContext,
397                             ((TypeProviderImpl) typeProvider).getGenTypeDefsContextMap(), context);
398         } else if (typeDef instanceof BitsTypeDefinition) {
399             genTOBuilder = (((TypeProviderImpl) typeProvider)).provideGeneratedTOBuilderForBitsTypeDefinition(
400                     packageName, typeDef, classNameFromLeaf, parentModule.getName(), context);
401         }
402         if (genTOBuilder != null) {
403             typeBuilder.addEnclosingTransferObject(genTOBuilder);
404             genCtx.get(parentModule).addInnerTypedefType(typeDef.getPath(), genTOBuilder);
405             return genTOBuilder;
406         }
407         return null;
408
409     }
410
411     @SuppressWarnings({ "unchecked", "rawtypes" })
412     static Type createReturnTypeForUnion(final GeneratedTOBuilder genTOBuilder, final TypeDefinition<?> typeDef,
413             final GeneratedTypeBuilder typeBuilder, final Module parentModule, final TypeProvider typeProvider) {
414         final GeneratedTOBuilderImpl returnType = (GeneratedTOBuilderImpl) genTOBuilder;
415         final String typedefDescription = encodeAngleBrackets(typeDef.getDescription());
416
417         returnType.setDescription(typedefDescription);
418         returnType.setReference(typeDef.getReference());
419         returnType.setSchemaPath((List) typeDef.getPath().getPathFromRoot());
420         returnType.setModuleName(parentModule.getName());
421
422         genTOBuilder.setTypedef(true);
423         genTOBuilder.setIsUnion(true);
424         TypeProviderImpl.addUnitsToGenTO(genTOBuilder, typeDef.getUnits());
425
426         return returnType.toInstance();
427     }
428
429     static boolean isInnerType(final LeafSchemaNode leaf, final TypeDefinition<?> type) {
430         return leaf.getPath().equals(type.getPath()) || leaf.getPath().equals(type.getPath().getParent());
431
432     }
433
434     /**
435      * Generates for the <code>list</code> which contains any list keys special
436      * generated TO builder.
437      *
438      * @param packageName
439      *            string with package name to which the list belongs
440      * @param list
441      *            schema node of list
442      * @return generated TO builder which represents the keys of the
443      *         <code>list</code> or empty TO builder if <code>list</code> is null or list of
444      *         key definitions is null or empty.
445      */
446     static GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list,
447             ModuleContext context) {
448         GeneratedTOBuilder genTOBuilder = null;
449         if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
450             // underscore used as separator for distinction of class name parts
451             final String genTOName =
452                     new StringBuilder(list.getQName().getLocalName()).append('_').append(BindingNamespaceType.Key)
453                             .toString();
454             genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName, context);
455         }
456         return genTOBuilder;
457     }
458
459     static GeneratedTypeBuilder resolveListKeyTypeBuilder(final String packageName, final ListSchemaNode list,
460             ModuleContext context) {
461         GeneratedTypeBuilder genTypeBuilder = null;
462         if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
463             // underscore used as separator for distinction of class name parts
464             final String genTOName =
465                     new StringBuilder(list.getQName().getLocalName()).append('_').append(BindingNamespaceType.Key)
466                             .toString();
467             genTypeBuilder = new GeneratedTypeBuilderImpl(packageName, genTOName, context);
468         }
469         return genTypeBuilder;
470     }
471
472     /**
473      * Converts <code>leaf</code> schema node to property of generated TO
474      * builder.
475      *
476      * @param toBuilder
477      *            generated TO builder to which is <code>leaf</code> added as
478      *            property
479      * @param leaf
480      *            leaf schema node which is added to <code>toBuilder</code> as
481      *            property
482      * @param returnType
483      *            property type
484      * @param isReadOnly
485      *            boolean value which says if leaf property is|isn't read only
486      * @return boolean value
487      *         <ul>
488      *         <li>false - if <code>leaf</code>, <code>toBuilder</code> or leaf
489      *         name equals null or if leaf is added by <i>uses</i>.</li>
490      *         <li>true - other cases</li>
491      *         </ul>
492      */
493     static boolean resolveLeafSchemaNodeAsProperty(final String nodeName, final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
494         final Type returnType, final boolean isReadOnly) {
495
496         if (returnType == null) {
497             return false;
498         }
499         final String leafName = leaf.getQName().getLocalName();
500         final String leafGetterName;
501
502         if ("key".equals(leafName.toLowerCase())) {
503             StringBuilder sb = new StringBuilder(leafName)
504                     .append('_').append("RESERVED_WORD");
505             leafGetterName = sb.toString();
506         } else {
507             leafGetterName = leafName;
508         }
509
510         final String leafDesc = encodeAngleBrackets(leaf.getDescription());
511         final GeneratedPropertyBuilder propBuilder =
512                 toBuilder.addProperty(JavaIdentifierNormalizer.normalizeSpecificIdentifier(leafGetterName, JavaIdentifier.METHOD));
513         propBuilder.setReadOnly(isReadOnly);
514         propBuilder.setReturnType(returnType);
515         propBuilder.setComment(leafDesc);
516         toBuilder.addEqualsIdentity(propBuilder);
517         toBuilder.addHashIdentity(propBuilder);
518         toBuilder.addToStringProperty(propBuilder);
519         return true;
520     }
521
522     static void checkModuleAndModuleName(final Module module) {
523         checkArgument(module != null, "Module reference cannot be NULL.");
524         checkArgument(module.getName() != null, "Module name cannot be NULL.");
525     }
526
527     @VisibleForTesting
528     public static String replaceAllIllegalChars(final StringBuilder stringBuilder){
529         final String ret = UNICODE_CHAR_PATTERN.matcher(stringBuilder).replaceAll("\\\\\\\\u");
530         return ret.isEmpty() ? "" : ret;
531     }
532 }