Migrate from JSR305 to JDT annotations, along with implentations.
Change-Id: I38c8c567a91c42e0c4387cfc3d7baf06cf495e2b
JIRA: YANGTOOLS-907
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<ByteSource> {
- private final ByteSource delegate;
+ private final @NonNull ByteSource delegate;
DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
super(identifier);
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
final class DelegatedYinTextSchemaSource extends YinTextSchemaSource implements Delegator<ByteSource> {
- private final ByteSource delegate;
+ private final @NonNull ByteSource delegate;
DelegatedYinTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
super(identifier);
import java.io.InputStream;
import java.net.URL;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
/**
@Beta
// FIXME: YANGTOOLS-849: 3.0.0: hide this class
public final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
- private final URL url;
+ private final @NonNull URL url;
ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url) {
super(identifier);
*/
package org.opendaylight.yangtools.yang.model.repo.api;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
/**
* A resource-backed {@link YangTextSchemaSource}.
*/
final class ResourceYinTextSchemaSource extends YinTextSchemaSource implements Delegator<URL> {
- private final URL url;
+ private final @NonNull URL url;
ResourceYinTextSchemaSource(final SourceIdentifier identifier, final URL url) {
super(identifier);
- this.url = Preconditions.checkNotNull(url);
+ this.url = requireNonNull(url);
}
@Override
import com.google.common.annotations.Beta;
import java.util.Optional;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.concepts.Immutable;
/**
- * Common interface for schema source representations.
+ * Common interface for schema source representations. A schema source is an atomic piece of the overall schema context.
+ * In YANG terms, a schema source is semantically equivalent to a single YANG text file, be it a module or a submodule.
*
* <p>
- * A schema source is an atomic piece of the overall schema context. In YANG terms,
- * a schema source is semantically equivalent to a single YANG text file, be it a
- * module or a submodule.
- *
- * <p>
- * A schema source can exist in various forms, which we call representations. Again,
- * in YANG terms, each representation is semantically equivalent, but from
- * implementation perspective certain operations on a schema source may require it
- * to be first transformed into a particular representation before they can be
- * applied. Such transformations are affected via instances of
- * SchemaSourceTransformation.
+ * A schema source can exist in various forms, which we call representations. Again, in YANG terms, each representation
+ * is semantically equivalent, but from implementation perspective certain operations on a schema source may require it
+ * to be first transformed into a particular representation before they can be applied. Such transformations are
+ * affected via instances of SchemaSourceTransformation.
*
* <p>
* Typical examples of a schema source representation include:
*
* @return The type of representation.
*/
- @Nonnull Class<? extends SchemaSourceRepresentation> getType();
+ @NonNull Class<? extends SchemaSourceRepresentation> getType();
/**
* Return the symbolic name, if available. This name has no semantic meaning beyond being useful for debugging
*/
package org.opendaylight.yangtools.yang.model.repo.api;
-import javax.annotation.Nonnull;
-
/**
* A YANG {@link SchemaSourceRepresentation}.
*/
public interface YangSchemaSourceRepresentation extends SchemaSourceRepresentation {
- /**
- * Return the concrete representation type.
- *
- * @return The type of representation.
- */
- @Nonnull
@Override
Class<? extends YangSchemaSourceRepresentation> getType();
}
import java.io.InputStream;
import java.net.URL;
import java.util.Map.Entry;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
/**
*/
@Beta
public abstract class YangTextSchemaSource extends ByteSource implements YangSchemaSourceRepresentation {
- private final SourceIdentifier identifier;
+ private final @NonNull SourceIdentifier identifier;
protected YangTextSchemaSource(final SourceIdentifier identifier) {
this.identifier = requireNonNull(identifier);
}
- public static SourceIdentifier identifierFromFilename(final String name) {
+ public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
checkArgument(name.endsWith(RFC6020_YANG_FILE_EXTENSION), "Filename %s does not end with '%s'",
RFC6020_YANG_FILE_EXTENSION, name);
* @param delegate Backing ByteSource instance
* @return A new YangTextSchemaSource
*/
- public static YangTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
+ public static @NonNull YangTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
final ByteSource delegate) {
return new DelegatedYangTextSchemaSource(identifier, delegate);
}
* @return A new YangTextSchemaSource
* @throws IllegalArgumentException if the file name has invalid format
*/
- public static YangTextSchemaSource delegateForByteSource(final String fileName, final ByteSource delegate) {
+ public static @NonNull YangTextSchemaSource delegateForByteSource(final String fileName,
+ final ByteSource delegate) {
return new DelegatedYangTextSchemaSource(identifierFromFilename(fileName), delegate);
}
* @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
* @throws NullPointerException if file is null
*/
- public static YangTextSchemaSource forFile(final File file) {
+ public static @NonNull YangTextSchemaSource forFile(final File file) {
checkArgument(file.isFile(), "Supplied file %s is not a file", file);
return new YangTextFileSchemaSource(identifierFromFilename(file.getName()), file);
}
* @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
*/
// FIXME: 3.0.0: YANGTOOLS-849: return YangTextSchemaSource
- public static ResourceYangTextSchemaSource forResource(final String resourceName) {
+ public static @NonNull ResourceYangTextSchemaSource forResource(final String resourceName) {
return forResource(YangTextSchemaSource.class, resourceName);
}
* @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
*/
// FIXME: 3.0.0: YANGTOOLS-849: return YangTextSchemaSource
- public static ResourceYangTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+ public static @NonNull ResourceYangTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
final SourceIdentifier identifier = identifierFromFilename(fileName);
final URL url = Resources.getResource(clazz, resourceName);
return identifier;
}
- @Nonnull
@Override
public Class<? extends YangTextSchemaSource> getType() {
return YangTextSchemaSource.class;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
-import javax.annotation.Nonnull;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.YangConstants;
* @param source W3C DOM source
* @return A new {@link YinDomSchemaSource} instance.
*/
- public static @Nonnull YinDomSchemaSource create(@Nonnull final SourceIdentifier identifier,
- final @Nonnull DOMSource source) {
+ public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier,
+ final @NonNull DOMSource source) {
final Node root = source.getNode().getFirstChild();
final String rootNs = root.getNamespaceURI();
* @param xmlSchemaSource Backing schema source
* @return A {@link YinDomSchemaSource} instance
*/
- @Nonnull public static YinDomSchemaSource lazyTransform(final YinXmlSchemaSource xmlSchemaSource) {
+ public static @NonNull YinDomSchemaSource lazyTransform(final YinXmlSchemaSource xmlSchemaSource) {
final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast : new Transforming(xmlSchemaSource);
}
* @return A {@link YinDomSchemaSource} instance
* @throws TransformerException when the provided source fails to transform
*/
- @Nonnull public static YinDomSchemaSource transform(final YinXmlSchemaSource xmlSchemaSource)
+ public static @NonNull YinDomSchemaSource transform(final YinXmlSchemaSource xmlSchemaSource)
throws TransformerException {
final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast :
}
@Override
- @Nonnull public abstract DOMSource getSource();
+ public abstract DOMSource getSource();
@Override
public final Class<? extends YinXmlSchemaSource> getType() {
*/
protected abstract ToStringHelper addToStringAttributes(ToStringHelper toStringHelper);
- static DOMSource transformSource(final Source source) throws TransformerException {
+ static @NonNull DOMSource transformSource(final Source source) throws TransformerException {
final DOMResult result = new DOMResult();
TRANSFORMER_FACTORY.newTransformer().transform(source, result);
return new DOMSource(result.getNode(), result.getSystemId());
}
- private static YinDomSchemaSource castSchemaSource(final YinXmlSchemaSource xmlSchemaSource) {
+ private static @Nullable YinDomSchemaSource castSchemaSource(final YinXmlSchemaSource xmlSchemaSource) {
if (xmlSchemaSource instanceof YinDomSchemaSource) {
return (YinDomSchemaSource) xmlSchemaSource;
}
}
private static final class Simple extends YinDomSchemaSource {
- private final SourceIdentifier identifier;
- private final DOMSource source;
+ private final @NonNull SourceIdentifier identifier;
+ private final @NonNull DOMSource source;
- Simple(@Nonnull final SourceIdentifier identifier, @Nonnull final DOMSource source) {
+ Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source) {
this.identifier = requireNonNull(identifier);
this.source = requireNonNull(source);
}
- @Nonnull
@Override
public DOMSource getSource() {
return source;
this.xmlSchemaSource = requireNonNull(xmlSchemaSource);
}
- @Nonnull
@Override
public DOMSource getSource() {
DOMSource ret = source;
*/
package org.opendaylight.yangtools.yang.model.repo.api;
-import javax.annotation.Nonnull;
-
/**
* A YIN {@link SchemaSourceRepresentation}.
*/
public interface YinSchemaSourceRepresentation extends SchemaSourceRepresentation {
- /**
- * Return the concrete representation type.
- *
- * @return The type of representation.
- */
- @Nonnull
@Override
Class<? extends YinSchemaSourceRepresentation> getType();
}
*/
package org.opendaylight.yangtools.yang.model.repo.api;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
/**
final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<File> {
private final File file;
- YinTextFileSchemaSource(final SourceIdentifier identifier, final File file) {
+ YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull File file) {
super(identifier);
- this.file = Preconditions.checkNotNull(file);
+ this.file = requireNonNull(file);
}
@Override
import com.google.common.io.Resources;
import java.io.File;
import java.io.InputStream;
-import java.net.URL;
import java.util.Map.Entry;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.common.YangNames;
private static final Logger LOG = LoggerFactory.getLogger(YinTextSchemaSource.class);
private static final String XML_EXTENSION = ".xml";
- private final SourceIdentifier identifier;
+ private final @NonNull SourceIdentifier identifier;
protected YinTextSchemaSource(final SourceIdentifier identifier) {
this.identifier = requireNonNull(identifier);
}
- public static SourceIdentifier identifierFromFilename(final String name) {
+ public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
final String baseName;
if (name.endsWith(YangConstants.RFC6020_YIN_FILE_EXTENSION)) {
baseName = name.substring(0, name.length() - YangConstants.RFC6020_YIN_FILE_EXTENSION.length());
return identifier;
}
- @Nonnull
@Override
public Class<? extends YinTextSchemaSource> getType() {
return YinTextSchemaSource.class;
* @param toStringHelper ToStringHelper onto the attributes can be added
* @return ToStringHelper supplied as input argument.
*/
- protected abstract ToStringHelper addToStringAttributes(ToStringHelper toStringHelper);
+ protected abstract ToStringHelper addToStringAttributes(@NonNull ToStringHelper toStringHelper);
/**
* Create a new YinTextSchemaSource with a specific source identifier and backed
* @param delegate Backing ByteSource instance
* @return A new YinTextSchemaSource
*/
- public static YinTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
+ public static @NonNull YinTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
final ByteSource delegate) {
return new DelegatedYinTextSchemaSource(identifier, delegate);
}
- public static YinTextSchemaSource forFile(final File file) {
+ public static @NonNull YinTextSchemaSource forFile(final File file) {
checkArgument(file.isFile(), "Supplied file %s is not a file", file);
return new YinTextFileSchemaSource(identifierFromFilename(file.getName()), file);
}
- public static YinTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+ public static @NonNull YinTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
- final SourceIdentifier identifier = identifierFromFilename(fileName);
- final URL url = Resources.getResource(clazz, resourceName);
- return new ResourceYinTextSchemaSource(identifier, url);
+ return new ResourceYinTextSchemaSource(identifierFromFilename(fileName),
+ Resources.getResource(clazz, resourceName));
}
}
package org.opendaylight.yangtools.yang.model.repo.api;
import com.google.common.annotations.Beta;
-import javax.annotation.Nonnull;
import javax.xml.transform.Source;
+import org.eclipse.jdt.annotation.NonNull;
/**
* YIN text schema source representation. Exposes an RFC6020 or RFC7950 XML representation as an XML {@link Source}.
*/
@Beta
public interface YinXmlSchemaSource extends YinSchemaSourceRepresentation {
- @Nonnull
@Override
Class<? extends YinXmlSchemaSource> getType();
*
* @return An XML {@link Source} instance.
*/
- @Nonnull Source getSource();
+ @NonNull Source getSource();
}
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import java.util.Optional;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.antlr.v4.runtime.ParserRuleContext;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
*/
@Beta
public final class ASTSchemaSource implements SchemaSourceRepresentation {
- private final YangModelDependencyInfo depInfo;
- private final SemVerSourceIdentifier semVerId;
- private final SourceIdentifier identifier;
- private final ParserRuleContext tree;
- private final String symbolicName;
-
- private ASTSchemaSource(@Nonnull final SourceIdentifier identifier, @Nonnull final SemVerSourceIdentifier semVerId,
- @Nonnull final ParserRuleContext tree, @Nonnull final YangModelDependencyInfo depInfo,
+ private final @NonNull YangModelDependencyInfo depInfo;
+ private final @NonNull SemVerSourceIdentifier semVerId;
+ private final @NonNull SourceIdentifier identifier;
+ private final @NonNull ParserRuleContext tree;
+ private final @Nullable String symbolicName;
+
+ private ASTSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull SemVerSourceIdentifier semVerId,
+ final @NonNull ParserRuleContext tree, final @NonNull YangModelDependencyInfo depInfo,
@Nullable final String symbolicName) {
this.depInfo = requireNonNull(depInfo);
this.tree = requireNonNull(tree);
* @throws YangSyntaxErrorException
* if we fail to extract dependency information.
*/
- static ASTSchemaSource create(@Nonnull final SourceIdentifier identifier,
- @Nullable final String symbolicName, @Nonnull final ParserRuleContext tree)
+ static @NonNull ASTSchemaSource create(final @NonNull SourceIdentifier identifier,
+ final @Nullable String symbolicName, final @NonNull ParserRuleContext tree)
throws YangSyntaxErrorException {
final YangModelDependencyInfo depInfo = YangModelDependencyInfo.fromAST(identifier, tree);
final SourceIdentifier id = getSourceId(depInfo);
return new ASTSchemaSource(id, semVerId, tree, depInfo, symbolicName);
}
-
@Override
public SourceIdentifier getIdentifier() {
return identifier;
return Optional.ofNullable(symbolicName);
}
- public SemVerSourceIdentifier getSemVerIdentifier() {
+ public @NonNull SemVerSourceIdentifier getSemVerIdentifier() {
return semVerId;
}
- @Nonnull
@Override
public Class<? extends SchemaSourceRepresentation> getType() {
return ASTSchemaSource.class;
*
* @return Underlying AST.
*/
- @Nonnull public ParserRuleContext getAST() {
+ public @NonNull ParserRuleContext getAST() {
return tree;
}
*/
// FIXME: this method should be extracted into a public interface in the model.api.repo class, relying solely
// on model.api types.
- @Nonnull public YangModelDependencyInfo getDependencyInformation() {
+ public @NonNull YangModelDependencyInfo getDependencyInformation() {
return depInfo;
}
return MoreObjects.toStringHelper(this).add("identifier", identifier).toString();
}
- private static SourceIdentifier getSourceId(final YangModelDependencyInfo depInfo) {
+ private static @NonNull SourceIdentifier getSourceId(final @NonNull YangModelDependencyInfo depInfo) {
final String name = depInfo.getName();
return depInfo.getFormattedRevision() == null ? RevisionSourceIdentifier.create(name)
: RevisionSourceIdentifier.create(name, depInfo.getRevision());
}
- private static SemVerSourceIdentifier getSemVerSourceId(final YangModelDependencyInfo depInfo) {
+ private static @NonNull SemVerSourceIdentifier getSemVerSourceId(final @NonNull YangModelDependencyInfo depInfo) {
return depInfo.getFormattedRevision() == null
? SemVerSourceIdentifier.create(depInfo.getName(), depInfo.getSemanticVersion().orElse(null))
: SemVerSourceIdentifier.create(depInfo.getName(), depInfo.getRevision(),
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nullable;
import org.antlr.v4.runtime.ParserRuleContext;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.ArgumentContext;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext;
import org.opendaylight.yangtools.concepts.SemVer;
* @return {@link YangModelDependencyInfo}
* @throws YangSyntaxErrorException If the AST is not a valid YANG module/submodule
*/
- static YangModelDependencyInfo fromAST(final SourceIdentifier source, final ParserRuleContext tree)
+ static @NonNull YangModelDependencyInfo fromAST(final SourceIdentifier source, final ParserRuleContext tree)
throws YangSyntaxErrorException {
if (tree instanceof StatementContext) {
throw new YangSyntaxErrorException(source, 0, 0, "Unknown YANG text type");
}
- private static YangModelDependencyInfo parseAST(final StatementContext rootStatement,
+ private static @NonNull YangModelDependencyInfo parseAST(final StatementContext rootStatement,
final SourceIdentifier source) {
final String keyWordText = rootStatement.keyword().getText();
if (MODULE.equals(keyWordText)) {
return parseAST((StatementContext) ast, source.getIdentifier());
}
- private static YangModelDependencyInfo parseModuleContext(final StatementContext module,
+ private static @NonNull YangModelDependencyInfo parseModuleContext(final StatementContext module,
final SourceIdentifier source) {
final String name = safeStringArgument(source, module, "module name");
final String latestRevision = getLatestRevision(module, source);
return latestRevision;
}
- private static YangModelDependencyInfo parseSubmoduleContext(final StatementContext submodule,
+ private static @NonNull YangModelDependencyInfo parseSubmoduleContext(final StatementContext submodule,
final SourceIdentifier source) {
final String name = safeStringArgument(source, submodule, "submodule name");
final String belongsTo = parseBelongsTo(submodule, source);
private final SemVer semVer;
private final String name;
- ModuleImportImpl(final String moduleName, final Revision revision) {
+ ModuleImportImpl(final @NonNull String moduleName, final @Nullable Revision revision) {
this(moduleName, revision, null);
}
- ModuleImportImpl(final String moduleName, @Nullable final Revision revision, @Nullable final SemVer semVer) {
+ ModuleImportImpl(final @NonNull String moduleName, final @Nullable Revision revision,
+ final @Nullable SemVer semVer) {
this.name = requireNonNull(moduleName, "Module name must not be null.");
this.revision = revision;
this.semVer = semVer;