def protected CharSequence asJavadoc(String comment) {
if(comment == null) return ''
var txt = comment
- if (txt.contains("*/")) {
- txt = txt.replace("*/", "*/")
- }
+
txt = comment.trim
txt = formatToParagraph(txt)
}
def protected String formatDataForJavaDoc(GeneratedType type) {
- val typeDescription = type.getDescription();
+ val typeDescription = type.getDescription().encodeJavadocSymbols;
return '''
«IF !typeDescription.nullOrEmpty»
'''.toString
}
+ def encodeJavadocSymbols(String description) {
+ if (!description.nullOrEmpty) {
+ return description.replace("*/", "*/")
+ }
+ return description;
+ }
+
def asLink(String text) {
val StringBuilder sb = new StringBuilder()
var tempText = text
var StringBuilder lineBuilder = new StringBuilder();
var boolean isFirstElementOnNewLineEmptyChar = false;
- formattedText = formattedText.replace("*/", "*/")
+ formattedText = formattedText.encodeJavadocSymbols
formattedText = formattedText.replace(NEW_LINE, "")
formattedText = formattedText.replace("\t", "")
formattedText = formattedText.replaceAll(" +", " ");
lineBuilder.setLength(0)
sb.append(NEW_LINE)
- if(nextElement.toString == ' ')
+ if(nextElement.toString == ' ') {
isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
+ }
}
if(isFirstElementOnNewLineEmptyChar) {
--- /dev/null
+package org.opendaylight.yangtools.sal.java.api.generator.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+/**
+ * Test if generated classes from yang file is compilable, generated javadoc comments contains
+ * symbols as javadoc comment tag, which caused of compilation problem.
+ */
+public class EndodingInJavaDocTest extends BaseCompilationTest {
+
+ @Test
+ public void testAugmentToUsesInAugment() throws Exception {
+ final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "encoding-javadoc");
+ assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+ final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "encoding-javadoc");
+ assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+ final List<File> sourceFiles = getSourceFiles("/compilation/encoding-javadoc");
+ final SchemaContext context = parser.parseFiles(sourceFiles);
+ final List<Type> types = bindingGenerator.generateTypes(context);
+ final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
+ generator.generateToFile(sourcesOutputDir);
+
+ // Test if sources are compilable
+ testCompilation(sourcesOutputDir, compiledOutputDir);
+ cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+module encoding-javadoc {
+ yang-version 1;
+ namespace "urn:opendaylight:encoding-javadoc";
+ prefix "enc";
+
+ revision "2014-04-09" {
+ }
+
+ container cont1 {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 - http://tools.ietf.org/html/rfc6020";
+
+ list list1 {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 - http://tools.ietf.org/html/rfc6020";
+
+ key "topology-id";
+ leaf topology-id {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 - http://tools.ietf.org/html/rfc6020";
+ type int32;
+ }
+ uses link1;
+ }
+ }
+
+ grouping link1 {
+ list link1 {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 - http://tools.ietf.org/html/rfc6020";
+ key "link-id";
+ uses link-attributes;
+ }
+ }
+
+ grouping link-attributes {
+ leaf link-id {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 - http://tools.ietf.org/html/rfc6020";
+ type int8;
+ }
+ }
+
+ leaf inclusion-rulez {
+ description "/e.g. 1/*/*";
+ reference "RFC 6020 http://technet.com";
+
+ type string;
+ }
+
+ leaf inclusion-rule {
+ description "/e.g. 1/*/*";
+ default include;
+
+ type enumeration {
+ enum include {
+ description
+ "/e.g. 1/*/*";
+ }
+ enum exclude {
+ description
+ "/e.g. 1/*/*";
+ }
+ }
+ }
+}