package org.opendaylight.yangtools.yang.parser.repo;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache;
-import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
-import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private volatile Object contextVersion = version;
private YangTextSchemaContextResolver(final SchemaRepository repository, final SchemaSourceRegistry registry) {
- this.repository = Preconditions.checkNotNull(repository);
- this.registry = Preconditions.checkNotNull(registry);
+ this.repository = requireNonNull(repository);
+ this.registry = requireNonNull(registry);
final TextToASTTransformer t = TextToASTTransformer.create(repository, registry);
transReg = registry.registerSchemaSourceListener(t);
* @throws IOException when the URL is not readable
* @throws SchemaSourceException When parsing encounters general error
*/
- public YangTextSchemaSourceRegistration registerSource(@Nonnull final YangTextSchemaSource source)
+ public @NonNull YangTextSchemaSourceRegistration registerSource(final @NonNull YangTextSchemaSource source)
throws SchemaSourceException, IOException, YangSyntaxErrorException {
checkArgument(source != null);
* @throws IOException when the URL is not readable
* @throws SchemaSourceException When parsing encounters general error
*/
- public YangTextSchemaSourceRegistration registerSource(@Nonnull final URL url) throws SchemaSourceException,
- IOException, YangSyntaxErrorException {
+ public @NonNull YangTextSchemaSourceRegistration registerSource(final @NonNull URL url)
+ throws SchemaSourceException, IOException, YangSyntaxErrorException {
checkArgument(url != null, "Supplied URL must not be null");
final String path = url.getPath();
});
}
- private static SourceIdentifier guessSourceIdentifier(final String fileName) {
+ private static SourceIdentifier guessSourceIdentifier(final @NonNull String fileName) {
try {
return YangTextSchemaSource.identifierFromFilename(fileName);
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
LOG.warn("Invalid file name format in '{}'", fileName, e);
return RevisionSourceIdentifier.create(fileName);
}
try {
sc = Optional.of(f.get());
break;
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted while assembling schema context", e);
- } catch (ExecutionException e) {
+ } catch (final InterruptedException e) {
+ throw new IllegalStateException("Interrupted while assembling schema context", e);
+ } catch (final ExecutionException e) {
LOG.info("Failed to fully assemble schema context for {}", sources, e);
final Throwable cause = e.getCause();
Verify.verify(cause instanceof SchemaResolutionException);
}
@Override
- public synchronized ListenableFuture<YangTextSchemaSource> getSource(
+ public synchronized FluentFuture<YangTextSchemaSource> getSource(
final SourceIdentifier sourceIdentifier) {
final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier);
LOG.debug("Lookup {} result {}", sourceIdentifier, ret);
if (ret.isEmpty()) {
- return Futures.immediateFailedFuture(new MissingSchemaSourceException(
- "URL for " + sourceIdentifier + " not registered", sourceIdentifier));
+ return immediateFailedFluentFuture(new MissingSchemaSourceException("URL for " + sourceIdentifier
+ + " not registered", sourceIdentifier));
}
- return Futures.immediateFuture(ret.iterator().next());
+ return immediateFluentFuture(ret.iterator().next());
}
/**
}
@Beta
+ @SuppressWarnings("checkstyle:avoidHidingCauseException")
public SchemaContext trySchemaContext(final StatementParserMode statementParserMode)
throws SchemaResolutionException {
final ListenableFuture<SchemaContext> future = repository
try {
return future.get();
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted while waiting for SchemaContext assembly", e);
- } catch (ExecutionException e) {
+ } catch (final InterruptedException e) {
+ throw new IllegalStateException("Interrupted while waiting for SchemaContext assembly", e);
+ } catch (final ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof SchemaResolutionException) {
throw (SchemaResolutionException) cause;