* Represents unique path to the every node inside the module.
*/
public abstract class SchemaPath implements Immutable {
+
/**
* An absolute SchemaPath.
*/
*/
private volatile ImmutableList<QName> legacyPath;
+ protected SchemaPath(final SchemaPath parent, final QName qname) {
+ this.parent = parent;
+ this.qname = qname;
+
+ int h = parent == null ? 0 : parent.hashCode();
+ if (qname != null) {
+ h = h * 31 + qname.hashCode();
+ }
+
+ hash = h;
+ }
+
private ImmutableList<QName> getLegacyPath() {
ImmutableList<QName> ret = legacyPath;
if (ret == null) {
return getLegacyPath();
}
- protected SchemaPath(final SchemaPath parent, final QName qname) {
- this.parent = parent;
- this.qname = qname;
-
- int h = parent == null ? 0 : parent.hashCode();
- if (qname != null) {
- h = h * 31 + qname.hashCode();
- }
-
- hash = h;
- }
-
/**
* Constructs new instance of this class with the concrete path.
*
return this;
}
- SchemaPath parent = this;
+ SchemaPath parentPath = this;
for (QName qname : relative) {
- parent = parent.createInstance(parent, qname);
+ parentPath = parentPath.createInstance(parentPath, qname);
}
- return parent;
+ return parentPath;
}
/**
public SchemaPath createChild(final SchemaPath relative) {
Preconditions.checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
- SchemaPath parent = this;
+ SchemaPath parentPath = this;
for (QName qname : relative.getPathFromRoot()) {
- parent = parent.createInstance(parent, qname);
+ parentPath = parentPath.createInstance(parentPath, qname);
}
- return parent;
+ return parentPath;
}
/**
*
*/
public abstract class SchemaNodeIdentifier implements Immutable {
+
/**
* An absolute schema node identifier.
*/
*/
private volatile ImmutableList<QName> legacyPath;
+ protected SchemaNodeIdentifier(final SchemaNodeIdentifier parent, final QName qname) {
+ this.parent = parent;
+ this.qname = qname;
+
+ int h = parent == null ? 0 : parent.hashCode();
+ if (qname != null) {
+ h = h * 31 + qname.hashCode();
+ }
+
+ hash = h;
+ }
+
private ImmutableList<QName> getLegacyPath() {
ImmutableList<QName> ret = legacyPath;
if (ret == null) {
return getLegacyPath();
}
- protected SchemaNodeIdentifier(final SchemaNodeIdentifier parent, final QName qname) {
- this.parent = parent;
- this.qname = qname;
-
- int h = parent == null ? 0 : parent.hashCode();
- if (qname != null) {
- h = h * 31 + qname.hashCode();
- }
-
- hash = h;
- }
-
/**
* Constructs new instance of this class with the concrete path.
*
return this;
}
- SchemaNodeIdentifier parent = this;
+ SchemaNodeIdentifier parentNode = this;
for (QName qname : relative) {
- parent = parent.createInstance(parent, qname);
+ parentNode = parentNode.createInstance(parentNode, qname);
}
- return parent;
+ return parentNode;
}
/**
public SchemaNodeIdentifier createChild(final SchemaNodeIdentifier relative) {
Preconditions.checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
- SchemaNodeIdentifier parent = this;
+ SchemaNodeIdentifier parentNode = this;
for (QName qname : relative.getPathFromRoot()) {
- parent = parent.createInstance(parent, qname);
+ parentNode = parentNode.createInstance(parentNode, qname);
}
- return parent;
+ return parentNode;
}
/**
*/
@Beta
public class SchemaResolutionException extends SchemaSourceException {
+
+ private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
+
private static final long serialVersionUID = 1L;
private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
private final Collection<SourceIdentifier> resolvedSources;
this.resolvedSources = ImmutableList.copyOf(resolvedSources);
}
- private static final String MESSAGE_BLUEPRINT = "%s, resolved sources: %s, unsatisfied imports: %s";
private static String formatMessage(final String message, final Collection<SourceIdentifier> resolvedSources, final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
return String.format(MESSAGE_BLUEPRINT, message, resolvedSources, unsatisfiedImports);
}
* A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
*/
public static final SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
- private final Iterable<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS =
+ private final Iterable<Class<? extends SchemaSourceRepresentation>> Representations =
Collections.<Class<? extends SchemaSourceRepresentation>>singletonList(SchemaSourceRepresentation.class);
@Override
public Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
- return REPRESENTATIONS;
+ return Representations;
}
@Override
*/
public static final Pattern REVISION_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d-\\d\\d");
-
private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(SourceIdentifier.class);
private static final long serialVersionUID = 1L;
private final String revision;
private final String name;
+ /**
+ *
+ * Creates new YANG Schema source identifier for sources without revision.
+ * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
+ *
+ * @param name Name of schema
+ */
+ public SourceIdentifier(final String name) {
+ this(name, NOT_PRESENT_FORMATTED_REVISION);
+ }
+
/**
* Creates new YANG Schema source identifier.
*
return CACHE.getReference(this);
}
- /**
- *
- * Creates new YANG Schema source identifier for sources without revision.
- * {@link SourceIdentifier#NOT_PRESENT_FORMATTED_REVISION} as default revision.
- *
- * @param name Name of schema
- */
- public SourceIdentifier(final String name) {
- this(name, NOT_PRESENT_FORMATTED_REVISION);
- }
-
/**
* Returns model name
*
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import org.antlr.v4.runtime.tree.ParseTree;
private static final Date NULL_DATE = new Date(0L);
private static final String INPUT = "input";
private static final String OUTPUT = "output";
+ private static final String CHILD_NOT_FOUND_IN_NODE_STR = "Child {} not found in node {}";
private BuilderUtils() {
}
* current line in yang model
* @return module builder if found, null otherwise
*/
- public static ModuleBuilder findModuleFromBuilders(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ public static ModuleBuilder findModuleFromBuilders(final Map<String, NavigableMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module, final String prefix, final int line) {
ModuleBuilder dependentModule;
Date dependentModuleRevision;
String dependentModuleName = dependentModuleImport.getModuleName();
dependentModuleRevision = dependentModuleImport.getRevision();
- TreeMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
+ NavigableMap<Date, ModuleBuilder> moduleBuildersByRevision = modules.get(dependentModuleName);
if (moduleBuildersByRevision == null) {
return null;
}
public static ModuleBuilder findModuleFromBuilders(ModuleImport imp, Iterable<ModuleBuilder> modules) {
String name = imp.getModuleName();
Date revision = imp.getRevision();
- TreeMap<Date, ModuleBuilder> map = new TreeMap<>();
+ NavigableMap<Date, ModuleBuilder> map = new TreeMap<>();
for (ModuleBuilder module : modules) {
- if (module != null) {
- if (module.getName().equals(name)) {
- map.put(module.getRevision(), module);
- }
+ if (module != null && module.getName().equals(name)) {
+ map.put(module.getRevision(), module);
}
}
if (map.isEmpty()) {
*/
public static Module findModuleFromContext(final SchemaContext context, final ModuleBuilder currentModule,
final String prefix, final int line) {
- TreeMap<Date, Module> modulesByRevision = new TreeMap<>();
+ NavigableMap<Date, Module> modulesByRevision = new TreeMap<>();
ModuleImport dependentModuleImport = currentModule.getImport(prefix);
if (dependentModuleImport == null) {
node = findUnknownNode(name, parent);
}
} else if (parent instanceof RpcDefinitionBuilder) {
- if ("input".equals(name)) {
+ if (INPUT.equals(name)) {
node = ((RpcDefinitionBuilder) parent).getInput();
- } else if ("output".equals(name)) {
+ } else if (OUTPUT.equals(name)) {
node = ((RpcDefinitionBuilder) parent).getOutput();
} else {
if (node == null) {
return castOptional(SchemaNodeBuilder.class, findCaseInChoice((ChoiceBuilder) parent, child));
} else if (parent instanceof RpcDefinitionBuilder) {
return castOptional(SchemaNodeBuilder.class, findContainerInRpc((RpcDefinitionBuilder) parent, child));
-
} else {
- LOG.trace("Child {} not found in node {}", child, parent);
+ LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
return Optional.absent();
}
}
final QName child) {
if (INPUT.equals(child.getLocalName())) {
if (parent.getInput() == null) {
- QName qname = QName.create(parent.getQName().getModule(), "input");
+ QName qname = QName.create(parent.getQName().getModule(), INPUT);
final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(parent.getModuleName(),
parent.getLine(), qname, parent.getPath().createChild(qname));
inputBuilder.setParent(parent);
return Optional.of(parent.getInput());
} else if (OUTPUT.equals(child.getLocalName())) {
if (parent.getOutput() == null) {
- QName qname = QName.create(parent.getQName().getModule(), "output");
+ QName qname = QName.create(parent.getQName().getModule(), OUTPUT);
final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(parent.getModuleName(),
parent.getLine(), qname, parent.getPath().createChild(qname));
outputBuilder.setParent(parent);
}
return Optional.of(parent.getOutput());
}
- LOG.trace("Child {} not found in node {}", child, parent);
+ LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
return Optional.absent();
}
return Optional.of(caze);
}
}
- LOG.trace("Child {} not found in node {}", child, parent);
+ LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
return Optional.absent();
}
return Optional.of(childNode);
}
}
- LOG.trace("Child {} not found in node {}", child, parent);
+ LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, parent);
return Optional.absent();
}
return Optional.<SchemaNodeBuilder> of(childNode);
}
}
- LOG.trace("Child {} not found in node {}", child, builder);
+ LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, builder);
return Optional.absent();
}
final SchemaPath schemaPath = parentPath.createChild(qname);
if (node instanceof AnyXmlSchemaNode) {
- return new AnyXmlBuilder(moduleName, line, qname, schemaPath, ((AnyXmlSchemaNode) node));
+ return new AnyXmlBuilder(moduleName, line, qname, schemaPath, (AnyXmlSchemaNode) node);
} else if (node instanceof ChoiceSchemaNode) {
- return new ChoiceBuilder(moduleName, line, qname, schemaPath, ((ChoiceSchemaNode) node));
+ return new ChoiceBuilder(moduleName, line, qname, schemaPath, (ChoiceSchemaNode) node);
} else if (node instanceof ContainerSchemaNode) {
- return new ContainerSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((ContainerSchemaNode) node));
+ return new ContainerSchemaNodeBuilder(moduleName, line, qname, schemaPath, (ContainerSchemaNode) node);
} else if (node instanceof LeafSchemaNode) {
- return new LeafSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((LeafSchemaNode) node));
+ return new LeafSchemaNodeBuilder(moduleName, line, qname, schemaPath, (LeafSchemaNode) node);
} else if (node instanceof LeafListSchemaNode) {
- return new LeafListSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((LeafListSchemaNode) node));
+ return new LeafListSchemaNodeBuilder(moduleName, line, qname, schemaPath, (LeafListSchemaNode) node);
} else if (node instanceof ListSchemaNode) {
- return new ListSchemaNodeBuilder(moduleName, line, qname, schemaPath, ((ListSchemaNode) node));
+ return new ListSchemaNodeBuilder(moduleName, line, qname, schemaPath, (ListSchemaNode) node);
} else if (node instanceof ChoiceCaseNode) {
- return new ChoiceCaseBuilder(moduleName, line, qname, schemaPath, ((ChoiceCaseNode) node));
+ return new ChoiceCaseBuilder(moduleName, line, qname, schemaPath, (ChoiceCaseNode) node);
} else {
throw new YangParseException(moduleName, line, "Failed to copy node: Unknown type of DataSchemaNode: "
+ node);
for (TypeDefinition<?> node : nodes) {
QName qname = QName.create(parentQName, node.getQName().getLocalName());
SchemaPath schemaPath = parentPath.createChild(qname);
- result.add(new TypeDefinitionBuilderImpl(moduleName, line, qname, schemaPath, ((ExtendedType) node)));
+ result.add(new TypeDefinitionBuilderImpl(moduleName, line, qname, schemaPath, (ExtendedType) node));
}
return result;
}
}
}
- public static ModuleBuilder findModule(final QName qname, final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- TreeMap<Date, ModuleBuilder> map = modules.get(qname.getNamespace());
+ public static ModuleBuilder findModule(final QName qname, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ NavigableMap<Date, ModuleBuilder> map = modules.get(qname.getNamespace());
if (map == null) {
return null;
}
return map.get(qname.getRevision());
}
- public static Map<String, TreeMap<Date, URI>> createYangNamespaceContext(
+ public static Map<String, NavigableMap<Date, URI>> createYangNamespaceContext(
final Collection<? extends ParseTree> modules, final Optional<SchemaContext> context) {
- Map<String, TreeMap<Date, URI>> namespaceContext = new HashMap<>();
+ Map<String, NavigableMap<Date, URI>> namespaceContext = new HashMap<>();
Set<Submodule_stmtContext> submodules = new HashSet<>();
// first read ParseTree collection and separate modules and submodules
for (ParseTree module : modules) {
}
}
// update namespaceContext
- TreeMap<Date, URI> revToNs = namespaceContext.get(moduleName);
+ NavigableMap<Date, URI> revToNs = namespaceContext.get(moduleName);
if (revToNs == null) {
revToNs = new TreeMap<>();
revToNs.put(rev, namespace);
// from SchemaContext
if (context.isPresent()) {
for (Module module : context.get().getModules()) {
- TreeMap<Date, URI> revToNs = namespaceContext.get(module.getName());
+ NavigableMap<Date, URI> revToNs = namespaceContext.get(module.getName());
if (revToNs == null) {
revToNs = new TreeMap<>();
revToNs.put(module.getRevision(), module.getNamespace());
ParseTree belongsCtx = subHeaderCtx.getChild(j);
if (belongsCtx instanceof Belongs_to_stmtContext) {
final String belongsTo = ParserListenerUtils.stringFromNode(belongsCtx);
- TreeMap<Date, URI> ns = namespaceContext.get(belongsTo);
+ NavigableMap<Date, URI> ns = namespaceContext.get(belongsTo);
if (ns == null) {
throw new YangParseException(moduleName, submodule.getStart().getLine(), String.format(
"Unresolved belongs-to statement: %s", belongsTo));
}
// submodule get namespace and revision from module
- TreeMap<Date, URI> subNs = new TreeMap<>();
+ NavigableMap<Date, URI> subNs = new TreeMap<>();
subNs.put(ns.firstKey(), ns.firstEntry().getValue());
namespaceContext.put(moduleName, subNs);
}
copy.setAddedByUses(old.isAddedByUses());
copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
return copy;
copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
return copy;
copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
return copy;
copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
return copy;
copy.setAddedByUses(old.isAddedByUses());
copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
if (old.getType() == null) {
copy.setAddedByUses(old.isAddedByUses());
copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
if (old.getType() == null) {
copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
copy.setUserOrdered(old.isUserOrdered());
copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ copy.addUnknownNodeBuilder(copy(un, copy, updateQName));
}
return copy;
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- type.addUnknownNodeBuilder((copy(un, type, updateQName)));
+ type.addUnknownNodeBuilder(copy(un, type, updateQName));
}
type.setRanges(old.getRanges());
copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- copy.addUnknownNodeBuilder((copy(un, copy, false)));
+ copy.addUnknownNodeBuilder(copy(un, copy, false));
}
return copy;
c.setStatus(old.getStatus());
c.setAddedByUses(old.isAddedByUses());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodes()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ c.addUnknownNodeBuilder(copy(un, c, updateQName));
}
c.setExtensionBuilder(old.getExtensionBuilder());
c.setExtensionDefinition(old.getExtensionDefinition());
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
-import java.util.TreeMap;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
public final class GroupingUtils {
private static final Logger LOG = LoggerFactory.getLogger(GroupingUtils.class);
- private static final Splitter COLON_SPLITTER = Splitter.on(':');
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
private GroupingUtils() {
* if no grouping found
*/
public static GroupingBuilder getTargetGroupingFromModules(final UsesNodeBuilder usesBuilder,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
final int line = usesBuilder.getLine();
SchemaPath groupingPath = usesBuilder.getTargetGroupingPath();
*/
public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DocumentedNodeBuilder {
+ private static final String GROUPING_STR = "Grouping";
+ private static final String TYPEDEF_STR = "typedef";
private ModuleImpl instance;
private final String name;
private final String sourcePath;
public ExtensionBuilder addExtension(final QName qname, final int line, final SchemaPath path) {
checkNotSealed();
- Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "extension can be defined only in module or submodule");
}
}
}
final ExtensionBuilder builder = new ExtensionBuilderImpl(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
addedExtensions.add(builder);
return builder;
}
checkNotSealed();
final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
return builder;
}
checkNotSealed();
final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(name, line, qname, schemaPath);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
allLists.add(builder);
return builder;
checkNotSealed();
final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(name, line, qname, schemaPath);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
return builder;
}
checkNotSealed();
final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(name, line, qname, schemaPath);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
return builder;
}
checkNotSealed();
final GroupingBuilder builder = new GroupingBuilderImpl(name, line, qname, path);
- Builder parent = getActualNode();
- builder.setParent(parent);
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
String groupingName = qname.getLocalName();
- if (parent.equals(this)) {
+ if (parentBuilder.equals(this)) {
for (GroupingBuilder addedGrouping : getGroupingBuilders()) {
if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
- raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+ raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine());
}
}
addGrouping(builder);
} else {
- if (parent instanceof DataNodeContainerBuilder) {
- DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+ if (parentBuilder instanceof DataNodeContainerBuilder) {
+ DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder;
for (GroupingBuilder addedGrouping : parentNode.getGroupingBuilders()) {
if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
- raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+ raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine());
}
}
parentNode.addGrouping(builder);
- } else if (parent instanceof RpcDefinitionBuilder) {
- RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent;
+ } else if (parentBuilder instanceof RpcDefinitionBuilder) {
+ RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parentBuilder;
for (GroupingBuilder child : parentNode.getGroupings()) {
if (child.getQName().getLocalName().equals(groupingName)) {
- raiseYangParserException("", "Grouping", groupingName, line, child.getLine());
+ raiseYangParserException("", GROUPING_STR, groupingName, line, child.getLine());
}
}
parentNode.addGrouping(builder);
final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr,
targetPath, order);
- Builder parent = getActualNode();
- builder.setParent(parent);
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
- if (parent.equals(this)) {
+ if (parentBuilder.equals(this)) {
// augment can be declared only under 'module' ...
if (!(augmentTargetStr.startsWith("/"))) {
throw new YangParseException(
augmentBuilders.add(builder);
} else {
// ... or 'uses' statement
- if (parent instanceof UsesNodeBuilder) {
+ if (parentBuilder instanceof UsesNodeBuilder) {
if (augmentTargetStr.startsWith("/")) {
throw new YangParseException(name, line,
"If 'augment' statement is a substatement to the 'uses' statement, it cannot contain absolute path ("
+ augmentTargetStr + ")");
}
- ((UsesNodeBuilder) parent).addAugment(builder);
+ ((UsesNodeBuilder) parentBuilder).addAugment(builder);
} else {
throw new YangParseException(name, line, "Augment can be declared only under module or uses statement.");
}
checkNotSealed();
final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, grouping);
- Builder parent = getActualNode();
- usesBuilder.setParent(parent);
+ Builder parentBuilder = getActualNode();
+ usesBuilder.setParent(parentBuilder);
- if (parent.equals(this)) {
+ if (parentBuilder.equals(this)) {
addUsesNode(usesBuilder);
} else {
- if (!(parent instanceof DataNodeContainerBuilder)) {
+ if (!(parentBuilder instanceof DataNodeContainerBuilder)) {
throw new YangParseException(name, line, "Unresolved parent of uses '" + grouping + "'.");
}
- ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
+ ((DataNodeContainerBuilder) parentBuilder).addUsesNode(usesBuilder);
}
- if (parent instanceof AugmentationSchemaBuilder) {
+ if (parentBuilder instanceof AugmentationSchemaBuilder) {
usesBuilder.setAugmenting(true);
}
public void addRefine(final RefineHolderImpl refine) {
checkNotSealed();
- final Builder parent = getActualNode();
- if (!(parent instanceof UsesNodeBuilder)) {
+ final Builder parentBuilder = getActualNode();
+ if (!(parentBuilder instanceof UsesNodeBuilder)) {
throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
}
- ((UsesNodeBuilder) parent).addRefine(refine);
- refine.setParent(parent);
+ ((UsesNodeBuilder) parentBuilder).addRefine(refine);
+ refine.setParent(parentBuilder);
}
public RpcDefinitionBuilder addRpc(final int line, final QName qname, final SchemaPath path) {
checkNotSealed();
- Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
}
final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(name, line, qname, path);
- rpcBuilder.setParent(parent);
+ rpcBuilder.setParent(parentBuilder);
String rpcName = qname.getLocalName();
checkNotConflictingInDataNamespace(rpcName, line);
public ContainerSchemaNodeBuilder addRpcInput(final int line, final QName qname, final SchemaPath schemaPath) {
checkNotSealed();
- final Builder parent = getActualNode();
- if (!(parent instanceof RpcDefinitionBuilder)) {
+ final Builder parentBuilder = getActualNode();
+ if (!(parentBuilder instanceof RpcDefinitionBuilder)) {
throw new YangParseException(name, line, "input can be defined only in rpc statement");
}
- final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+ final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder;
final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
inputBuilder.setParent(rpc);
public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {
checkNotSealed();
- final Builder parent = getActualNode();
- if (!(parent instanceof RpcDefinitionBuilder)) {
+ final Builder parentBuilder = getActualNode();
+ if (!(parentBuilder instanceof RpcDefinitionBuilder)) {
throw new YangParseException(name, line, "output can be defined only in rpc statement");
}
- final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+ final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder;
final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
outputBuilder.setParent(rpc);
public NotificationBuilder addNotification(final int line, final QName qname, final SchemaPath path) {
checkNotSealed();
- final Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ final Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "notification can be defined only in module or submodule");
}
checkNotConflictingInDataNamespace(notificationName, line);
final NotificationBuilder builder = new NotificationBuilder(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
addedNotifications.add(builder);
return builder;
}
public FeatureBuilder addFeature(final int line, final QName qname, final SchemaPath path) {
- Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "feature can be defined only in module or submodule");
}
final FeatureBuilder builder = new FeatureBuilder(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
String featureName = qname.getLocalName();
for (FeatureBuilder addedFeature : addedFeatures) {
public ChoiceBuilder addChoice(final int line, final QName qname, final SchemaPath path) {
final ChoiceBuilder builder = new ChoiceBuilder(name, line, qname, path);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
return builder;
}
public ChoiceCaseBuilder addCase(final int line, final QName qname, final SchemaPath path) {
- Builder parent = getActualNode();
- if (parent == null || parent.equals(this)) {
+ Builder parentBuilder = getActualNode();
+ if (parentBuilder == null || parentBuilder.equals(this)) {
throw new YangParseException(name, line, "'case' parent not found");
}
final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
- if (parent instanceof ChoiceBuilder) {
- ((ChoiceBuilder) parent).addCase(builder);
- } else if (parent instanceof AugmentationSchemaBuilder) {
- ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+ if (parentBuilder instanceof ChoiceBuilder) {
+ ((ChoiceBuilder) parentBuilder).addCase(builder);
+ } else if (parentBuilder instanceof AugmentationSchemaBuilder) {
+ ((AugmentationSchemaBuilder) parentBuilder).addChildNode(builder);
} else {
throw new YangParseException(name, line, "Unresolved parent of 'case' " + qname.getLocalName());
}
public AnyXmlBuilder addAnyXml(final int line, final QName qname, final SchemaPath schemaPath) {
final AnyXmlBuilder builder = new AnyXmlBuilder(name, line, qname, schemaPath);
- Builder parent = getActualNode();
- builder.setParent(parent);
- addChildToParent(parent, builder, qname.getLocalName());
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
+ addChildToParent(parentBuilder, builder, qname.getLocalName());
return builder;
}
String nodeName = typedefBuilder.getQName().getLocalName();
for (TypeDefinitionBuilder tdb : getTypeDefinitionBuilders()) {
if (tdb.getQName().getLocalName().equals(nodeName)) {
- raiseYangParserException("", "typedef", nodeName, typedefBuilder.getLine(), tdb.getLine());
+ raiseYangParserException("", TYPEDEF_STR, nodeName, typedefBuilder.getLine(), tdb.getLine());
}
}
super.addTypedef(typedefBuilder);
public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname, final SchemaPath path) {
final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(name, line, qname, path);
- Builder parent = getActualNode();
- builder.setParent(parent);
+ Builder parentBuilder = getActualNode();
+ builder.setParent(parentBuilder);
String typedefName = qname.getLocalName();
- if (parent.equals(this)) {
+ if (parentBuilder.equals(this)) {
addTypedef(builder);
} else {
- if (parent instanceof DataNodeContainerBuilder) {
- DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+ if (parentBuilder instanceof DataNodeContainerBuilder) {
+ DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder;
for (TypeDefinitionBuilder child : parentNode.getTypeDefinitionBuilders()) {
if (child.getQName().getLocalName().equals(typedefName)) {
- raiseYangParserException("", "typedef", typedefName, line, child.getLine());
+ raiseYangParserException("", TYPEDEF_STR, typedefName, line, child.getLine());
}
}
parentNode.addTypedef(builder);
- } else if (parent instanceof RpcDefinitionBuilder) {
- RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent;
+ } else if (parentBuilder instanceof RpcDefinitionBuilder) {
+ RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parentBuilder;
for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) {
if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {
- raiseYangParserException("", "typedef", typedefName, line, tdb.getLine());
+ raiseYangParserException("", TYPEDEF_STR, typedefName, line, tdb.getLine());
}
}
rpcParent.addTypedef(builder);
}
public void setType(final TypeDefinition<?> type) {
- Builder parent = getActualNode();
- if (!(parent instanceof TypeAwareBuilder)) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder instanceof TypeAwareBuilder)) {
throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()
- + "'. Invalid parent node: " + parent);
+ + "'. Invalid parent node: " + parentBuilder);
}
- ((TypeAwareBuilder) parent).setType(type);
+ ((TypeAwareBuilder) parentBuilder).setType(type);
}
public UnionTypeBuilder addUnionType(final int line, final QNameModule module) {
- final Builder parent = getActualNode();
- if (parent == null) {
+ final Builder parentBuilder = getActualNode();
+ if (parentBuilder == null) {
throw new YangParseException(name, line, "Unresolved parent of union type");
} else {
final UnionTypeBuilder union = new UnionTypeBuilder(name, line);
- if (parent instanceof TypeAwareBuilder) {
- ((TypeAwareBuilder) parent).setTypedef(union);
+ if (parentBuilder instanceof TypeAwareBuilder) {
+ ((TypeAwareBuilder) parentBuilder).setTypedef(union);
return union;
} else {
throw new YangParseException(name, line, "Invalid parent of union type.");
public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) {
final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(name, line, baseString, schemaPath);
- final Builder parent = getActualNode();
- if (parent == null) {
+ final Builder parentBuilder = getActualNode();
+ if (parentBuilder == null) {
throw new YangParseException(name, line, "Unresolved parent of identityref type.");
} else {
- if (parent instanceof TypeAwareBuilder) {
- final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+ if (parentBuilder instanceof TypeAwareBuilder) {
+ final TypeAwareBuilder typeParent = (TypeAwareBuilder) parentBuilder;
typeParent.setTypedef(identityref);
dirtyNodes.add(typeParent);
} else {
}
public DeviationBuilder addDeviation(final int line, final SchemaPath targetPath) {
- Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
}
final DeviationBuilder builder = new DeviationBuilder(name, line, targetPath);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
deviationBuilders.add(builder);
return builder;
}
public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line, final SchemaPath path) {
- Builder parent = getActualNode();
- if (!(parent.equals(this))) {
+ Builder parentBuilder = getActualNode();
+ if (!(parentBuilder.equals(this))) {
throw new YangParseException(name, line, "identity can be defined only in module or submodule");
}
String identityName = qname.getLocalName();
}
final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
addedIdentities.add(builder);
return builder;
}
}
public UnknownSchemaNodeBuilderImpl addUnknownSchemaNode(final int line, final QName qname, final SchemaPath path) {
- final Builder parent = getActualNode();
+ final Builder parentBuilder = getActualNode();
final UnknownSchemaNodeBuilderImpl builder = new UnknownSchemaNodeBuilderImpl(name, line, qname, path);
- builder.setParent(parent);
+ builder.setParent(parentBuilder);
allUnknownNodes.add(builder);
- if (parent.equals(this)) {
+ if (parentBuilder.equals(this)) {
addedUnknownNodes.add(builder);
} else {
- if (parent instanceof SchemaNodeBuilder) {
- parent.addUnknownNodeBuilder(builder);
- } else if (parent instanceof DataNodeContainerBuilder) {
- parent.addUnknownNodeBuilder(builder);
- } else if (parent instanceof RefineHolderImpl) {
- parent.addUnknownNodeBuilder(builder);
+ if (parentBuilder instanceof SchemaNodeBuilder) {
+ parentBuilder.addUnknownNodeBuilder(builder);
+ } else if (parentBuilder instanceof DataNodeContainerBuilder) {
+ parentBuilder.addUnknownNodeBuilder(builder);
+ } else if (parentBuilder instanceof RefineHolderImpl) {
+ parentBuilder.addUnknownNodeBuilder(builder);
} else {
throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName()
+ "'");
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import org.opendaylight.yangtools.concepts.Immutable;
}
private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final Set<T> original) {
- TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+ NavigableSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
sorted.addAll(original);
return Collections.unmodifiableSet(sorted);
}
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<>();
private final Set<GroupingBuilder> addedGroupings = new HashSet<>();
+ RpcDefinitionBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
+ super(moduleName, line, qname);
+ this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
+ }
+
public ContainerSchemaNodeBuilder getInput() {
return inputBuilder;
}
return outputBuilder;
}
- RpcDefinitionBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path) {
- super(moduleName, line, qname);
- this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
- }
-
@Override
public RpcDefinition build() {
if (instance != null) {
import java.net.URI;
import java.util.Date;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
-import java.util.TreeMap;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
* current module
*/
public static void resolveType(final TypeAwareBuilder nodeToResolve,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
QName unknownTypeQName = nodeToResolve.getTypeQName();
final ModuleBuilder dependentModuleBuilder = BuilderUtils.findModule(unknownTypeQName, modules);
if (dependentModuleBuilder == null) {
* current module
*/
public static void resolveTypeUnion(final UnionTypeBuilder union,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
// special handling for identityref types under union
for (TypeDefinitionBuilder unionType : union.getTypedefs()) {
if (unionType instanceof IdentityrefTypeBuilder) {
* @return TypeDefinitionBuilder of node type
*/
private static TypeDefinitionBuilder findUnknownTypeDefinition(final TypeAwareBuilder nodeToResolve,
- final ModuleBuilder dependentModuleBuilder, final Map<URI, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder dependentModuleBuilder, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
final int line = nodeToResolve.getLine();
final QName unknownTypeQName = nodeToResolve.getTypeQName();
}
private static TypeConstraints findConstraintsFromTypeBuilder(final TypeAwareBuilder nodeToResolve,
- final TypeConstraints constraints, final Map<URI, TreeMap<Date, ModuleBuilder>> modules,
+ final TypeConstraints constraints, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules,
final ModuleBuilder builder) {
// union and identityref types cannot be restricted
Iterable<String> keyList = ValidationUtil.listKeysFromId(key);
Set<String> duplicates = ValidationUtil.getDuplicates(keyList);
- if (duplicates.size() != 0) {
+ if (!duplicates.isEmpty()) {
ValidationUtil.ex(ValidationUtil.f("(In (sub)module:%s) %s:%s, %s:%s contains duplicates:%s",
rootParentName, ValidationUtil.getSimpleStatementName(parent.getClass()),
ValidationUtil.getName(parent), ValidationUtil.getSimpleStatementName(ctx.getClass()), key,
// module builders sorted by dependencies
List<ModuleBuilder> sortedBuilders = ModuleDependencySort.sort(resolved);
- Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
+ Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
Collection<Module> unsorted = build(modules).values();
Set<Module> result = new LinkedHashSet<>(
ModuleDependencySort.sort(unsorted.toArray(new Module[unsorted.size()])));
}
final List<ModuleBuilder> sorted = resolveModuleBuilders(sources, context);
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, context);
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, context);
final Set<Module> unsorted = new LinkedHashSet<>(build(modules).values());
if (context != null) {
return resolveSchemaContext(result);
}
- private static Map<URI, TreeMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
+ private static Map<URI, NavigableMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
final SchemaContext context) {
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules = orderModules(sorted);
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = orderModules(sorted);
for (ModuleBuilder module : sorted) {
if (module != null) {
for (ModuleImport imp : module.getImports().values()) {
if (targetModule == null) {
Module result = findModuleFromContext(context, module, prefix, 0);
targetModule = new ModuleBuilder(result);
- TreeMap<Date, ModuleBuilder> map = modules.get(targetModule.getNamespace());
+ NavigableMap<Date, ModuleBuilder> map = modules.get(targetModule.getNamespace());
if (map == null) {
map = new TreeMap<>();
map.put(targetModule.getRevision(), targetModule);
public Collection<Module> buildModules(final Collection<ModuleBuilder> builders) {
Collection<ModuleBuilder> unsorted = resolveSubmodules(builders);
List<ModuleBuilder> sorted = ModuleDependencySort.sort(unsorted);
- Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
+ Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
Map<ModuleBuilder, Module> builderToModule = build(modules);
return builderToModule.values();
}
Map<ByteSource, ModuleBuilder> sourceToBuilder = resolveSources(sources, context);
// sort and check for duplicates
List<ModuleBuilder> sorted = ModuleDependencySort.sort(sourceToBuilder.values());
- Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
+ Map<URI, NavigableMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sorted, null);
Map<ModuleBuilder, Module> builderToModule = build(modules);
Map<ModuleBuilder, ByteSource> builderToSource = HashBiMap.create(sourceToBuilder).inverse();
sorted = ModuleDependencySort.sort(builderToModule.keySet());
// validate yang
new YangModelBasicValidator(walker).validate(sourceToTree.values());
- Map<String, TreeMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
+ Map<String, NavigableMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
sourceToTree.values(), Optional.fromNullable(context));
YangParserListenerImpl yangModelParser;
for (Map.Entry<ByteSource, ParseTree> entry : sourceToTree.entrySet()) {
private Map<ByteSource, ModuleBuilder> resolveSubmodules(final Map<ByteSource, ModuleBuilder> builders) {
Map<ByteSource, ModuleBuilder> modules = new HashMap<>();
- Map<String, TreeMap<Date, ModuleBuilder>> submodules = new HashMap<>();
+ Map<String, NavigableMap<Date, ModuleBuilder>> submodules = new HashMap<>();
for (Map.Entry<ByteSource, ModuleBuilder> entry : builders.entrySet()) {
ModuleBuilder builder = entry.getValue();
if (builder.isSubmodule()) {
String submoduleName = builder.getName();
- TreeMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
+ NavigableMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
if (map == null) {
map = new TreeMap<>();
map.put(builder.getRevision(), builder);
private Collection<ModuleBuilder> resolveSubmodules(final Collection<ModuleBuilder> builders) {
Collection<ModuleBuilder> modules = new HashSet<>();
- Map<String, TreeMap<Date, ModuleBuilder>> submodules = new HashMap<>();
+ Map<String, NavigableMap<Date, ModuleBuilder>> submodules = new HashMap<>();
for (ModuleBuilder builder : builders) {
if (builder.isSubmodule()) {
String submoduleName = builder.getName();
- TreeMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
+ NavigableMap<Date, ModuleBuilder> map = submodules.get(submoduleName);
if (map == null) {
map = new TreeMap<>();
map.put(builder.getRevision(), builder);
* @return collection of module builders with resolved submodules
*/
private void resolveSubmodules(final ModuleBuilder module,
- final Map<String, TreeMap<Date, ModuleBuilder>> submodules) {
+ final Map<String, NavigableMap<Date, ModuleBuilder>> submodules) {
Map<String, Date> includes = module.getIncludedModules();
for (Map.Entry<String, Date> entry : includes.entrySet()) {
NavigableMap<Date, ModuleBuilder> subs = submodules.get(entry.getKey());
}
}
- if (submodule.getIncludedModules().size() > 0) {
+ if (!submodule.getIncludedModules().isEmpty()) {
resolveSubmodules(submodule, submodules);
}
addSubmoduleToModule(submodule, module);
* topologically sorted modules
* @return modules ordered by namespace and revision
*/
- private static Map<URI, TreeMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
- final Map<URI, TreeMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
+ private static Map<URI, NavigableMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
for (final ModuleBuilder builder : modules) {
if (builder == null) {
continue;
rev = new Date(0);
}
- TreeMap<Date, ModuleBuilder> builderByRevision = result.get(ns);
+ NavigableMap<Date, ModuleBuilder> builderByRevision = result.get(ns);
if (builderByRevision == null) {
builderByRevision = new TreeMap<>();
builderByRevision.put(rev, builder);
// if this is submodule, add parent to filtered and pick its imports
if (main.isSubmodule()) {
- TreeMap<Date, ModuleBuilder> dependencies = new TreeMap<>();
+ NavigableMap<Date, ModuleBuilder> dependencies = new TreeMap<>();
for (ModuleBuilder mb : other) {
if (mb.getName().equals(main.getBelongsTo())) {
dependencies.put(mb.getRevision(), mb);
filterImports(builder, other, filtered);
}
} else {
- if (mi.getRevision().equals(builder.getRevision())) {
- if (!filtered.contains(builder)) {
- filtered.add(builder);
- filterImports(builder, other, filtered);
- }
+ if (!filtered.contains(builder) && mi.getRevision().equals(builder.getRevision())) {
+ filtered.add(builder);
+ filterImports(builder, other, filtered);
}
}
}
* all loaded modules
* @return modules mapped on their builders
*/
- private Map<ModuleBuilder, Module> build(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private Map<ModuleBuilder, Module> build(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
resolveDirtyNodes(modules);
resolveAugmentsTargetPath(modules);
resolveUsesTargetGrouping(modules);
// build
final Map<ModuleBuilder, Module> result = new LinkedHashMap<>();
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
final ModuleBuilder moduleBuilder = childEntry.getValue();
final Module module = moduleBuilder.build();
* @param modules
* all loaded modules
*/
- private void resolveDirtyNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ private void resolveDirtyNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
final ModuleBuilder module = childEntry.getValue();
resolveUnknownNodes(modules, module);
* @param module
* current module
*/
- private void resolveDirtyNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ private void resolveDirtyNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
if (!dirtyNodes.isEmpty()) {
for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
* @param modules
* all loaded modules
*/
- private void resolveAugmentsTargetPath(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveAugmentsTargetPath(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
// collect augments from all loaded modules
final List<AugmentationSchemaBuilder> allAugments = new ArrayList<>();
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
allAugments.addAll(inner.getValue().getAllAugments());
}
* all loaded modules topologically sorted (based on dependencies
* between each other)
*/
- private void resolveAugments(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveAugments(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
List<ModuleBuilder> all = new ArrayList<>();
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
all.add(inner.getValue());
}
* @return true if augment process succeed
*/
private boolean resolveUsesAugment(final AugmentationSchemaBuilder augment, final ModuleBuilder module,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
if (augment.isResolved()) {
return true;
}
* @return true if augment process succeed
*/
private boolean resolveAugment(final AugmentationSchemaBuilder augment, final ModuleBuilder module,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
if (augment.isResolved()) {
return true;
}
* @param modules
* all loaded modules
*/
- private void resolveIdentities(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ private void resolveIdentities(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
ModuleBuilder module = inner.getValue();
final Set<IdentitySchemaNodeBuilder> identities = module.getAddedIdentities();
* @param modules
* all loaded modules
*/
- private void resolveUsesTargetGrouping(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveUsesTargetGrouping(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
final List<UsesNodeBuilder> allUses = new ArrayList<>();
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
allUses.addAll(inner.getValue().getAllUsesNodes());
}
* @param modules
* all loaded modules
*/
- private void resolveUsesForGroupings(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveUsesForGroupings(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
final Set<GroupingBuilder> allGroupings = new HashSet<>();
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
ModuleBuilder module = inner.getValue();
allGroupings.addAll(module.getAllGroupings());
* @param modules
* all loaded modules
*/
- private void resolveUsesForNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ private void resolveUsesForNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
ModuleBuilder module = inner.getValue();
List<UsesNodeBuilder> usesNodes = module.getAllUsesNodes();
* @param modules
* all loaded modules
*/
- private void resolveUses(final UsesNodeBuilder usesNode, final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ private void resolveUses(final UsesNodeBuilder usesNode, final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
if (!usesNode.isResolved()) {
DataNodeContainerBuilder parent = usesNode.getParent();
ModuleBuilder module = BuilderUtils.getParentModule(parent);
DataSchemaNodeBuilder nextNodeAfterUses = null;
for (DataSchemaNodeBuilder childNode : childNodes) {
- if (!(childNode.isAddedByUses()) && !(childNode.isAugmenting())) {
- if (childNode.getLine() > usesLine) {
- nextNodeAfterUses = childNode;
- break;
- }
+ if (!childNode.isAddedByUses() && !childNode.isAugmenting() && childNode.getLine() > usesLine) {
+ nextNodeAfterUses = childNode;
+ break;
}
}
* @param module
* current module
*/
- private void resolveUnknownNodes(final Map<URI, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ private void resolveUnknownNodes(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
for (UnknownSchemaNodeBuilder usnb : module.getAllUnknownNodes()) {
QName nodeType = usnb.getNodeType();
String localName = usnb.getNodeType().getLocalName();
* @param modules
* all loaded modules
*/
- private void checkChoiceCasesForDuplicityQNames(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ private void checkChoiceCasesForDuplicityQNames(final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<URI, NavigableMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
final ModuleBuilder moduleBuilder = childEntry.getValue();
final Module module = moduleBuilder.build();
}
private void findDuplicityNodesIn(final ChoiceSchemaNode choiceNode, final Module module, final ModuleBuilder moduleBuilder,
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
- final Set<QName> duplicityTestSet = new HashSet<QName>();
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules) {
+ final Set<QName> duplicityTestSet = new HashSet<>();
for (ChoiceCaseNode choiceCaseNode : choiceNode.getCases()) {
}
private List<ChoiceSchemaNode> getChoicesFrom(final Module module) {
- final List<ChoiceSchemaNode> allChoices = new ArrayList<ChoiceSchemaNode>();
+ final List<ChoiceSchemaNode> allChoices = new ArrayList<>();
for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
findChoicesIn(dataSchemaNode, allChoices);
import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseYinValue;
import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.stringFromNode;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterables;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
+
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.opendaylight.yangtools.antlrv4.code.gen.YangParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
public final class YangParserListenerImpl extends YangParserBaseListener {
private static final Logger LOG = LoggerFactory.getLogger(YangParserListenerImpl.class);
private static final Splitter COLON_SPLITTER = Splitter.on(':');
private static final String AUGMENT_STR = "augment";
- private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+ private static final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+ private static final String IMPORT_STR = "import";
+ private static final String UNION_STR = "union";
+ private static final String UNKNOWN_NODE_STR = "unknown-node";
private final SchemaPathStack stack = new SchemaPathStack();
- private final Map<String, TreeMap<Date, URI>> namespaceContext;
+ private final Map<String, NavigableMap<Date, URI>> namespaceContext;
private final String sourcePath;
private QName moduleQName = QName.create(null, new Date(0L), "dummy");
private ModuleBuilder moduleBuilder;
private int augmentOrder;
private String yangModelPrefix;
- public YangParserListenerImpl(final Map<String, TreeMap<Date, URI>> namespaceContext, final String sourcePath) {
+ public YangParserListenerImpl(final Map<String, NavigableMap<Date, URI>> namespaceContext, final String sourcePath) {
this.namespaceContext = namespaceContext;
this.sourcePath = sourcePath;
}
* @param tree
* @return new instance of YangParserListenerImpl
*/
- public static YangParserListenerImpl create(final Map<String, TreeMap<Date, URI>> namespaceContext,
+ public static YangParserListenerImpl create(final Map<String, NavigableMap<Date, URI>> namespaceContext,
final String sourcePath, final ParseTreeWalker walker, final ParseTree tree) {
final YangParserListenerImpl ret = new YangParserListenerImpl(namespaceContext, sourcePath);
walker.walk(ret, tree);
return ret;
}
-
-
@Override
public void enterModule_stmt(final YangParser.Module_stmtContext ctx) {
moduleName = stringFromNode(ctx);
@Override
public void enterBelongs_to_stmt(final YangParser.Belongs_to_stmtContext ctx) {
final String belongsTo = stringFromNode(ctx);
- TreeMap<Date, URI> context = namespaceContext.get(belongsTo);
+ NavigableMap<Date, URI> context = namespaceContext.get(belongsTo);
final Map.Entry<Date, URI> entry = context.firstEntry();
// TODO
// Submodule will contain namespace and revision from module to which it
public void enterImport_stmt(final Import_stmtContext ctx) {
final int line = ctx.getStart().getLine();
final String importName = stringFromNode(ctx);
- enterLog("import", importName, line);
+ enterLog(IMPORT_STR, importName, line);
String importPrefix = null;
Date importRevision = null;
@Override
public void exitImport_stmt(final Import_stmtContext ctx) {
- exitLog("import");
+ exitLog(IMPORT_STR);
}
@Override
public void enterInclude_stmt(YangParser.Include_stmtContext ctx) {
final int line = ctx.getStart().getLine();
final String includeName = stringFromNode(ctx);
- enterLog("import", includeName, line);
+ enterLog(IMPORT_STR, includeName, line);
Date includeRevision = null;
for (int i = 0; i < ctx.getChildCount(); i++) {
moduleBuilder.addInclude(includeName, includeRevision);
}
- @Override public void exitInclude_stmt(YangParser.Include_stmtContext ctx) {
+ @Override
+ public void exitInclude_stmt(YangParser.Include_stmtContext ctx) {
exitLog("include");
}
stack.push();
final SchemaPath targetPath = parseXPathString(augmentPath, line);
- final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
+ final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath,
+ augmentOrder++);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
} else {
QName qname;
switch (typeName) {
- case "union":
- qname = BaseTypes.UNION_QNAME;
- stack.addNodeToPath(qname);
+ case UNION_STR:
+ stack.addNodeToPath(BaseTypes.UNION_QNAME);
final UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(line, moduleQName.getModule());
- final Builder parent = moduleBuilder.getActualNode();
- unionBuilder.setParent(parent);
+ final Builder parentBuilder = moduleBuilder.getActualNode();
+ unionBuilder.setParent(parentBuilder);
moduleBuilder.enterNode(unionBuilder);
break;
case "identityref":
parent.setTypeQName(typeQName);
moduleBuilder.markActualNodeDirty();
} else {
- ParserListenerUtils.parseUnknownTypeWithBody(typeBody, parent, typeQName, moduleBuilder,
- moduleQName, stack.currentSchemaPath());
+ ParserListenerUtils.parseUnknownTypeWithBody(typeBody, parent, typeQName, moduleBuilder, moduleQName,
+ stack.currentSchemaPath());
}
stack.addNodeToPath(QName.create(moduleQName.getModule(), typeQName.getLocalName()));
}
}
/**
- * Method transforms string representation of yang element (i.e. leaf name, container name etc.) into QName.
- * The namespace of QName is assigned from parent module same as revision date of module. If String qname parameter
- * contains ":" the string is evaluated as prefix:name of element. In this case method will look into import map
- * and extract correct ModuleImport. If such import is not present in import map the method will throw {@link YangParseException}
- * <br>
- * If ModuleImport is present but the value of namespace in ModuleImport is <code>null</code> the method will throw {@link YangParseException}
+ * Method transforms string representation of yang element (i.e. leaf name,
+ * container name etc.) into QName. The namespace of QName is assigned from
+ * parent module same as revision date of module. If String qname parameter
+ * contains ":" the string is evaluated as prefix:name of element. In this
+ * case method will look into import map and extract correct ModuleImport.
+ * If such import is not present in import map the method will throw
+ * {@link YangParseException} <br>
+ * If ModuleImport is present but the value of namespace in ModuleImport is
+ * <code>null</code> the method will throw {@link YangParseException}
*
- * @param qnameString QName value as String
- * @param line line in Yang model document where QName occur.
+ * @param qnameString
+ * QName value as String
+ * @param line
+ * line in Yang model document where QName occur.
* @return transformed string qname parameter as QName structure.
*
* @throws YangParseException
if (imp == null) {
LOG.debug("Error in module {} at line {}: No import found with prefix {}", moduleName, line, prefix);
throw new YangParseException(moduleName, line, "Error in module " + moduleName
- + " No import found with prefix " + prefix + " not found.");
+ + " No import found with prefix " + prefix + " not found.");
}
Date revision = imp.getRevision();
- TreeMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
+ NavigableMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
if (namespaces == null) {
throw new YangParseException(moduleName, line, String.format("Imported module %s not found",
imp.getModuleName()));
revision = namespaces.lastEntry().getKey();
namespace = namespaces.lastEntry().getValue();
} else {
- // FIXME: this lookup does not look right, as we will end up with
- // a qname which does not have a namespace. At any rate we
- // should arrive at a QNameModule!
+ // FIXME: this lookup does not look right, as we will end up
+ // with
+ // a qname which does not have a namespace. At any rate we
+ // should arrive at a QNameModule!
namespace = namespaces.get(revision);
}
@Override
public void exitType_stmt(final YangParser.Type_stmtContext ctx) {
final String typeName = stringFromNode(ctx);
- if ("union".equals(typeName)) {
+ if (UNION_STR.equals(typeName)) {
moduleBuilder.exitNode();
}
exitLog("type", stack.removeNodeFromPath());
stack.push();
final SchemaPath targetPath = parseXPathString(augmentPath, line);
- final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
+ final AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath,
+ augmentOrder++);
for (int i = 0; i < ctx.getChildCount(); i++) {
final ParseTree child = ctx.getChild(i);
} else if (childNode instanceof Key_stmtContext) {
final Set<String> key = createListKey((Key_stmtContext) childNode);
builder.setKeys(key);
- } else if (childNode instanceof YangParser.Identifier_stmtContext) {
- if (childNode.getChild(0).toString().equals("union")) {
- throw new YangParseException(moduleName, line, "Union statement is not allowed inside a list statement");
- }
+ } else if (childNode instanceof YangParser.Identifier_stmtContext
+ && UNION_STR.equals(childNode.getChild(0).toString())) {
+ throw new YangParseException(moduleName, line, "Union statement is not allowed inside a list statement");
}
}
}
@Override
public void exitIdentifier_stmt(final YangParser.Identifier_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("unknown-node", stack.removeNodeFromPath());
+ exitLog(UNKNOWN_NODE_STR, stack.removeNodeFromPath());
}
- @Override public void enterUnknown_statement(final YangParser.Unknown_statementContext ctx) {
+ @Override
+ public void enterUnknown_statement(final YangParser.Unknown_statementContext ctx) {
handleUnknownNode(ctx.getStart().getLine(), ctx);
}
- @Override public void exitUnknown_statement(final YangParser.Unknown_statementContext ctx) {
+ @Override
+ public void exitUnknown_statement(final YangParser.Unknown_statementContext ctx) {
moduleBuilder.exitNode();
- exitLog("unknown-node", stack.removeNodeFromPath());
+ exitLog(UNKNOWN_NODE_STR, stack.removeNodeFromPath());
}
@Override
private void handleUnknownNode(final int line, final ParseTree ctx) {
final String nodeParameter = stringFromNode(ctx);
- enterLog("unknown-node", nodeParameter, line);
+ enterLog(UNKNOWN_NODE_STR, nodeParameter, line);
final String nodeTypeStr = ctx.getChild(0).getText();
final QName nodeType = parseQName(nodeTypeStr, line);
QName qname = null;
try {
- //FIXME: rewrite whole method to handle unknown nodes properly.
- // This should be bugfix for bug https://bugs.opendaylight.org/show_bug.cgi?id=1539
- // After this fix bug https://bugs.opendaylight.org/show_bug.cgi?id=1538 MUST be fixed since
+ // FIXME: rewrite whole method to handle unknown nodes properly.
+ // This should be bugfix for bug
+ // https://bugs.opendaylight.org/show_bug.cgi?id=1539
+ // After this fix bug
+ // https://bugs.opendaylight.org/show_bug.cgi?id=1538 MUST be fixed
+ // since
// they are dependent!!!
if (Strings.isNullOrEmpty(nodeParameter)) {
qname = nodeType;
return stream;
}
- private final class SourceContext extends AbstractObjectRegistration<URL> //
+ private final class SourceContext extends AbstractObjectRegistration<URL>
implements Identifiable<SourceIdentifier> {
final SourceIdentifier identifier;
YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this);
LOG.debug("Trying to create schema context from {}", sourcesMap.keySet());
- if (yangSourceContext.getMissingDependencies().size() != 0) {
+ if (!yangSourceContext.getMissingDependencies().isEmpty()) {
LOG.debug("Omitting {} because of unresolved dependencies", yangSourceContext.getMissingDependencies().keySet());
LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources());
}
this.revision = formattedRevision == null ? null : QName.parseRevision(formattedRevision);
this.moduleImports = imports;
this.submoduleIncludes = includes;
- this.dependencies = ImmutableSet.<ModuleImport> builder() //
- .addAll(moduleImports) //
- .addAll(submoduleIncludes) //
+ this.dependencies = ImmutableSet.<ModuleImport> builder()
+ .addAll(moduleImports)
+ .addAll(submoduleIncludes)
.build();
}
return builder.build();
}
- public static String getLatestRevision(final Revision_stmtsContext revision_stmts) {
- List<Revision_stmtContext> revisions = revision_stmts.getRuleContexts(Revision_stmtContext.class);
+ public static String getLatestRevision(final Revision_stmtsContext revisionStmts) {
+ List<Revision_stmtContext> revisions = revisionStmts.getRuleContexts(Revision_stmtContext.class);
String latestRevision = null;
for (Revision_stmtContext revisionStmt : revisions) {
String currentRevision = getArgumentString(revisionStmt);
return builder.build();
}
- private static Date getRevision(final Revision_date_stmtContext revision_date_stmt) {
- if (revision_date_stmt == null) {
+ private static Date getRevision(final Revision_date_stmtContext revisionDateStmt) {
+ if (revisionDateStmt == null) {
return null;
}
- String formatedDate = getArgumentString(revision_date_stmt);
+ String formatedDate = getArgumentString(revisionDateStmt);
return QName.parseRevision(formatedDate);
}
private final String belongsTo;
+ private SubmoduleDependencyInfo(final String name, final String latestRevision, final String belongsTo,
+ final ImmutableSet<ModuleImport> imports, final ImmutableSet<ModuleImport> includes) {
+ super(name, latestRevision, imports, includes);
+ this.belongsTo = belongsTo;
+ }
+
/**
* Returns name of parent module.
*
return belongsTo;
}
- private SubmoduleDependencyInfo(final String name, final String latestRevision, final String belongsTo,
- final ImmutableSet<ModuleImport> imports, final ImmutableSet<ModuleImport> includes) {
- super(name, latestRevision, imports, includes);
- this.belongsTo = belongsTo;
- }
-
@Override
public String toString() {
return "Submodule [name=" + getName() + ", revision=" + getRevision() + ", dependencies="
*/
package org.opendaylight.yangtools.yang.parser.repo;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.NavigableMap;
import java.util.Set;
-import java.util.TreeMap;
+
import javax.annotation.Nullable;
+
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
final class SharedSchemaContextFactory implements SchemaContextFactory {
private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper.create("resolve sources", SchemaResolutionException.class);
private static final Logger LOG = LoggerFactory.getLogger(SharedSchemaContextFactory.class);
final Map<SourceIdentifier, ParserRuleContext> asts =
Maps.transformValues(srcs, ASTSchemaSource.GET_AST);
- final Map<String, TreeMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
+ final Map<String, NavigableMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
asts.values(), Optional.<SchemaContext>absent());
final ParseTreeWalker walker = new ParseTreeWalker();
*
*/
@Override
- public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException, SourceException {
+ public void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
// NOOP for most implementations
}
*
*/
@Override
- public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
- SourceException {
+ public void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
// NOOP for most implementations
}
*
*/
@Override
- public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException, SourceException {
+ public void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException {
// NOOP for most implementations
}
@Nullable <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(Class<N> type, K key);
- //<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromLocalStorage(Class<N> type);
-
@Nullable <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(Class<N> type, K key, V value);
}
public abstract V getFrom(NamespaceStorageNode storage, K key);
- //public abstract Map<K, V> getAllFrom(NamespaceStorageNode storage);
-
public abstract void addTo(NamespaceStorageNode storage,K key,V value);
@Override
return storage.getFromLocalStorage(getIdentifier(), key);
}
-// protected final Map<K, V> getAllFromLocalStorage(NamespaceStorageNode storage) {
-// return storage.getAllFromLocalStorage(getIdentifier());
-// }
-
protected final void addToStorage(NamespaceStorageNode storage,K key,V value) {
storage.addToLocalStorage(getIdentifier(),key,value);
}
return getFromLocalStorage(current,key);
}
-// @Override
-// public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
-// NamespaceStorageNode current = storage;
-// while(current.getStorageNodeType() != storageType) {
-// current = current.getParentNamespaceStorage();
-// }
-// return getAllFromLocalStorage(current);
-// }
-
@Override
public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, K key, V value) {
NamespaceStorageNode current = storage;
* @param stmt
* Context of added statement.
*/
- void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
- SourceException;
+ void onLinkageDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
/**
*
* Context of added statement. Argument and statement parent is
* accessible.
*/
- void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
- SourceException;
+ void onStatementDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
/**
*
* Context of added statement. Argument and statement parent is
* accessible.
*/
- void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws InferenceException,
- SourceException;
+ void onFullDefinitionDeclared(StmtContext.Mutable<A, D, E> stmt) throws SourceException;
}
\ No newline at end of file
private final ImmutableMap<QName, StatementSupport<?,?,?>> definitions;
private final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
- public ImmutableMap<QName, StatementSupport<?, ?, ?>> getDefinitions() {
- return definitions;
- }
-
private StatementSupportBundle(StatementSupportBundle parent,
- ImmutableMap<QName, StatementSupport<?, ?, ?>> statements,
- ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces) {
+ ImmutableMap<QName, StatementSupport<?, ?, ?>> statements,
+ ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces) {
this.parent = parent;
this.definitions = statements;
this.namespaceDefinitions = namespaces;
}
+ public ImmutableMap<QName, StatementSupport<?, ?, ?>> getDefinitions() {
+ return definitions;
+ }
+
public static Builder builder() {
return new Builder(EMPTY);
}
* Safe cast, previous checkState checks equivalence of key from
* which type argument are derived
*/
- @SuppressWarnings("unchecked")
- NamespaceBehaviour<K, V, N> casted = (NamespaceBehaviour<K, V, N>) potential;
- return casted;
+ return (NamespaceBehaviour<K, V, N>) potential;
}
if (parent != null) {
return parent.getNamespaceBehaviour(namespace);
public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
StmtContext<?, ?, ?> stmtContext, int startIndex, Class<? extends DeclaredStatement<?>>... types) {
- if (startIndex >= types.length)
+ if (startIndex >= types.length) {
return null;
+ }
Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
.declaredSubstatements();
* Safe cast, previous checkState checks equivalence of key from
* which type argument are derived
*/
- @SuppressWarnings("unchecked")
- NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) potential;
- return casted;
+ return (NamespaceBehaviourWithListeners<K, V, N>) potential;
}
throw new NamespaceNotAvailableException("Namespace " + type + "is not available in phase " + currentPhase);
}
private void completePhaseActions() throws ReactorException {
Preconditions.checkState(currentPhase != null);
- ArrayList<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
+ List<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
try {
boolean progressing = true;
while(progressing) {
private void tryToResolve() throws InferenceException {
if(action == null) {
- return; // Action was not yet defined
+ // Action was not yet defined
+ return;
}
if(removeSatisfied()) {
applyAction();
boolean allSatisfied = true;
while(prereq.hasNext()) {
if(prereq.next().isDone()) {
- prereq.remove(); // We are removing current prerequisite from list.
+ // We are removing current prerequisite from list.
+ prereq.remove();
} else {
allSatisfied = false;
}
public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
throws SourceException {
- StatementContextBase<A, D, E> copy = new RootStatementContext<A, D, E>(
- this, newQNameModule);
- return copy;
+ return new RootStatementContext<>(this, newQNameModule);
}
@Override
import java.util.EventListener;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.Map;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
private final StatementIdentifier identifier;
private final StatementSourceReference statementDeclSource;
- private LinkedHashMap<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
+ private Map<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
private Collection<StatementContextBase<?, ?, ?>> declared = new ArrayList<>();
private Collection<StatementContextBase<?, ?, ?>> effective = new ArrayList<>();
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
}
- public void checkNamespaceAllowed(Class<? extends IdentifierNamespace<?,?>> namespace) throws NamespaceNotAvailableException {
+ public void checkNamespaceAllowed(Class<? extends IdentifierNamespace<?,?>> namespace) {
// Noop
}
@Override
public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
- StatementContextBase<A,D,E> copy = new SubstatementContext<A,D,E>(this,newQNameModule, newParent);
- return copy;
+ return new SubstatementContext<>(this,newQNameModule, newParent);
}
@Override
public final class AugmentUtils {
- private AugmentUtils() {
- }
-
private static final String REGEX_PATH_REL1 = "\\.\\.?\\s*/(.+)";
private static final String REGEX_PATH_REL2 = "//.*";
+ private AugmentUtils() {
+ }
+
public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx, String path) {
if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) {
noCopyDefSet.add(Rfc6020Mapping.USES);
StatementDefinition def = stmtContext.getPublicDefinition();
- return (!noCopyDefSet.contains(def));
+ return !noCopyDefSet.contains(def);
}
public static boolean isReusedByAugment(StmtContext<?, ?, ?> stmtContext) {
- HashSet<StatementDefinition> reusedDefSet = new HashSet<>();
+ Set<StatementDefinition> reusedDefSet = new HashSet<>();
reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
StatementDefinition def = stmtContext.getPublicDefinition();
- if (reusedDefSet.contains(def))
- return true;
- else
- return false;
+
+ return reusedDefSet.contains(def);
}
public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseEffectiveStatementImpl;
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PresenceEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseEffectiveStatementImpl;
public class CaseStatementImpl extends AbstractDeclaredStatement<QName> implements CaseStatement {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.GroupingEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import java.util.Collection;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.GroupingEffectiveStatementImpl;
public class GroupingStatementImpl extends AbstractDeclaredStatement<QName>
implements GroupingStatement {
if (targetQNameModule.equals(sourceQNameModule)) {
return null;
- }
- else {
+ } else {
return targetQNameModule;
}
} else {
noCopyDefSet.add(Rfc6020Mapping.USES);
StatementDefinition def = stmtContext.getPublicDefinition();
- return (!noCopyDefSet.contains(def));
+ return !noCopyDefSet.contains(def);
}
public static boolean isReusedByUses(StmtContext<?, ?, ?> stmtContext) {
reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
StatementDefinition def = stmtContext.getPublicDefinition();
- return (reusedDefSet.contains(def));
+ return reusedDefSet.contains(def);
}
public static void resolveUsesNode(
if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)) {
// :TODO resolve and perform refine statement
}
-
+ if (StmtContextUtils.producesDeclared(subStmtCtx, AugmentStatement.class)) {
+ // :TODO find target node and perform augmentation
+ }
// :TODO resolve other uses substatements
}
}
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl;
-
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
-import com.google.common.base.Optional;
import java.net.URI;
import java.util.Date;
+
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl;
+
+import com.google.common.base.Optional;
public class ModuleStatementSupport extends
AbstractStatementSupport<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> {
@Override
public String parseArgumentValue(StmtContext<?, ?,?> ctx, String value) {
- return (value);
+ return value;
}
@Override
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-
-import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import com.google.common.base.Optional;
import java.net.URI;
import java.util.Date;
+
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import com.google.common.base.Optional;
public class SubmoduleStatementImpl extends
AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.FULL_DECLARATION;
import java.util.Collection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implements UsesStatement {
public final class Utils {
- private Utils() {
- }
-
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
private static final String REGEX_PATH_ABS = "/[^/].*";
+ private Utils() {
+ }
+
public static List<String> splitPathToNodeNames(String path) {
Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
StringBuilder sb = new StringBuilder();
List<TerminalNode> strings = context.STRING();
- if (strings.size() == 0) {
+ if (strings.isEmpty()) {
strings = Arrays.asList(context.IDENTIFIER());
}
for (TerminalNode stringNode : strings) {
public static QName qNameFromArgument(StmtContext<?, ?, ?> ctx, String value) {
- String prefix = null;
+ String prefix;
QNameModule qNameModule = null;
try {
qNameModule = QNameModule.create(new URI(""), new Date(0));
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+
+import java.util.Map;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import org.opendaylight.yangtools.yang.common.QName;
public abstract class AbstractEffectiveSchemaContext implements SchemaContext {
- protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = new Supplier<TreeSet<Module>>() {
+ protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = new Supplier<NavigableSet<Module>>() {
@Override
- public TreeSet<Module> get() {
+ public NavigableSet<Module> get() {
return new TreeSet<>(REVISION_COMPARATOR);
}
};
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
public void setCopyOf(final AugmentationSchema build) {
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
- HashSet<ChoiceCaseNode> cases = new HashSet<ChoiceCaseNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+ Set<ChoiceCaseNode> casesInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
if (effectiveStatement instanceof ChoiceCaseNode) {
ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) effectiveStatement;
- cases.add(choiceCaseNode);
+ casesInit.add(choiceCaseNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
- this.cases = ImmutableSet.copyOf(cases);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+ this.cases = ImmutableSet.copyOf(casesInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
this.rootEffectiveStatements = ImmutableList
.copyOf(rootEffectiveStatements);
- HashSet<Module> modules = new HashSet<Module>();
+ Set<Module> modulesInit = new HashSet<>();
for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
if (rootEffectiveStatement instanceof Module) {
Module module = (Module) rootEffectiveStatement;
- modules.add(module);
+ modulesInit.add(module);
}
}
- this.modules = ImmutableSet.copyOf(modules);
+ this.modules = ImmutableSet.copyOf(modulesInit);
final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
- for (Module m : modules) {
+ for (Module m : modulesInit) {
nameMap.put(m.getName(), m);
nsMap.put(m.getNamespace(), m);
}
Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx
.effectiveSubstatements();
- Collection<StatementContextBase<?, ?, ?>> substatements = new LinkedList<StatementContextBase<?, ?, ?>>();
- substatements.addAll(declaredSubstatements);
- substatements.addAll(effectiveSubstatements);
+ Collection<StatementContextBase<?, ?, ?>> substatementsInit = new LinkedList<>();
+ substatementsInit.addAll(declaredSubstatements);
+ substatementsInit.addAll(effectiveSubstatements);
- this.substatements = FluentIterable.from(substatements)
+ this.substatements = FluentIterable.from(substatementsInit)
.transform(StmtContextUtils.buildEffective()).toList();
}
result = Collection.class.cast(Collections2.filter(substatements,
Predicates.instanceOf(type)));
} catch (NoSuchElementException e) {
- result = Collections.EMPTY_LIST;
+ result = Collections.emptyList();
}
return result;
}
result = Collection.class.cast(Collections2.filter(substatements,
Predicates.instanceOf(type)));
} catch (NoSuchElementException e) {
- result = Collections.EMPTY_LIST;
+ result = Collections.emptyList();
}
return result;
}
if (yinElement != null) {
this.yin = yinElement.argument();
} else {
- yin = false;
+ this.yin = false;
}
}
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
}
@Override
*
*/
private void initKeyDefinition() {
- List<QName> keyDefinition = new LinkedList<QName>();
+ List<QName> keyDefinitionInit = new LinkedList<QName>();
KeyEffectiveStatementImpl key = firstEffective(KeyEffectiveStatementImpl.class);
if (key != null) {
Collection<SchemaNodeIdentifier> keyParts = key.argument();
for (SchemaNodeIdentifier keyPart : keyParts) {
- keyDefinition.add(keyPart.getLastComponent());
+ keyDefinitionInit.add(keyPart.getLastComponent());
}
}
- this.keyDefinition = ImmutableList.copyOf(keyDefinition);
+ this.keyDefinition = ImmutableList.copyOf(keyDefinitionInit);
}
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<UnknownSchemaNode>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<AugmentationSchema>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
// :TODO other substatement collections ...
}
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
private void initSubstatementCollections() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof AugmentationSchema) {
AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentations.add(augmentationSchema);
+ augmentationsInit.add(augmentationSchema);
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.augmentations = ImmutableSet.copyOf(augmentations);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
}
@Override
private void initSubstatements() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
- LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
- HashSet<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
- HashSet<TypeDefinition<?>> typeDefinitions = new HashSet<TypeDefinition<?>>();
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<GroupingDefinition> groupingsInit = new HashSet<>();
+ Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ unknownNodesInit.add(unknownNode);
}
if (effectiveStatement instanceof GroupingDefinition) {
GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
- groupings.add(groupingDefinition);
+ groupingsInit.add(groupingDefinition);
}
if (effectiveStatement instanceof TypeDefinition) {
TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
- typeDefinitions.add(typeDefinition);
+ typeDefinitionsInit.add(typeDefinition);
}
if (this.input == null && effectiveStatement instanceof InputEffectiveStatementImpl) {
this.input = (InputEffectiveStatementImpl) effectiveStatement;
}
}
- this.unknownNodes = ImmutableList.copyOf(unknownNodes);
- this.groupings = ImmutableSet.copyOf(groupings);
- this.typeDefinitions = ImmutableSet.copyOf(typeDefinitions);
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.groupings = ImmutableSet.copyOf(groupingsInit);
+ this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
}
@Override
/**
* Topological sort of dependent nodes in acyclic graphs.
- *
+ *
* @return Sorted {@link List} of {@link Node}s. Order: Nodes with no
* dependencies starting.
* @throws IllegalStateException
private static Set<Node> getDependentNodes(Set<Node> nodes) {
Set<Node> dependentNodes = Sets.newHashSet();
for (Node n : nodes) {
- if (n.getOutEdges().size() == 0) {
+ if (n.getOutEdges().isEmpty()) {
dependentNodes.add(n);
}
}
private final Set<Edge> inEdges;
private final Set<Edge> outEdges;
+ public NodeImpl() {
+ inEdges = Sets.newHashSet();
+ outEdges = Sets.newHashSet();
+ }
+
@Override
public Set<Edge> getInEdges() {
return inEdges;
outEdges.add(e);
to.getInEdges().add(e);
}
-
- public NodeImpl() {
- inEdges = Sets.newHashSet();
- outEdges = Sets.newHashSet();
- }
}
/**
private final Node from;
private final Node to;
+ public EdgeImpl(Node from, Node to) {
+ this.from = from;
+ this.to = to;
+ }
+
@Override
public Node getFrom() {
return from;
return to;
}
- public EdgeImpl(Node from, Node to) {
- this.from = from;
- this.to = to;
-
- }
-
@Override
public int hashCode() {
final int prime = 31;
*/
package org.opendaylight.yangtools.yang.parser.builder.impl;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import com.google.common.base.Optional;
import java.net.URI;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.util.Uint16;
-import org.opendaylight.yangtools.yang.parser.builder.api.*;
+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.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+import com.google.common.base.Optional;
+
/**
* Test suite for increasing of test coverage of BuilderUtils implementation.
*
@Test
public void testFindModuleFromBuildersWithNullPrefix() throws Exception {
- final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+ final Map<String, NavigableMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
ModuleBuilder result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, null, 12);
assertEquals(masterModule, result);
assertEquals(dependentModule, result);
}
- private Map<String, TreeMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
- final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>();
+ private Map<String, NavigableMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
+ final Map<String, NavigableMap<Date, ModuleBuilder>> modules = new HashMap<>();
final String module3Name = "Module3";
ModuleBuilder module3 = new ModuleBuilder(module3Name, "test/module/path/module3.yang");
dependentModule.addModuleImport(module3.getModuleName(), module3.getRevision(), "ter");
- final TreeMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
+ final NavigableMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
module1Map.put(masterModule.getRevision(), masterModule);
- final TreeMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
+ final NavigableMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
module2Map.put(dependentModule.getRevision(), dependentModule);
- final TreeMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
+ final NavigableMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
module3Map.put(module3.getRevision(), module3);
modules.put(masterModule.getName(), module1Map);
@Test(expected = YangParseException.class)
public void testFindModuleFromBuildersWithNoImportedModule() throws Exception {
- final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+ final Map<String, NavigableMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
BuilderUtils.findModuleFromBuilders(testModules, masterModule, "eth", 12);
}
@Test
public void testFindModule() {
- final Map<URI, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
- final TreeMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
+ final Map<URI, NavigableMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
+ final NavigableMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
masterModuleMap.put(masterModule.getRevision(), masterModule);
modules.put(masterModule.getNamespace(), masterModuleMap);