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