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