def protected genUnionConstructor() '''
«FOR p : allProperties»
«val List<GeneratedProperty> other = new ArrayList(properties)»
- «val added = other.remove(p)»
- «genConstructor(p, other)»
+ «IF other.remove(p)»
+ «genConstructor(p, other)»
+ «ENDIF»
«ENDFOR»
'''
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.*;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG;
+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.NS_BAR;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc;
+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.testAugmentation;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-
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.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest {
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/augment-uses-to-augment");
- final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
- final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+ final SchemaContext context = parser.parseFiles(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
generator.generateToFile(sourcesOutputDir);
*/
package org.opendaylight.yangtools.sal.java.api.generator.test;
-import static org.junit.Assert.*;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG;
+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.NS_BAR;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount;
+import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc;
+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.lang.reflect.Constructor;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-
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.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class CascadeUsesCompilationTest extends BaseCompilationTest {
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/cascade-uses");
- final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
- final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+ final SchemaContext context = parser.parseFiles(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
generator.generateToFile(sourcesOutputDir);
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.yangtools.sal.java.api.generator.TOGenerator;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
public class ClassCodeGeneratorTest {
}
@Test
- public void compositeKeyClassTest() {
- final YangModelParser parser = new YangParserImpl();
- final Set<Module> modules = parser.parseYangModels(testModels);
- final SchemaContext context = parser.resolveSchemaContext(modules);
+ public void compositeKeyClassTest() throws IOException {
+ final YangContextParser parser = new YangParserImpl();
+ final SchemaContext context = parser.parseFiles(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
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.binding.annotations.RoutingContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
private void generateTestSources(String resourceDirPath, File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
- final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+ final SchemaContext context = parser.parseFiles(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
generator.generateToFile(sourcesOutputDir);
import java.io.File;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
-
import org.junit.Test;
import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.sal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
public class GenerateInnerClassForBitsAndUnionInLeavesTest {
- private SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) {
- final YangModelParser parser = new YangParserImpl();
+ private SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) throws Exception {
+ final YangContextParser parser = new YangParserImpl();
final List<File> inputFiles = new ArrayList<File>();
for (int i = 0; i < yangFiles.length; ++i) {
inputFiles.add(new File(yangFiles[i]));
}
- final Set<Module> modules = parser.parseYangModels(inputFiles);
- return parser.resolveSchemaContext(modules);
+ return parser.parseFiles(inputFiles);
}
@Test
- public void testInnerClassCreationForBitsAndUnionsInLeafes() throws URISyntaxException {
+ public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception {
final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();
final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
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.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/typedef");
- final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
- final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+ final SchemaContext context = parser.parseFiles(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
generator.generateToFile(sourcesOutputDir);
def CharSequence printUses(UsesNode usesNode) {
return '''
- «strong(listItem("uses", typeAnchorLink(usesNode.groupingPath, usesNode.groupingPath.path.last.localName)))»
+ «strong(listItem("uses", typeAnchorLink(usesNode.groupingPath, usesNode.groupingPath.pathTowardsRoot.iterator.next.localName)))»
<ul>
<li>refines:
<ul>
return parent;
}
+ /**
+ * Get the last component of this path.
+ *
+ * @return The last component of this path.
+ */
+ public final QName getLastComponent() {
+ return qname;
+ }
+
/**
* Describes whether schema path is|isn't absolute.
*
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
Preconditions.checkArgument(schemaPath != null, "Schema Path reference cannot be NULL");
- final List<QName> prefixedPath = (schemaPath.getPath());
+ final Iterable<QName> prefixedPath = schemaPath.getPathFromRoot();
if (prefixedPath == null) {
LOG.debug("Schema path {} has null path", schemaPath);
return null;
}
private static DataSchemaNode findCorrectTargetFromGrouping(final DataSchemaNode node, final SchemaContext ctx) {
- if (node.getPath().getPath().size() != 1) {
+ if (Iterables.size(node.getPath().getPathTowardsRoot()) != 1) {
QName currentName = node.getQName();
// tmpPath is used to track level of nesting
List<QName> tmpPath = new ArrayList<>();
import com.google.common.base.Splitter;
import com.google.common.collect.Collections2;
import com.google.common.io.ByteSource;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
*/
@Deprecated
public static SchemaPath createSchemaPath(final SchemaPath schemaPath, final QName... qname) {
- List<QName> path = new ArrayList<>(schemaPath.getPath());
- path.addAll(Arrays.asList(qname));
- return SchemaPath.create(path, schemaPath.isAbsolute());
+ return schemaPath.createChild(qname);
}
/**
package org.opendaylight.yangtools.yang.parser.builder.impl;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
}
private static DataBean getdata(final SchemaNodeBuilder old, final Builder newParent, final boolean updateQName) {
- List<QName> newPath = null;
+ final SchemaPath newSchemaPath;
QName newQName = null;
if (newParent instanceof ModuleBuilder) {
ModuleBuilder parent = (ModuleBuilder) newParent;
if (updateQName) {
newQName = new QName(parent.getNamespace(), parent.getRevision(), parent.getPrefix(), old.getQName()
.getLocalName());
- newPath = Collections.singletonList(newQName);
} else {
newQName = old.getQName();
- newPath = Collections.singletonList(newQName);
}
+ newSchemaPath = SchemaPath.create(true, newQName);
} else if (newParent instanceof AugmentationSchemaBuilder) {
AugmentationSchemaBuilder augment = (AugmentationSchemaBuilder) newParent;
ModuleBuilder parent = BuilderUtils.getParentModule(newParent);
if (updateQName) {
newQName = new QName(parent.getNamespace(), parent.getRevision(), parent.getPrefix(), old.getQName()
.getLocalName());
- newPath = new ArrayList<>(augment.getTargetNodeSchemaPath().getPath());
- newPath.add(newQName);
} else {
newQName = old.getQName();
- newPath = new ArrayList<>(augment.getTargetNodeSchemaPath().getPath());
- newPath.add(newQName);
}
-
+ newSchemaPath = augment.getTargetNodeSchemaPath().createChild(newQName);
} else if (newParent instanceof SchemaNodeBuilder) {
SchemaNodeBuilder parent = (SchemaNodeBuilder) newParent;
QName parentQName = parent.getQName();
if (updateQName) {
newQName = new QName(parentQName.getNamespace(), parentQName.getRevision(), parentQName.getPrefix(),
old.getQName().getLocalName());
- newPath = new ArrayList<>(parent.getPath().getPath());
- newPath.add(newQName);
} else {
newQName = old.getQName();
- newPath = new ArrayList<>(parent.getPath().getPath());
- newPath.add(newQName);
}
+ newSchemaPath = parent.getPath().createChild(newQName);
+ } else {
+ newSchemaPath = SchemaPath.ROOT;
}
- SchemaPath newSchemaPath = SchemaPath.create(newPath, true);
return new DataBean(newQName, newSchemaPath);
}
}
EnumPairImpl result = new EnumPairImpl();
- result.qname = path.getPath().get(path.getPath().size() - 1);
+ result.qname = path.getPathTowardsRoot().iterator().next();
result.path = path;
result.description = description;
result.reference = reference;
}
final List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
- return new BitImpl(position, schemaPath.getPath().get(schemaPath.getPath().size() - 1), schemaPath,
+ return new BitImpl(position, schemaPath.getPathTowardsRoot().iterator().next(), schemaPath,
description, reference, status, unknownNodes);
}