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/*/*";
+ }
+ }
+ }
+}
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<!-- test the features.xml -->
<dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.17.1-GA</version>
+ <version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
package org.opendaylight.yangtools.yang.model.repo.util;
import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
+import com.google.common.base.FinalizablePhantomReference;
+import com.google.common.base.FinalizableReferenceQueue;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
-
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
@Beta
-public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T> {
- private static final class CacheEntry<T extends SchemaSourceRepresentation> {
- private final SchemaSourceRegistration<T> reg;
- private final T source;
-
- public CacheEntry(final T source, final SchemaSourceRegistration<T> reg) {
- this.source = Preconditions.checkNotNull(source);
- this.reg = Preconditions.checkNotNull(reg);
- }
- }
-
- private static final RemovalListener<SourceIdentifier, CacheEntry<?>> LISTENER = new RemovalListener<SourceIdentifier, CacheEntry<?>>() {
- @Override
- public void onRemoval(final RemovalNotification<SourceIdentifier, CacheEntry<?>> notification) {
- notification.getValue().reg.close();
- }
- };
-
- private final Cache<SourceIdentifier, CacheEntry<T>> cache;
+public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T> implements AutoCloseable {
+ private final List<FinalizablePhantomReference<T>> regs = Collections.synchronizedList(new ArrayList<FinalizablePhantomReference<T>>());
+ private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue();
+ private final Cache<SourceIdentifier, T> cache;
protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final CacheBuilder<Object, Object> builder) {
super(consumer, representation, Costs.IMMEDIATE);
- cache = builder.removalListener(LISTENER).build();
+ cache = builder.build();
}
public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(final SchemaSourceRegistry consumer, final Class<R> representation) {
@Override
public CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
- final CacheEntry<T> present = cache.getIfPresent(sourceIdentifier);
+ final T present = cache.getIfPresent(sourceIdentifier);
if (present != null) {
- return Futures.immediateCheckedFuture(present.source);
+ return Futures.immediateCheckedFuture(present);
}
return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
@Override
protected void offer(final T source) {
- final CacheEntry<T> present = cache.getIfPresent(source.getIdentifier());
+ final T present = cache.getIfPresent(source.getIdentifier());
if (present == null) {
+ cache.put(source.getIdentifier(), source);
+
final SchemaSourceRegistration<T> reg = register(source.getIdentifier());
- cache.put(source.getIdentifier(), new CacheEntry<T>(source, reg));
+ final FinalizablePhantomReference<T> ref = new FinalizablePhantomReference<T>(source, queue) {
+ @Override
+ public void finalizeReferent() {
+ reg.close();
+ regs.remove(this);
+ }
+ };
+
+ regs.add(ref);
}
}
+
+ @Override
+ public void close() {
+ while (!regs.isEmpty()) {
+ final FinalizablePhantomReference<?> ref = regs.get(0);
+ ref.finalizeReferent();
+ }
+
+ cache.invalidateAll();
+ queue.close();
+ }
}