import java.util.ArrayList;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.antlr.v4.runtime.tree.ParseTree;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
private QNameToStatementDefinition stmtDef;
private PrefixToModule prefixes;
private List<String> toBeSkipped = new ArrayList<>();
+ private static final Logger LOG = LoggerFactory.getLogger(YangStatementParserListenerImpl.class);
public YangStatementParserListenerImpl(StatementSourceReference ref) {
this.ref = ref;
toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
}
} catch (SourceException e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
} else if (child instanceof YangStatementParser.ArgumentContext) {
try {
else
action = true;
} catch (SourceException e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
}
toBeSkipped.remove(statementName);
}
} catch (SourceException e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
}
}
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
import java.util.Collection;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
+ private static final Logger LOG = LoggerFactory.getLogger(AugmentStatementImpl.class);
+
protected AugmentStatementImpl(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
super(context);
}
- public static class Definition
- extends
- AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
+ public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
public Definition() {
super(Rfc6020Mapping.AUGMENT);
@Override
public void apply() throws InferenceException {
- final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
- .getAugmentTargetCtx(augmentNode);
- StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq
- .get();
+ final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils.getAugmentTargetCtx(augmentNode);
+ final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq.get();
try {
AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
} catch (SourceException e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
}
import java.util.Collection;
import java.util.HashSet;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-public class AugmentUtils {
+public final class AugmentUtils {
+
+ private AugmentUtils() {
+ }
private static final String REGEX_PATH_REL1 = "\\.\\.?\\s*/(.+)";
private static final String REGEX_PATH_REL2 = "//.*";
QName targetQName = (QName) targetStmtArgument;
QNameModule targetQNameModule = targetQName.getModule();
- if (targetQNameModule.equals(sourceQNameModule))
+ if (targetQNameModule.equals(sourceQNameModule)) {
return null;
- else
+ } else {
return targetQNameModule;
- } else
+ }
+ } else {
return null;
+ }
}
public static boolean needToCopyByAugment(StmtContext<?, ?, ?> stmtContext) {
- HashSet<StatementDefinition> noCopyDefSet = new HashSet<>();
+ Set<StatementDefinition> noCopyDefSet = new HashSet<>();
noCopyDefSet.add(Rfc6020Mapping.USES);
StatementDefinition def = stmtContext.getPublicDefinition();
- if (noCopyDefSet.contains(def))
- return false;
- else
- return true;
+ return (!noCopyDefSet.contains(def));
}
public static boolean isReusedByAugment(StmtContext<?, ?, ?> stmtContext) {
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class ContainerStatementImpl extends AbstractDeclaredStatement<QName> implements ContainerStatement {
- //private QName qname;
protected ContainerStatementImpl(StmtContext<QName, ContainerStatement,?> context) {
super(context);
- //this.qname =
}
public static class Definition extends AbstractStatementSupport<QName,ContainerStatement,EffectiveStatement<QName,ContainerStatement>> {
@Override
public void onFullDefinitionDeclared(
- Mutable<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> stmt)
- throws InferenceException, SourceException {
+ Mutable<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> stmt) throws SourceException {
stmt.getParentContext().addContext(GroupingNamespace.class, stmt.getStatementArgument(),stmt);
- //
}
}
import java.util.Collection;
import java.util.HashSet;
+import java.util.Set;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-public class GroupingUtils {
+public final class GroupingUtils {
+
+ private GroupingUtils() {
+ }
/**
* @param sourceGrpStmtCtx
QName sourceQName = (QName) sourceStmtArgument;
QNameModule sourceQNameModule = sourceQName.getModule();
- if (targetQNameModule.equals(sourceQNameModule))
+ if (targetQNameModule.equals(sourceQNameModule)) {
return null;
- else
+ }
+ else {
return targetQNameModule;
- } else
+ }
+ } else {
return null;
- } else
+ }
+ } else {
return null;
+ }
}
public static boolean needToCreateNewQName(
public static boolean needToCopyByUses(StmtContext<?, ?, ?> stmtContext) {
- HashSet<StatementDefinition> noCopyDefSet = new HashSet<StatementDefinition>();
+ Set<StatementDefinition> noCopyDefSet = new HashSet<StatementDefinition>();
noCopyDefSet.add(Rfc6020Mapping.USES);
StatementDefinition def = stmtContext.getPublicDefinition();
- if (noCopyDefSet.contains(def))
- return false;
- else
- return true;
+ return (!noCopyDefSet.contains(def));
}
public static boolean isReusedByUses(StmtContext<?, ?, ?> stmtContext) {
- HashSet<StatementDefinition> reusedDefSet = new HashSet<StatementDefinition>();
+ Set<StatementDefinition> reusedDefSet = new HashSet<StatementDefinition>();
reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
StatementDefinition def = stmtContext.getPublicDefinition();
- if (reusedDefSet.contains(def))
- return true;
- else
- return false;
+ return (reusedDefSet.contains(def));
}
public static void resolveUsesNode(
@Override
public void onLinkageDeclared(
final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
- throws InferenceException, SourceException {
+ throws SourceException {
final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt);
ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> imported;
@Override
public void apply() throws InferenceException {
StmtContext<?, ?, ?> importedModule = imported.get();
- // URI importedNs =
- // importedModule.firstSubstatement(NamespaceStatement.class).argument();
- // String prefix =
- // stmt.firstSubstatement(PrefixStatement.class).argument();
linkageTarget.get().addToNs(ImportedModuleContext.class, impIdentifier, importedModule);
- // prefixTarget.get().addToNs(PrefixToModule.class, prefix,
- // QNameModule.create(importedNs, null));
}
@Override
@Override
public void onLinkageDeclared(
final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt)
- throws InferenceException, SourceException {
+ throws SourceException {
final ModuleIdentifier includeSubmoduleIdentifier = getIncludeSubmoduleIdentifier(stmt);
ModelActionBuilder includeAction = stmt.newInferenceAction(SOURCE_LINKAGE);
@Override
public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
- System.out.println("");
if (failed.contains(requiresCtxPrerequisite)) {
throw new InferenceException("Included submodule was not found.", stmt
.getStatementSourceReference());
@Override
public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
throws SourceException {
- value = "input";
- return Utils.qNameFromArgument(ctx, value);
+ return Utils.qNameFromArgument(ctx, "input");
}
@Override
@Override
public void onLinkageDeclared(Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt)
- throws InferenceException, SourceException {
+ throws SourceException {
Optional<URI> moduleNs = Optional.fromNullable(firstAttributeOf(stmt.declaredSubstatements(),
NamespaceStatement.class));
@Override
public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
throws SourceException {
- value = "output";
- return Utils.qNameFromArgument(ctx, value);
+ return Utils.qNameFromArgument(ctx, "output");
}
@Override
@Override
public void onLinkageDeclared(
Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt)
- throws InferenceException, SourceException {
+ throws SourceException {
Optional<Date> revisionDate = Optional
.fromNullable(firstAttributeOf(
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.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
+
public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implements UsesStatement {
+ private static final Logger LOG = LoggerFactory.getLogger(UsesStatementImpl.class);
+
protected UsesStatementImpl(StmtContext<QName, UsesStatement, ?> context) {
super(context);
}
@Override
public void onFullDefinitionDeclared(
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode)
- throws InferenceException, SourceException {
+ throws SourceException {
ModelActionBuilder usesAction = usesNode.newInferenceAction(FULL_DECLARATION);
final QName groupingName = usesNode.getStatementArgument();
@Override
public void apply() throws InferenceException {
- StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre
- .get();
- StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre
- .get();
+ StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.get();
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.get();
try {
GroupingUtils.copyFromSourceToTarget(sourceGrpStmtCtx, targetNodeStmtCtx);
GroupingUtils.resolveUsesNode(usesNode, targetNodeStmtCtx);
} catch (SourceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
}
@Override
public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
if (failed.contains(sourceGroupingPre)) {
- throw new InferenceException("Grouping " + groupingName + " was not resovled.", usesNode
- .getStatementSourceReference());
+ throw new InferenceException("Grouping " + groupingName + " was not resovled.", usesNode.getStatementSourceReference());
}
throw new InferenceException("Unknown error occurred.", usesNode.getStatementSourceReference());
}
-
});
-
}
@Override
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
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.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class Utils {
+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 = "/[^/].+";
- public static final StatementSourceReference CONTEXT_REF = new StatementSourceReference() {
-
- @Override
- public StatementSource getStatementSource() {
- return StatementSource.CONTEXT;
- }
- };
-
public static List<String> splitPathToNodeNames(String path) {
Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
try {
xPath.compile(path);
} catch (XPathExpressionException e) {
- throw new IllegalArgumentException("An argument is not valid XPath string");
+ throw new IllegalArgumentException("Argument is not valid XPath string", e);
}
}
try {
qNameModule = QNameModule.create(new URI(""), new Date(0));
} catch (URISyntaxException e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
String localName = null;
if (argument instanceof QName) {
QName qname = (QName) argument;
qNamesFromRoot.add(qname);
- } else
+ } else {
return SchemaPath.SAME;
+ }
}
return SchemaPath.create(qNamesFromRoot, true);
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
/**
*
*
*/
-public class YangStatementSourceImpl implements StatementStreamSource {
+public final class YangStatementSourceImpl implements StatementStreamSource {
private YangStatementParserListenerImpl yangStatementModelParser;
private YangStatementParser.StatementContext statementContext;
private ParseTreeWalker walker;
+ private static final Logger LOG = LoggerFactory.getLogger(YangStatementSourceImpl.class);
+
+ private static final StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
public YangStatementSourceImpl(String fileName) {
try {
walker = new ParseTreeWalker();
yangStatementModelParser = new YangStatementParserListenerImpl(REF);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.warn(e.getMessage(), e);
}
}
- private StatementSourceReference REF = new StatementSourceReference() {
-
- @Override
- public StatementSource getStatementSource() {
- return StatementSource.DECLARATION;
- }
- };
-
@Override
public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
yangStatementModelParser.setAttributes(writer, stmtDef);
walker.walk(yangStatementModelParser, statementContext);
}
- private FileInputStream loadFile(String fileName) throws Exception {
+ private FileInputStream loadFile(String fileName) throws URISyntaxException, FileNotFoundException {
return new FileInputStream(new File(getClass().getResource(fileName).toURI()));
}
final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final YangStatementParser parser = new YangStatementParser(tokens);
- final YangStatementParser.StatementContext result = parser.statement();
- return result;
+ return parser.statement();
}
}