This is straightforward change, just switch over annotations and
fixup some of the warnings in the corresponding test.
JIRA: YANGTOOLS-907
Change-Id: I9d757381d71af205f3ed4a41778a2027a66d3fdb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
public class InferenceException extends SourceException {
private static final long serialVersionUID = 1L;
public class InferenceException extends SourceException {
private static final long serialVersionUID = 1L;
- public InferenceException(@Nonnull final String message, @Nonnull final StatementSourceReference source,
+ public InferenceException(final @NonNull String message, final @NonNull StatementSourceReference source,
final Throwable cause) {
super(message, source, cause);
}
final Throwable cause) {
super(message, source, cause);
}
- public InferenceException(@Nonnull final String message, @Nonnull final StatementSourceReference source) {
+ public InferenceException(final @NonNull String message, final @NonNull StatementSourceReference source) {
super(message, source);
}
super(message, source);
}
- public InferenceException(@Nonnull final StatementSourceReference source, @Nonnull final String format,
+ public InferenceException(final @NonNull StatementSourceReference source, final @NonNull String format,
final Object... args) {
this(String.format(format, args), source);
}
final Object... args) {
this(String.format(format, args), source);
}
* @param args Format string arguments, according to {@link String#format(String, Object...)}
* @throws InferenceException if the expression evaluates to true.
*/
* @param args Format string arguments, according to {@link String#format(String, Object...)}
* @throws InferenceException if the expression evaluates to true.
*/
- public static void throwIf(final boolean expression, @Nonnull final StatementSourceReference source,
- @Nonnull final String format, final Object... args) {
+ public static void throwIf(final boolean expression, final @NonNull StatementSourceReference source,
+ final @NonNull String format, final Object... args) {
if (expression) {
throw new InferenceException(source, format, args);
}
if (expression) {
throw new InferenceException(source, format, args);
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
public class InvalidSubstatementException extends SourceException {
private static final long serialVersionUID = 1L;
public class InvalidSubstatementException extends SourceException {
private static final long serialVersionUID = 1L;
- public InvalidSubstatementException(@Nonnull final String message,
- @Nonnull final StatementSourceReference source) {
+ public InvalidSubstatementException(final @NonNull String message, final @NonNull StatementSourceReference source) {
super(message, source);
}
super(message, source);
}
- public InvalidSubstatementException(@Nonnull final String message, @Nonnull final StatementSourceReference source,
+ public InvalidSubstatementException(final @NonNull String message, final @NonNull StatementSourceReference source,
final Throwable cause) {
super(message, source, cause);
}
final Throwable cause) {
super(message, source, cause);
}
- public InvalidSubstatementException(@Nonnull final StatementSourceReference source, @Nonnull final String format,
+ public InvalidSubstatementException(final @NonNull StatementSourceReference source, final @NonNull String format,
final Object... args) {
this(String.format(format, args), source);
}
final Object... args) {
this(String.format(format, args), source);
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
public class MissingSubstatementException extends SourceException {
private static final long serialVersionUID = 1L;
public class MissingSubstatementException extends SourceException {
private static final long serialVersionUID = 1L;
- public MissingSubstatementException(@Nonnull final String message,
- @Nonnull final StatementSourceReference source) {
+ public MissingSubstatementException(final @NonNull String message, final @NonNull StatementSourceReference source) {
super(message, source);
}
super(message, source);
}
- public MissingSubstatementException(@Nonnull final String message, @Nonnull final StatementSourceReference source,
+ public MissingSubstatementException(final @NonNull String message, final @NonNull StatementSourceReference source,
final Throwable cause) {
super(message, source, cause);
}
final Throwable cause) {
super(message, source, cause);
}
- public MissingSubstatementException(@Nonnull final StatementSourceReference source, @Nonnull final String format,
+ public MissingSubstatementException(final @NonNull StatementSourceReference source, final @NonNull String format,
final Object... args) {
this(String.format(format, args), source);
}
final Object... args) {
this(String.format(format, args), source);
}
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
/**
* Thrown to indicate error in YANG model source.
/**
* Thrown to indicate error in YANG model source.
private static final long serialVersionUID = 1L;
@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Interface-specified member")
private static final long serialVersionUID = 1L;
@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Interface-specified member")
- private final StatementSourceReference sourceRef;
+ private final @NonNull StatementSourceReference sourceRef;
/**
* Create a new instance with the specified message and source. The message will be appended with
/**
* Create a new instance with the specified message and source. The message will be appended with
* @param message Context message
* @param source Statement source
*/
* @param message Context message
* @param source Statement source
*/
- public SourceException(@Nonnull final String message, @Nonnull final StatementSourceReference source) {
+ public SourceException(final @NonNull String message, final @NonNull StatementSourceReference source) {
super(createMessage(message, source));
sourceRef = source;
}
super(createMessage(message, source));
sourceRef = source;
}
* @param source Statement source
* @param cause Underlying cause of this exception
*/
* @param source Statement source
* @param cause Underlying cause of this exception
*/
- public SourceException(@Nonnull final String message, @Nonnull final StatementSourceReference source,
+ public SourceException(final @NonNull String message, final @NonNull StatementSourceReference source,
final Throwable cause) {
super(createMessage(message, source), cause);
sourceRef = source;
final Throwable cause) {
super(createMessage(message, source), cause);
sourceRef = source;
* @param format Format string, according to {@link String#format(String, Object...)}.
* @param args Format string arguments, according to {@link String#format(String, Object...)}
*/
* @param format Format string, according to {@link String#format(String, Object...)}.
* @param args Format string arguments, according to {@link String#format(String, Object...)}
*/
- public SourceException(@Nonnull final StatementSourceReference source, @Nonnull final String format,
+ public SourceException(final @NonNull StatementSourceReference source, final @NonNull String format,
final Object... args) {
this(String.format(format, args), source);
}
final Object... args) {
this(String.format(format, args), source);
}
* @param format Format string, according to {@link String#format(String, Object...)}.
* @param args Format string arguments, according to {@link String#format(String, Object...)}
*/
* @param format Format string, according to {@link String#format(String, Object...)}.
* @param args Format string arguments, according to {@link String#format(String, Object...)}
*/
- public SourceException(@Nonnull final StatementSourceReference source, final Throwable cause,
- @Nonnull final String format, final Object... args) {
+ public SourceException(final @NonNull StatementSourceReference source, final Throwable cause,
+ final @NonNull String format, final Object... args) {
this(String.format(format, args), source, cause);
}
this(String.format(format, args), source, cause);
}
*
* @return Source reference
*/
*
* @return Source reference
*/
- public @Nonnull StatementSourceReference getSourceReference() {
+ public @NonNull StatementSourceReference getSourceReference() {
* @param args Format string arguments, according to {@link String#format(String, Object...)}
* @throws SourceException if the expression evaluates to true.
*/
* @param args Format string arguments, according to {@link String#format(String, Object...)}
* @throws SourceException if the expression evaluates to true.
*/
- public static void throwIf(final boolean expression, @Nonnull final StatementSourceReference source,
- @Nonnull final String format, final Object... args) {
+ public static void throwIf(final boolean expression, final @NonNull StatementSourceReference source,
+ final @NonNull String format, final Object... args) {
if (expression) {
throw new SourceException(source, format, args);
}
if (expression) {
throw new SourceException(source, format, args);
}
* @return Object if it is not null
* @throws SourceException if object is null
*/
* @return Object if it is not null
* @throws SourceException if object is null
*/
- @Nonnull public static <T> T throwIfNull(@Nullable final T obj, @Nonnull final StatementSourceReference source,
- @Nonnull final String format, final Object... args) {
- throwIf(obj == null, source, format, args);
+ public static <T> @NonNull T throwIfNull(final @Nullable T obj, final @NonNull StatementSourceReference source,
+ final @NonNull String format, final Object... args) {
+ if (obj == null) {
+ throw new SourceException(source, format, args);
+ }
* @return Object unwrapped from the opt optional
* @throws SourceException if the optional is not present
*/
* @return Object unwrapped from the opt optional
* @throws SourceException if the optional is not present
*/
- @Nonnull public static <T> T unwrap(final Optional<T> opt, @Nonnull final StatementSourceReference source,
- @Nonnull final String format, final Object... args) {
+ public static <T> @NonNull T unwrap(final Optional<T> opt, final @NonNull StatementSourceReference source,
+ final @NonNull String format, final Object... args) {
throwIf(!opt.isPresent(), source, format, args);
return opt.get();
}
throwIf(!opt.isPresent(), source, format, args);
return opt.get();
}
- private static String createMessage(@Nonnull final String message, @Nonnull final StatementSourceReference source) {
- requireNonNull(message);
- requireNonNull(source);
-
- return message + " [at " + source + ']';
+ private static String createMessage(final @NonNull String message, final @NonNull StatementSourceReference source) {
+ return requireNonNull(message) + " [at " + requireNonNull(source) + ']';
@Test
public void testThrowIfFalse() {
@Test
public void testThrowIfFalse() {
- SourceException.throwIf(false, null, null);
- }
-
- @Test(expected = NullPointerException.class)
- public void testThrowIfTrueNullNull() {
- SourceException.throwIf(true, null, null);
+ SourceException.throwIf(false, mock, "");
}
@Test(expected = NullPointerException.class)
}
@Test(expected = NullPointerException.class)
@Test
public void testThrowIfNullMock() {
@Test
public void testThrowIfNullMock() {
- assertSame(mock, SourceException.throwIfNull(mock, null, null));
+ assertSame(mock, SourceException.throwIfNull(mock, mock, ""));
}
@Test
public void testUnwrapPresent() {
}
@Test
public void testUnwrapPresent() {
- assertEquals("test", SourceException.unwrap(Optional.of("test"), null, null));
+ assertEquals("test", SourceException.unwrap(Optional.of("test"), mock, ""));
}
@Test(expected = SourceException.class)
}
@Test(expected = SourceException.class)