Add more intrinsic methods to be maybe used in the future

This commit is contained in:
Alexander Udalov
2015-10-19 16:03:32 +03:00
parent a24ac86e1c
commit c204e8fc67
@@ -28,7 +28,19 @@ public class Intrinsics {
} }
public static String stringPlus(String self, Object other) { public static String stringPlus(String self, Object other) {
return String.valueOf(self) + String.valueOf(other); return self + other;
}
public static void checkNotNull(Object object) {
if (object == null) {
throwNpe();
}
}
public static void checkNotNull(Object object, String message) {
if (object == null) {
throwNpe(message);
}
} }
public static void throwNpe() { public static void throwNpe() {
@@ -47,26 +59,65 @@ public class Intrinsics {
throwUninitializedProperty("lateinit property " + propertyName + " has not been initialized"); throwUninitializedProperty("lateinit property " + propertyName + " has not been initialized");
} }
public static void checkExpressionValueIsNotNull(Object value, String message) { public static void throwAssert() {
throw sanitizeStackTrace(new AssertionError());
}
public static void throwAssert(String message) {
throw sanitizeStackTrace(new AssertionError(message));
}
public static void throwIllegalArgument() {
throw sanitizeStackTrace(new IllegalArgumentException());
}
public static void throwIllegalArgument(String message) {
throw sanitizeStackTrace(new IllegalArgumentException(message));
}
public static void throwIllegalState() {
throw sanitizeStackTrace(new IllegalStateException());
}
public static void throwIllegalState(String message) {
throw sanitizeStackTrace(new IllegalStateException(message));
}
public static void checkExpressionValueIsNotNull(Object value, String expression) {
if (value == null) { if (value == null) {
IllegalStateException exception = new IllegalStateException(message + " must not be null"); throw sanitizeStackTrace(new IllegalStateException(expression + " must not be null"));
throw sanitizeStackTrace(exception); }
}
public static void checkNotNullExpressionValue(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
} }
} }
public static void checkReturnedValueIsNotNull(Object value, String className, String methodName) { public static void checkReturnedValueIsNotNull(Object value, String className, String methodName) {
if (value == null) { if (value == null) {
IllegalStateException exception = throw sanitizeStackTrace(
new IllegalStateException("Method specified as non-null returned null: " + className + "." + methodName); new IllegalStateException("Method specified as non-null returned null: " + className + "." + methodName)
throw sanitizeStackTrace(exception); );
}
}
public static void checkReturnedValueIsNotNull(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
} }
} }
public static void checkFieldIsNotNull(Object value, String className, String fieldName) { public static void checkFieldIsNotNull(Object value, String className, String fieldName) {
if (value == null) { if (value == null) {
IllegalStateException exception = throw sanitizeStackTrace(new IllegalStateException("Field specified as non-null is null: " + className + "." + fieldName));
new IllegalStateException("Field specified as non-null is null: " + className + "." + fieldName); }
throw sanitizeStackTrace(exception); }
public static void checkFieldIsNotNull(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
} }
} }
@@ -76,6 +127,12 @@ public class Intrinsics {
} }
} }
public static void checkNotNullParameter(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalArgumentException(message));
}
}
private static void throwParameterIsNullException(String paramName) { private static void throwParameterIsNullException(String paramName) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();