Brings the violation count to below 500.
Change-Id: I22ee943c06bf04f3692a511f703573a0a57ec0ba
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
@Override
+ @SuppressWarnings("checkstyle:parameterName")
public void endElement(final String uri, final String localName, final String qName) {
addTextIfNeeded();
final Element closedEl = stack.pop();
private final List<YangSyntaxErrorException> exceptions = new ArrayList<>();
@Override
+ @SuppressWarnings("checkstyle:parameterName")
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
final int charPositionInLine, final String msg, final RecognitionException e) {
LOG.debug("Syntax error at {}:{}: {}", line, charPositionInLine, msg, e);
exceptions.add(new YangSyntaxErrorException(module, line, charPositionInLine, msg, e));
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private static String getModuleName(final Recognizer<?, ?> recognizer) {
if (!(recognizer instanceof Parser)) {
return null;
public static YangStatementStreamSource create(final YangTextSchemaSource source) throws IOException,
YangSyntaxErrorException {
final StatementContext context;
- try (final InputStream stream = source.openStream()) {
+ try (InputStream stream = source.openStream()) {
context = parseYangSource(stream);
}
return context;
}
- /**
- * @deprecated Provided for migration purposes only. Do not use.
- */
- @Deprecated
- public static StatementContext parseYangSource(final InputStream stream) throws IOException,
+ private static StatementContext parseYangSource(final InputStream stream) throws IOException,
YangSyntaxErrorException {
final YangStatementLexer lexer = new YangStatementLexer(CharStreams.fromStream(stream));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
public URI load(@Nonnull final String key) throws URISyntaxException {
return new URI(key);
}
- });
+ });
private final SourceIdentifier identifier;
private final Node root;
return new YinTextToDomTransformer(provider, consumer);
}
- public static YinDomSchemaSource transformSource(final YinTextSchemaSource source) throws SAXException, IOException {
+ public static YinDomSchemaSource transformSource(final YinTextSchemaSource source) throws SAXException,
+ IOException {
final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
final SAXParser parser = UntrustedXML.newSAXParser();
final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
parser.parse(source.openStream(), handler);
return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc));
}
-
}
throw new SomeModifiersUnresolvedException(currentPhase, sourceId, cause);
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private EffectiveSchemaContext transformEffective() throws ReactorException {
Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
loadPhaseStatementsFor(libSources);
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private void loadPhaseStatementsFor(final Set<SourceSpecificContext> sources) throws ReactorException {
for (final SourceSpecificContext source : sources) {
try {
if (suppressed.length > 0) {
LOG.error("{} additional errors reported:", suppressed.length);
- int i = 1;
+ int count = 1;
for (final Throwable t : suppressed) {
// FIXME: this should be configured in the appender, really
if (LOG.isDebugEnabled()) {
- LOG.error("Error {}: {}", i, t.getMessage(), t);
+ LOG.error("Error {}: {}", count, t.getMessage(), t);
} else {
- LOG.error("Error {}: {}", i, t.getMessage());
+ LOG.error("Error {}: {}", count, t.getMessage());
}
- i++;
+ count++;
}
}
return buildFailure;
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private void completePhaseActions() throws ReactorException {
Preconditions.checkState(currentPhase != null);
final List<SourceSpecificContext> sourcesToProgress = Lists.newArrayList(sources);
* @param argument statement argument
* @return A new substatement
*/
+ @SuppressWarnings("checkstyle:methodTypeParameterName")
public final <CA, CD extends DeclaredStatement<CA>, CE extends EffectiveStatement<CA, CD>>
StatementContextBase<CA, CD, CE> createSubstatement(final int offset,
final StatementDefinitionContext<CA, CD, CE> def, final StatementSourceReference ref,
import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-final class VirtualNamespaceContext<K, V, N extends IdentifierNamespace<K, V>, DK>
+final class VirtualNamespaceContext<K, V, N extends IdentifierNamespace<K, V>, D>
extends NamespaceBehaviourWithListeners<K, V, N> {
- private final Multimap<DK, ValueAddedListener<K>> listeners = HashMultimap.create();
- private final DerivedNamespaceBehaviour<K, V, DK, N, ?> derivedDelegate;
+ private final Multimap<D, ValueAddedListener<K>> listeners = HashMultimap.create();
+ private final DerivedNamespaceBehaviour<K, V, D, N, ?> derivedDelegate;
- VirtualNamespaceContext(final DerivedNamespaceBehaviour<K, V, DK, N, ?> delegate) {
+ VirtualNamespaceContext(final DerivedNamespaceBehaviour<K, V, D, N, ?> delegate) {
super(delegate);
this.derivedDelegate = delegate;
}
listeners.put(derivedDelegate.getSignificantKey(key), listener);
}
- void addedToSourceNamespace(final NamespaceBehaviour.NamespaceStorageNode storage, final DK key, final V value) {
+ void addedToSourceNamespace(final NamespaceBehaviour.NamespaceStorageNode storage, final D key, final V value) {
notifyListeners(storage, listeners.get(key).iterator(), value);
}
break;
case DELETE:
performDeviateDelete(sourceNodeStmtCtx, targetNodeStmtCtx);
+ break;
+ default:
+ throw new IllegalStateException("Unsupported deviate " + deviateKind);
}
}
return identifier;
}
+ @SuppressWarnings("checkstyle:illegalCatch")
static SchemaNodeIdentifier nodeIdentifierFromPath(final StmtContext<?, ?, ?> ctx, final String path) {
// FIXME: is the path trimming really necessary??
final List<QName> qNames = new ArrayList<>();
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
"shared-schema-repo-multiple-rev-import-test");
- final SettableSchemaProvider<ASTSchemaSource> foo = getSourceProvider("/rfc7950/bug6875/yang1-1/foo.yang");
- final SettableSchemaProvider<ASTSchemaSource> bar1 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
- final SettableSchemaProvider<ASTSchemaSource> bar2 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
- final SettableSchemaProvider<ASTSchemaSource> bar3 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
+ final SettableSchemaProvider<ASTSchemaSource> foo = getSourceProvider(
+ "/rfc7950/bug6875/yang1-1/foo.yang");
+ final SettableSchemaProvider<ASTSchemaSource> bar1 = getSourceProvider(
+ "/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
+ final SettableSchemaProvider<ASTSchemaSource> bar2 = getSourceProvider(
+ "/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
+ final SettableSchemaProvider<ASTSchemaSource> bar3 = getSourceProvider(
+ "/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
setAndRegister(sharedSchemaRepository, foo);
setAndRegister(sharedSchemaRepository, bar1);
final SchemaContext context = schemaContextFuture.get();
assertEquals(context.getModules().size(), 4);
- assertTrue(findNode(context, ImmutableList.of(foo("root"), foo("my-container-1"))) instanceof ContainerSchemaNode);
- assertTrue(findNode(context, ImmutableList.of(foo("root"), foo("my-container-2"))) instanceof ContainerSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(foo("root"), foo("my-container-1")))
+ instanceof ContainerSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(foo("root"), foo("my-container-2")))
+ instanceof ContainerSchemaNode);
- assertTrue(findNode(context, ImmutableList.of(bar3("root"), foo("my-container-1"))) instanceof ContainerSchemaNode);
- assertTrue(findNode(context, ImmutableList.of(bar3("root"), foo("my-container-2"))) instanceof ContainerSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(bar3("root"), foo("my-container-1")))
+ instanceof ContainerSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(bar3("root"), foo("my-container-2")))
+ instanceof ContainerSchemaNode);
assertNull(findNode(context, ImmutableList.of(bar2("root"), foo("my-container-1"))));
assertNull(findNode(context, ImmutableList.of(bar2("root"), foo("my-container-2"))));
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
"shared-schema-repo-multiple-rev-import-test");
- final SettableSchemaProvider<ASTSchemaSource> foo = getSourceProvider("/rfc7950/bug6875/yang1-0/foo.yang");
- final SettableSchemaProvider<ASTSchemaSource> bar1 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
- final SettableSchemaProvider<ASTSchemaSource> bar2 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
+ final SettableSchemaProvider<ASTSchemaSource> foo = getSourceProvider(
+ "/rfc7950/bug6875/yang1-0/foo.yang");
+ final SettableSchemaProvider<ASTSchemaSource> bar1 = getSourceProvider(
+ "/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
+ final SettableSchemaProvider<ASTSchemaSource> bar2 = getSourceProvider(
+ "/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
setAndRegister(sharedSchemaRepository, foo);
setAndRegister(sharedSchemaRepository, bar1);
ASTSchemaSource.class);
}
- private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
- return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
+ private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
+ return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
}
private static QName foo(final String localName) {
private final T schemaSourceRepresentation;
private final PotentialSchemaSource<T> potentialSchemaSource;
- SettableSchemaProvider(final T schemaSourceRepresentation, final SourceIdentifier sourceIdentifier, final Class<T> representation, final int cost) {
+ SettableSchemaProvider(final T schemaSourceRepresentation, final SourceIdentifier sourceIdentifier,
+ final Class<T> representation, final int cost) {
this.schemaSourceRepresentation = schemaSourceRepresentation;
this.potentialSchemaSource = PotentialSchemaSource.create(sourceIdentifier, representation, cost);
}
- public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createRemote(final T schemaSourceRepresentation, final Class<T> representation) {
- return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(), representation, PotentialSchemaSource.Costs.REMOTE_IO.getValue());
+ public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createRemote(
+ final T schemaSourceRepresentation, final Class<T> representation) {
+ return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(),
+ representation, PotentialSchemaSource.Costs.REMOTE_IO.getValue());
}
- public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createImmediate(final T schemaSourceRepresentation, final Class<T> representation) {
- return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(), representation, PotentialSchemaSource.Costs.IMMEDIATE.getValue());
+ public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createImmediate(
+ final T schemaSourceRepresentation, final Class<T> representation) {
+ return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(),
+ representation, PotentialSchemaSource.Costs.IMMEDIATE.getValue());
}
@Override
public void setResult() {
future.set(schemaSourceRepresentation);
}
+
public void setException(final Throwable ex) {
future.setException(ex);
}
@Test
public void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
- final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
+ final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository,
+ filter);
final ListenableFuture<SchemaContext> schemaContext =
sharedSchemaContextFactory.createSchemaContext(Arrays.asList(s1, s1, s2));
assertNotNull(schemaContext.get());
repository.registerSchemaSource(provider, PotentialSchemaSource.create(
sIdWithoutRevision, ASTSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
- final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
+ final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository,
+ filter);
final ListenableFuture<SchemaContext> schemaContext =
sharedSchemaContextFactory.createSchemaContext(Arrays.asList(sIdWithoutRevision, provider.getId()));
assertNotNull(schemaContext.get());
"/ietf/network-topology@2013-10-21.yang");
remoteTopologyYang.register(sharedSchemaRepository);
remoteTopologyYang.setResult();
- final SettableSchemaProvider<ASTSchemaSource> remoteModuleNoRevYang = getImmediateYangSourceProviderFromResource(
- "/no-revision/module-without-revision.yang");
+ final SettableSchemaProvider<ASTSchemaSource> remoteModuleNoRevYang =
+ getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
remoteModuleNoRevYang.register(sharedSchemaRepository);
final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("running".getBytes(StandardCharsets.UTF_8));
}
- }), PotentialSchemaSource.create(runningId, YangTextSchemaSource.class,
- PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
+ }), PotentialSchemaSource.create(runningId, YangTextSchemaSource.class,
+ PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
final TextToASTTransformer transformer = TextToASTTransformer.create(sharedSchemaRepository,
sharedSchemaRepository);
}
@Override
- public void onFailure(@Nonnull final Throwable t) {
+ public void onFailure(@Nonnull final Throwable cause) {
// Creation of schema context fails, since we do not provide regular sources, but we just want
// to check cache
final List<File> cachedSchemas = Arrays.asList(storageDir.listFiles());
final PatternConstraint pattern = getPatternConstraintOf(context, "leaf-with-pattern");
final String rawRegex = pattern.getRawRegularExpression();
- final String expectedYangRegex = "$0$.*|$1$[a-zA-Z0-9./]{1,8}$[a-zA-Z0-9./]{22}|$5$(rounds=\\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{43}|$6$(rounds=\\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{86}";
+ final String expectedYangRegex = "$0$.*|$1$[a-zA-Z0-9./]{1,8}$[a-zA-Z0-9./]{22}|$5$(rounds=\\d+$)?"
+ + "[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{43}|$6$(rounds=\\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{86}";
assertEquals(expectedYangRegex, rawRegex);
final String javaRegexFromYang = pattern.getRegularExpression();
- final String expectedJavaRegex = "^\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86}$";
+ final String expectedJavaRegex = "^\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$"
+ + "(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?"
+ + "[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86}$";
assertEquals(expectedJavaRegex, javaRegexFromYang);
- final String value = "$6$AnrKGc0V$B/0/A.pWg4HrrA6YiEJOtFGibQ9Fmm5.4rI/00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
+ final String value = "$6$AnrKGc0V$B/0/A.pWg4HrrA6YiEJOtFGibQ9Fmm5.4rI/"
+ + "00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
testPattern(javaRegexFromYang, ImmutableList.of(value), ImmutableList.of());
}
}
}
- private static String javaRegexFromXSD(final String xsdRegex) {
- return RegexUtils.getJavaRegexFromXSD(xsdRegex);
+ private static void testPattern(final String xsdRegex, final String unanchoredJavaRegex) {
+ testPattern(xsdRegex, '^' + unanchoredJavaRegex + '$', ImmutableList.of(), ImmutableList.of());
}
private static boolean testMatch(final String javaRegex, final String value) {
return value.matches(javaRegex);
}
- private static void testPattern(final String xsdRegex, final String unanchoredJavaRegex) {
- testPattern(xsdRegex, '^' + unanchoredJavaRegex + '$', ImmutableList.of(), ImmutableList.of());
+ private static String javaRegexFromXSD(final String xsdRegex) {
+ return RegexUtils.getJavaRegexFromXSD(xsdRegex);
}
private static PatternConstraint getPatternConstraintOf(final SchemaContext context, final String leafName) {
return QName.create(FOO_NS, FOO_REV, localName);
}
- private static void testInvalidPattern(final String xsdRegex, final String expectedMessage) throws UnsupportedEncodingException {
+ @SuppressWarnings("checkstyle:regexpSinglelineJava")
+ private static void testInvalidPattern(final String xsdRegex, final String expectedMessage)
+ throws UnsupportedEncodingException {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output, true, "UTF-8"));
StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo-invalid.yang");
fail("Test should fail due to invalid Yang 1.1");
} catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("Action (foo-namespace?revision=2016-12-13)" +
- "action-in-grouping is defined within a notification, rpc or another action"));
+ assertTrue(e.getCause().getMessage().startsWith("Action (foo-namespace?revision=2016-12-13)"
+ + "action-in-grouping is defined within a notification, rpc or another action"));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Action (bar-namespace?revision=2016-12-13)my-action is defined within a list" +
- " that has no key statement"));
+ "Action (bar-namespace?revision=2016-12-13)my-action is defined within a list"
+ + " that has no key statement"));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Action (baz-namespace?revision=2016-12-13)action-in-grouping is defined within a " +
- "case statement"));
+ "Action (baz-namespace?revision=2016-12-13)action-in-grouping is defined within a "
+ + "case statement"));
}
}
ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo"));
assertSchemaContextFor(ImmutableSet.of("foo", "bar", "baz", "imp:bar"),
ImmutableSet.of("my-container-1", "my-container-2", "my-container-3", "foo", "imp-bar"));
- assertSchemaContextFor(ImmutableSet.of("foo", "baz", "imp:bar"), ImmutableSet.of("foo", "imp-bar", "imp-bar-2"));
+ assertSchemaContextFor(ImmutableSet.of("foo", "baz", "imp:bar"),
+ ImmutableSet.of("foo", "imp-bar", "imp-bar-2"));
}
private static void assertSchemaContextFor(final Set<String> supportedFeatures,
private static SchemaNode findNode(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, FOO_REV, localName));
return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
}
private static SchemaNode findNode(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, FOO_REV, localName));
return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
}
public class Bug6874Test {
- private static final StatementStreamSource ROOT_MODULE = sourceForResource
- ("/rfc7950/include-import-stmt-test/valid-11/root-module.yang");
- private static final StatementStreamSource CHILD_MODULE = sourceForResource
- ("/rfc7950/include-import-stmt-test/valid-11/child-module.yang");
- private static final StatementStreamSource CHILD_MODULE_1 = sourceForResource
- ("/rfc7950/include-import-stmt-test/valid-11/child-module-1.yang");
- private static final StatementStreamSource IMPORTED_MODULE = sourceForResource
- ("/rfc7950/include-import-stmt-test/valid-11/imported-module.yang");
+ private static final StatementStreamSource ROOT_MODULE = sourceForResource(
+ "/rfc7950/include-import-stmt-test/valid-11/root-module.yang");
+ private static final StatementStreamSource CHILD_MODULE = sourceForResource(
+ "/rfc7950/include-import-stmt-test/valid-11/child-module.yang");
+ private static final StatementStreamSource CHILD_MODULE_1 = sourceForResource(
+ "/rfc7950/include-import-stmt-test/valid-11/child-module-1.yang");
+ private static final StatementStreamSource IMPORTED_MODULE = sourceForResource(
+ "/rfc7950/include-import-stmt-test/valid-11/imported-module.yang");
@Test
public void valid11Test() throws Exception {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/include-import-stmt-test/valid-11");
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
+ "/rfc7950/include-import-stmt-test/valid-11");
assertNotNull(schemaContext);
// Test for valid include statement
reactor.addSources(ROOT_MODULE, CHILD_MODULE, CHILD_MODULE_1, IMPORTED_MODULE);
reactor.build().getRootStatements().forEach(declaredStmt -> {
- if(declaredStmt instanceof ModuleStatementImpl) {
+ if (declaredStmt instanceof ModuleStatementImpl) {
declaredStmt.declaredSubstatements().forEach(subStmt -> {
- if (subStmt instanceof IncludeStatementImpl &&
- subStmt.rawArgument().equals("child-module")) {
+ if (subStmt instanceof IncludeStatementImpl
+ && subStmt.rawArgument().equals("child-module")) {
subStmt.declaredSubstatements().forEach(Bug6874Test::verifyDescAndRef);
}
});
}
@SuppressWarnings("rawtypes")
- private static void verifyDescAndRef (final DeclaredStatement stmt) {
+ private static void verifyDescAndRef(final DeclaredStatement stmt) {
if (stmt instanceof DescriptionStatementImpl) {
assertEquals("Yang 1.1: Allow description and reference in include and import.",
((DescriptionStatementImpl) stmt).argument());
assertNull(findNode(context, ImmutableList.of(bar("augment-target"), foo("mandatory-leaf"))));
}
- private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
- return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
+ private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
+ return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
}
private static QName foo(final String localName) {
public class Bug6878Test {
@Test
+ @SuppressWarnings("checkstyle:regexpSinglelineJava")
public void testParsingXPathWithYang11Functions() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
}
@Test
+ @SuppressWarnings("checkstyle:regexpSinglelineJava")
public void shouldLogInvalidYang10XPath() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
}
@Test
+ @SuppressWarnings("checkstyle:regexpSinglelineJava")
public void shouldLogInvalidYang10XPath2() throws Exception {
final PrintStream stdout = System.out;
final ByteArrayOutputStream output = new ByteArrayOutputStream();
private static AnyDataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, FOO_REV, localName));
final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(qNames, true));
assertTrue(findDataSchemaNode instanceof AnyDataSchemaNode);
instanceof ContainerSchemaNode);
}
- private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
- return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
+ private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
+ return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
}
private static QName foo(final String localName) {
@Test
public void invalidListLeafKeyTest1() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in " +
- "(incorrect-list-keys-test?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
+ + "(incorrect-list-keys-test?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test.yang", exceptionMessage);
}
@Test
public void invalidListLeafKeyTest2() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in " +
- "(incorrect-list-keys-test1?revision=2017-02-06)b leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ + "(incorrect-list-keys-test1?revision=2017-02-06)b leaf statement which is specified as a list key.";
testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test1.yang", exceptionMessage);
}
@Test
public void invalidListUsesLeafKeyTest() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in " +
- "(incorrect-list-keys-test2?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ + "(incorrect-list-keys-test2?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test2.yang", exceptionMessage);
}
@Test
public void invalidListUsesLeafKeyTest1() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in " +
- "(incorrect-list-keys-test3?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)when statement is not allowed in "
+ + "(incorrect-list-keys-test3?revision=2017-02-06)a2 leaf statement which is specified as a list key.";
testForWhen("/rfc7950/list-keys-test/incorrect-list-keys-test3.yang", exceptionMessage);
}
@Test
public void invalidListUsesLeafKeyTest2() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in " +
- "(incorrect-list-keys-test4?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ + "(incorrect-list-keys-test4?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test4.yang", exceptionMessage);
}
@Test
public void invalidListUsesRefineLeafKeyTest() throws Exception {
- final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in " +
- "(incorrect-list-keys-test5?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
+ final String exceptionMessage = "(urn:ietf:params:xml:ns:yang:yin:1)if-feature statement is not allowed in "
+ + "(incorrect-list-keys-test5?revision=2017-02-06)a1 leaf statement which is specified as a list key.";
testForIfFeature("/rfc7950/list-keys-test/incorrect-list-keys-test5.yang", exceptionMessage);
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith("Enum 'purple' is not a subset of its base enumeration type" +
- " (foo?revision=2017-02-02)my-derived-enumeration-type."));
+ assertTrue(cause.getMessage().startsWith("Enum 'purple' is not a subset of its base enumeration type "
+ + "(foo?revision=2017-02-02)my-derived-enumeration-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidEnumDefinitionException);
- assertTrue(cause.getMessage().startsWith("Enum 'magenta' is not a subset of its base enumeration type" +
- " (foo?revision=2017-02-02)my-base-enumeration-type."));
+ assertTrue(cause.getMessage().startsWith("Enum 'magenta' is not a subset of its base enumeration type "
+ + "(foo?revision=2017-02-02)my-base-enumeration-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidEnumDefinitionException);
- assertTrue(cause.getMessage().startsWith("Value of enum 'red' must be the same as the value of " +
- "corresponding enum in the base enumeration type (foo?revision=2017-02-02)" +
- "my-derived-enumeration-type."));
+ assertTrue(cause.getMessage().startsWith("Value of enum 'red' must be the same as the value of "
+ + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+ + "my-derived-enumeration-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidEnumDefinitionException);
- assertTrue(cause.getMessage().startsWith("Value of enum 'black' must be the same as the value of " +
- "corresponding enum in the base enumeration type (foo?revision=2017-02-02)" +
- "my-base-enumeration-type."));
+ assertTrue(cause.getMessage().startsWith("Value of enum 'black' must be the same as the value of "
+ + "corresponding enum in the base enumeration type (foo?revision=2017-02-02)"
+ + "my-base-enumeration-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith("Restricted enumeration type is allowed only in YANG 1.1 version."));
+ assertTrue(cause.getMessage().startsWith(
+ "Restricted enumeration type is allowed only in YANG 1.1 version."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith("Restricted enumeration type is allowed only in YANG 1.1 version."));
+ assertTrue(cause.getMessage().startsWith(
+ "Restricted enumeration type is allowed only in YANG 1.1 version."));
}
}
bitsType = bitsType.getBaseType();
bits = bitsType.getBits();
assertEquals(4, bits.size());
- Bit bitA = createBit(createSchemaPath(true, bar.getQNameModule(), ImmutableList.of("my-base-bits-type",
+ final Bit bitA = createBit(createSchemaPath(true, bar.getQNameModule(), ImmutableList.of("my-base-bits-type",
"bits", "bit-a")), 1);
bitB = createBit(createSchemaPath(true, bar.getQNameModule(), ImmutableList.of("my-base-bits-type",
"bits", "bit-b")), 2);
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith("Bit 'bit-w' is not a subset of its base bits type" +
- " (bar?revision=2017-02-02)my-derived-bits-type."));
+ assertTrue(cause.getMessage().startsWith("Bit 'bit-w' is not a subset of its base bits type "
+ + "(bar?revision=2017-02-02)my-derived-bits-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidBitDefinitionException);
- assertTrue(cause.getMessage().startsWith("Bit 'bit-x' is not a subset of its base bits type" +
- " (bar?revision=2017-02-02)my-base-bits-type."));
+ assertTrue(cause.getMessage().startsWith("Bit 'bit-x' is not a subset of its base bits type "
+ + "(bar?revision=2017-02-02)my-base-bits-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidBitDefinitionException);
- assertTrue(cause.getMessage().startsWith("Position of bit 'bit-c' must be the same as the position of " +
- "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."));
+ assertTrue(cause.getMessage().startsWith("Position of bit 'bit-c' must be the same as the position of "
+ + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-derived-bits-type."));
}
}
} catch (final ReactorException ex) {
final Throwable cause = ex.getCause();
assertTrue(cause instanceof InvalidBitDefinitionException);
- assertTrue(cause.getMessage().startsWith("Position of bit 'bit-d' must be the same as the position of " +
- "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."));
+ assertTrue(cause.getMessage().startsWith("Position of bit 'bit-d' must be the same as the position of "
+ + "corresponding bit in the base bits type (bar?revision=2017-02-02)my-base-bits-type."));
}
}
}
}
- private static SchemaPath createSchemaPath(final boolean absolute, final QNameModule qNameModule,
+ private static SchemaPath createSchemaPath(final boolean absolute, final QNameModule qnameModule,
final Iterable<String> localNames) {
- final Iterable<QName> qNames = Iterables.transform(localNames,
- localName -> QName.create(qNameModule, localName));
- return SchemaPath.create(qNames, true);
+ return SchemaPath.create(Iterables.transform(localNames,
+ localName -> QName.create(qnameModule, localName)), true);
}
}
StmtTestUtils.parseYangSource("/rfc7950/notifications-in-data-nodes/foo-invalid.yang");
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
- assertTrue(e
- .getCause()
- .getMessage()
- .startsWith(
- "Notification (foo?revision=1970-01-01)grp-notification is defined within"
- + " an rpc, action, or another notification"));
+ assertTrue(e.getCause().getMessage().startsWith(
+ "Notification (foo?revision=1970-01-01)grp-notification is defined within an rpc, action, or another "
+ + "notification"));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Notification (bar-namespace?revision=2016-12-08)my-notification is defined within a list" +
- " that has no key statement"));
+ "Notification (bar-namespace?revision=2016-12-08)my-notification is defined within a list "
+ + "that has no key statement"));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Notification (baz-namespace?revision=2016-12-08)notification-in-grouping is defined within a " +
- "case statement"));
+ "Notification (baz-namespace?revision=2016-12-08)notification-in-grouping is defined within a case "
+ + "statement"));
}
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature statement."));
+ "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
+ + "statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature statement."));
+ "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
+ + "statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature statement."));
+ "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
+ + "statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Typedef '(foo?revision=1970-01-01)bits-typedef-2' has default value 'two' marked with an if-feature statement."));
+ "Typedef '(foo?revision=1970-01-01)bits-typedef-2' has default value 'two' marked with an "
+ + "if-feature statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)union-leaf' has default value 'two' marked with an if-feature statement."));
+ "Leaf '(foo?revision=1970-01-01)union-leaf' has default value 'two' marked with an if-feature "
+ + "statement."));
}
}
assertTrue(e.getCause().getMessage().startsWith("IF_FEATURE is not valid for BIT"));
}
}
-}
\ No newline at end of file
+}
import java.util.Set;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597");
assertNotNull(context);
- final Module foo = context.findModuleByName("foo",
- SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
+ final Module foo = context.findModuleByName("foo", QName.parseRevision("1970-01-01"));
assertNotNull(foo);
final Set<ModuleImport> imports = foo.getImports();
for (final ModuleImport moduleImport : imports) {
switch (moduleImport.getModuleName()) {
- case "bar":
- assertEquals(SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"), moduleImport.getRevision());
- assertEquals("bar-ref", moduleImport.getReference());
- assertEquals("bar-desc", moduleImport.getDescription());
- break;
- case "baz":
- assertEquals(SimpleDateFormatUtil.getRevisionFormat().parse("2010-10-10"), moduleImport.getRevision());
- assertEquals("baz-ref", moduleImport.getReference());
- assertEquals("baz-desc", moduleImport.getDescription());
- break;
- default:
- fail("Module 'foo' should only contains import of module 'bar' and 'baz'");
+ case "bar":
+ assertEquals(QName.parseRevision("1970-01-01"), moduleImport.getRevision());
+ assertEquals("bar-ref", moduleImport.getReference());
+ assertEquals("bar-desc", moduleImport.getDescription());
+ break;
+ case "baz":
+ assertEquals(QName.parseRevision("2010-10-10"), moduleImport.getRevision());
+ assertEquals("baz-ref", moduleImport.getReference());
+ assertEquals("baz-desc", moduleImport.getDescription());
+ break;
+ default:
+ fail("Module 'foo' should only contains import of module 'bar' and 'baz'");
}
}
}
Module imported = null;
for (final Module module : modules) {
switch (module.getName()) {
- case "root-module":
- root = module;
- break;
- case "imported-module":
- imported = module;
- break;
- default:
+ case "root-module":
+ root = module;
+ break;
+ case "imported-module":
+ imported = module;
+ break;
+ default:
}
StmtTestUtils.printReferences(module, false, "");
StmtTestUtils.printChilds(module.getChildNodes(), " ");
Module sub2 = null;
for (final Module rootSubmodule : rootSubmodules) {
switch (rootSubmodule.getName()) {
- case "submodule-1":
- sub1 = rootSubmodule;
- break;
- case "submodule-2":
- sub2 = rootSubmodule;
- break;
- default:
+ case "submodule-1":
+ sub1 = rootSubmodule;
+ break;
+ case "submodule-2":
+ sub2 = rootSubmodule;
+ break;
+ default:
}
}
Module sub1Submodule = null;
for (final Module submodule : sub1Submodules) {
switch (submodule.getName()) {
- case "submodule-to-submodule-1":
- sub1Submodule = submodule;
- break;
- default:
+ case "submodule-to-submodule-1":
+ sub1Submodule = submodule;
+ break;
+ default:
}
}
SimpleDateFormatUtil.DEFAULT_DATE_REV),
sub1Submodule.getQNameModule());
- final Collection<DataSchemaNode> sub1SubmoduleChildNodes = sub1Submodule
- .getChildNodes();
+ final Collection<DataSchemaNode> sub1SubmoduleChildNodes = sub1Submodule.getChildNodes();
assertNotNull(sub1SubmoduleChildNodes);
assertEquals(1, sub1SubmoduleChildNodes.size());
findModulesSubTest(result, root, imported);
getDataChildByNameSubTest(result, root);
-
}
private static void getDataChildByNameSubTest(final SchemaContext result, final Module root) {
assertFalse(root.equals(imported));
}
-
}