From 43866163b9ec09d0955b87cca2656fa9b951a26c Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Mon, 11 May 2020 08:38:35 -0400 Subject: [PATCH] XOMW: Add Assert [#632] --- .../gplx/xowa/mediawiki/XophpException.java | 1 + .../XophpInvalidArgumentException.java | 6 +- .../xowa/mediawiki/XophpLogicException.java | 25 ++ .../xowa/mediawiki/XophpRuntimeException.java | 1 + .../src/gplx/xowa/mediawiki/XophpType_.java | 1 + .../libs/services/XomwServiceContainer.java | 7 +- .../wikimedia/Assert/src/XomwAssert.java | 226 ++++++++++++++++++ .../Assert/src/XomwAssertionException.java | 31 +++ .../Assert/src/XomwInvariantException.java | 34 +++ .../src/XomwParameterAssertionException.java | 63 +++++ .../XomwParameterElementTypeException.java | 58 +++++ .../src/XomwParameterTypeException.java | 58 +++++ .../src/XomwPostconditionException.java | 34 +++ .../Assert/src/XomwPreconditionException.java | 33 +++ 14 files changed, 572 insertions(+), 6 deletions(-) create mode 100644 400_xowa/src/gplx/xowa/mediawiki/XophpLogicException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssert.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssertionException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwInvariantException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterAssertionException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterElementTypeException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterTypeException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPostconditionException.java create mode 100644 400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPreconditionException.java diff --git a/400_xowa/src/gplx/xowa/mediawiki/XophpException.java b/400_xowa/src/gplx/xowa/mediawiki/XophpException.java index 2ad15646b..a3dd0b2fc 100644 --- a/400_xowa/src/gplx/xowa/mediawiki/XophpException.java +++ b/400_xowa/src/gplx/xowa/mediawiki/XophpException.java @@ -19,6 +19,7 @@ import gplx.Err; // REF.PHP:https://www.php.net/manual/en/class.exception.php public class XophpException extends Err { + public XophpException() {this("", 0, null);} public XophpException(String message) {this(message, 0, null);} public XophpException(String message, int code, XophpException previous) { super(true, "", "", message); diff --git a/400_xowa/src/gplx/xowa/mediawiki/XophpInvalidArgumentException.java b/400_xowa/src/gplx/xowa/mediawiki/XophpInvalidArgumentException.java index 2c6fc87e9..c2d027d43 100644 --- a/400_xowa/src/gplx/xowa/mediawiki/XophpInvalidArgumentException.java +++ b/400_xowa/src/gplx/xowa/mediawiki/XophpInvalidArgumentException.java @@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository: GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt */ -package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*; +package gplx.xowa.mediawiki; + +import gplx.Err; +import gplx.String_; + public class XophpInvalidArgumentException extends Err { public XophpInvalidArgumentException(String fmt, Object... args) { super(true, "", "", String_.Format(fmt, args)); diff --git a/400_xowa/src/gplx/xowa/mediawiki/XophpLogicException.java b/400_xowa/src/gplx/xowa/mediawiki/XophpLogicException.java new file mode 100644 index 000000000..64c6ad4e6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/XophpLogicException.java @@ -0,0 +1,25 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.mediawiki; + +// REF.PHP:https://www.php.net/manual/en/class.logicexception.php +public class XophpLogicException extends XophpException { + public XophpLogicException() {} + public XophpLogicException(String message) {super(message);} + public XophpLogicException(String message, int code, XophpException previous) { + super(message, code, previous); + } +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/XophpRuntimeException.java b/400_xowa/src/gplx/xowa/mediawiki/XophpRuntimeException.java index d692ade4f..c06e3551d 100644 --- a/400_xowa/src/gplx/xowa/mediawiki/XophpRuntimeException.java +++ b/400_xowa/src/gplx/xowa/mediawiki/XophpRuntimeException.java @@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt */ package gplx.xowa.mediawiki; public class XophpRuntimeException extends XophpException { + public XophpRuntimeException() {} public XophpRuntimeException(String message) {super(message);} public XophpRuntimeException(String message, int code, XophpException previous) { super(message, code, previous); diff --git a/400_xowa/src/gplx/xowa/mediawiki/XophpType_.java b/400_xowa/src/gplx/xowa/mediawiki/XophpType_.java index 049cb061a..5d08ad303 100644 --- a/400_xowa/src/gplx/xowa/mediawiki/XophpType_.java +++ b/400_xowa/src/gplx/xowa/mediawiki/XophpType_.java @@ -53,4 +53,5 @@ public class XophpType_ { } public static Class get_class(Object o) {return o.getClass();} + public static String To_str(Class c) {return c.getCanonicalName();} } diff --git a/400_xowa/src/gplx/xowa/mediawiki/includes/libs/services/XomwServiceContainer.java b/400_xowa/src/gplx/xowa/mediawiki/includes/libs/services/XomwServiceContainer.java index 8e47e4a47..5e9050a3a 100644 --- a/400_xowa/src/gplx/xowa/mediawiki/includes/libs/services/XomwServiceContainer.java +++ b/400_xowa/src/gplx/xowa/mediawiki/includes/libs/services/XomwServiceContainer.java @@ -19,10 +19,7 @@ import gplx.xowa.mediawiki.XophpArray; import gplx.xowa.mediawiki.XophpCallback; import gplx.xowa.mediawiki.XophpObject_; import gplx.xowa.mediawiki.XophpType_; -/* -XOTODO: -* XomwAssert: /vendor/wikimedia/Assert/src -*/ + // MW.SRC:1.33.1 /** * ServiceContainer provides a generic service to manage named services using @@ -132,7 +129,7 @@ public class XomwServiceContainer implements XomwDestructibleService { * instantiator functions. */ public void applyWiring(XophpArray $serviceInstantiators) { - // Assert::parameterElementType('callable', $serviceInstantiators, '$serviceInstantiators'); + // XomwAssert.parameterElementType(XophpCallback.class, $serviceInstantiators, "serviceInstantiators"); // foreach ($serviceInstantiators as $name => $instantiator) { // this.defineService($name, $instantiator); diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssert.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssert.java new file mode 100644 index 000000000..ffdfd3b01 --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssert.java @@ -0,0 +1,226 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.xowa.mediawiki.XophpArray; +import gplx.xowa.mediawiki.XophpObject_; +import gplx.xowa.mediawiki.XophpType; +import gplx.xowa.mediawiki.XophpType_; + +// MW.SRC:1.33.1 +/** + * Assert provides functions for assorting preconditions (such as parameter types) and + * postconditions. It is intended as a safer alternative to PHP's assert() function. + * + * Note that assertions evaluate expressions and add function calls, so using assertions + * may have a negative impact on performance when used in performance hotspots. The idea + * if this class is to have a neat tool for assertions if and when they are needed. + * It is not recommended to place assertions all over the code indiscriminately. + * + * For more information, see the the README file. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwAssert { + + /** + * Checks a precondition, that is, throws a PreconditionException if condition is false. + * For checking call parameters, use Assert::parameter() instead. + * + * This is provided for completeness, most preconditions should be covered by + * Assert::parameter() and related assertions. + * + * @see parameter() + * + * @note This is intended mostly for checking preconditions in constructors and setters, + * or before using parameters in complex computations. + * Checking preconditions in every function call is not recommended, since it may have a + * negative impact on performance. + * + * @param bool condition + * @param string description The message to include in the exception if the condition fails. + * + * @throws PreconditionException if condition is not true. + */ + public static void precondition(boolean condition, String description) { + if (!condition) { + throw new XomwPreconditionException("Precondition failed: {0}", description); + } + } + + /** + * Checks a parameter, that is, throws a ParameterAssertionException if condition is false. + * This is similar to Assert::precondition(). + * + * @note This is intended for checking parameters in constructors and setters. + * Checking parameters in every function call is not recommended, since it may have a + * negative impact on performance. + * + * @param bool condition + * @param string name The name of the parameter that was checked. + * @param string description The message to include in the exception if the condition fails. + * + * @throws ParameterAssertionException if condition is not true. + */ + public static void parameter(boolean condition, String name, String description) { + if (!condition) { + throw new XomwParameterAssertionException(name, description); + } + } + + /** + * Checks an parameter's type, that is, throws a InvalidArgumentException if condition is false. + * This is really a special case of Assert::precondition(). + * + * @note This is intended for checking parameters in constructors and setters. + * Checking parameters in every function call is not recommended, since it may have a + * negative impact on performance. + * + * @note If possible, type hints should be used instead of calling this function. + * It is intended for cases where type hints to not work, e.g. for checking primitive types. + * + * @param string type The parameter's expected type. Can be the name of a native type or a + * class or interface. If multiple types are allowed, they can be given separated by + * a pipe character ("|"). + * @param mixed value The parameter's actual value. + * @param string name The name of the parameter that was checked. + * + * @throws ParameterTypeException if value is not of type (or, for objects, is not an + * instance of) type. + */ + public static void parameterType(Class type, Object value, String name) { + // if (!hasType(value, XophpArray.explode('|', type))) { + if (!hasType(value, type)) { + throw new XomwParameterTypeException(name, XophpType_.To_str(type)); + } + } + + /** + * Checks the type of all elements of an parameter, assuming the parameter is an array, + * that is, throws a ParameterElementTypeException if value + * + * @note This is intended for checking parameters in constructors and setters. + * Checking parameters in every function call is not recommended, since it may have a + * negative impact on performance. + * + * @param string type The elements' expected type. Can be the name of a native type or a + * class or interface. If multiple types are allowed, they can be given separated by + * a pipe character ("|"). + * @param mixed value The parameter's actual value. If this is not an array, + * a ParameterTypeException is raised. + * @param string name The name of the parameter that was checked. + * + * @throws ParameterTypeException If value is not an array. + * @throws ParameterElementTypeException If an element of value is not of type + * (or, for objects, is not an instance of) type. + */ + public static void parameterElementType(Class type, XophpArray value, String name) { + // parameterType(XophpArray.class, valueObj, name); + + // allowedTypes = explode('|', type); + + for (Object element : value) { + if (!hasType(element, type)) { + throw new XomwParameterElementTypeException(name, XophpType_.To_str(type)); + } + } + } + + /** + * Checks a postcondition, that is, throws a PostconditionException if condition is false. + * This is very similar Assert::invariant() but is intended for use only after a computation + * is complete. + * + * @note This is intended for sanity-checks in the implementation of complex algorithms. + * Note however that it should not be used in performance hotspots, since evaluating + * condition and calling postcondition() costs time. + * + * @param bool condition + * @param string description The message to include in the exception if the condition fails. + * + * @throws PostconditionException + */ + public static void postcondition(boolean condition, String description) { + if (!condition) { + throw new XomwPostconditionException("Postcondition failed: {0}", description); + } + } + + /** + * Checks an invariant, that is, throws a InvariantException if condition is false. + * This is very similar Assert::postcondition() but is intended for use throughout the code. + * + * @note This is intended for sanity-checks in the implementation of complex algorithms. + * Note however that it should not be used in performance hotspots, since evaluating + * condition and calling postcondition() costs time. + * + * @param bool condition + * @param string description The message to include in the exception if the condition fails. + * + * @throws InvariantException + */ + public static void invariant(boolean condition, String description) { + if (!condition) { + throw new XomwInvariantException("Invariant failed: {0}", description); + } + } + + /** + * @param mixed value + * @param array allowedTypes + * + * @return bool + */ + private static boolean hasType(Object value, Class allowedTypes) { + // Apply strtolower because gettype returns "NULL" for null values. + //type = strtolower(gettype(value)); + // + //if (in_array(type, allowedTypes)) { + // return true; + //} + // + //if (is_callable(value) && in_array('callable', allowedTypes)) { + // return true; + //} + + if (XophpObject_.is_object(value) && isInstanceOf(value, allowedTypes)) { + return true; + } + + return false; + } + + /** + * @param mixed value + * @param array allowedTypes + * + * @return bool + */ + private static boolean isInstanceOf(Object value, Class type) {return XophpType_.instance_of(value, type);} + private static boolean isInstanceOf(Object value, XophpArray allowedTypes) { + for (Class type : allowedTypes) { + if (XophpType_.instance_of(value, type)) { + return true; + } + } + + return false; + } + +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssertionException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssertionException.java new file mode 100644 index 000000000..d05f65d3b --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwAssertionException.java @@ -0,0 +1,31 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +// MW.SRC:1.33.1 +/** + * Marker interface for exceptions thrown by Assert. Since the exceptions thrown by Assert + * use different standard exceptions as base classes, the marker interface is needed to be + * able to catch them all at once. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public interface XomwAssertionException { + +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwInvariantException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwInvariantException.java new file mode 100644 index 000000000..868a2402b --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwInvariantException.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.String_; +import gplx.xowa.mediawiki.XophpLogicException; + +// MW.SRC:1.33.1 +/** + * Exception indicating that an invariant assertion failed. + * This generally means an error in the internal logic of a function, or a serious problem + * in the runtime environment. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwInvariantException extends XophpLogicException implements XomwAssertionException { + public XomwInvariantException(String fmt, Object... args) {super(String_.Format(fmt, args));} +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterAssertionException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterAssertionException.java new file mode 100644 index 000000000..7615c9ca0 --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterAssertionException.java @@ -0,0 +1,63 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.xowa.mediawiki.XophpInvalidArgumentException; + +// MW.SRC:1.33.1 +/** + * Exception indicating that an parameter assertion failed. + * This generally means a disagreement between the caller and the implementation of a function. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwParameterAssertionException extends XophpInvalidArgumentException implements XomwAssertionException { + + /** + * @var string + */ + private String parameterName; + + /** + * @param string $parameterName + * @param string $description + * + * @throws ParameterTypeException + */ + public XomwParameterAssertionException(String parameterName, String description) { + //if (!is_string($parameterName)) { + // throw new ParameterTypeException("parameterName", "string"); + //} + // + //if (!is_string($description)) { + // throw new ParameterTypeException("description", "string"); + //} + super("Bad value for parameter {0}:{1}", parameterName, description); + + this.parameterName = parameterName; + } + + /** + * @return string + */ + public String getParameterName() { + return this.parameterName; + } + +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterElementTypeException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterElementTypeException.java new file mode 100644 index 000000000..d6f092b9e --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterElementTypeException.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.String_; + +// MW.SRC:1.33.1 +/** + * Exception indicating that a parameter element type assertion failed. + * This generally means a disagreement between the caller and the implementation of a function. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwParameterElementTypeException extends XomwParameterAssertionException implements XomwAssertionException { + /** + * @var string + */ + private String elementType; + + /** + * @param string $parameterName + * @param string $elementType + * + * @throws ParameterTypeException + */ + public XomwParameterElementTypeException(String parameterName, String elementType) { + //if ( !is_string( $elementType ) ) { + // throw new ParameterTypeException( 'elementType', 'string' ); + //} + + super(parameterName, String_.Format("all elements must be {0}", elementType)); + + this.elementType = elementType; + } + + /** + * @return string + */ + public String getElementType() { + return this.elementType; + } +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterTypeException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterTypeException.java new file mode 100644 index 000000000..21651338d --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwParameterTypeException.java @@ -0,0 +1,58 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.String_; + +// MW.SRC:1.33.1 +/** + * Exception indicating that a parameter type assertion failed. + * This generally means a disagreement between the caller and the implementation of a function. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwParameterTypeException extends XomwParameterAssertionException implements XomwAssertionException { + /** + * @var string + */ + private String parameterType; + + /** + * @param string $parameterName + * @param string $parameterType + * + * @throws ParameterTypeException + */ + public XomwParameterTypeException(String parameterName, String parameterType) { + //if ( !is_string( $parameterType ) ) { + // throw new ParameterTypeException( 'parameterType', 'string' ); + //} + + super(parameterName, String_.Format("must be a {0}", parameterType)); + + this.parameterType = parameterType; + } + + /** + * @return string + */ + public String getParameterType() { + return this.parameterType; + } +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPostconditionException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPostconditionException.java new file mode 100644 index 000000000..c7d9380eb --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPostconditionException.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.String_; +import gplx.xowa.mediawiki.XophpLogicException; + +// MW.SRC:1.33.1 +/** + * Exception indicating that a postcondition assertion failed. + * This generally means an error in the internal logic of a function, or a serious problem + * in the runtime environment. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwPostconditionException extends XophpLogicException implements XomwAssertionException { + public XomwPostconditionException(String fmt, Object... args) {super(String_.Format(fmt, args));} +} diff --git a/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPreconditionException.java b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPreconditionException.java new file mode 100644 index 000000000..35de2f001 --- /dev/null +++ b/400_xowa/src/gplx/xowa/mediawiki/vendor/wikimedia/Assert/src/XomwPreconditionException.java @@ -0,0 +1,33 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ + +package gplx.xowa.mediawiki.vendor.wikimedia.Assert.src; + +import gplx.String_; +import gplx.xowa.mediawiki.XophpRuntimeException; + +// MW.SRC:1.33.1 +/** + * Exception indicating that an precondition assertion failed. + * This generally means a disagreement between the caller and the implementation of a function. + * + * @license MIT + * @author Daniel Kinzler + * @copyright Wikimedia Deutschland e.V. + */ +public class XomwPreconditionException extends XophpRuntimeException implements XomwAssertionException { + public XomwPreconditionException(String fmt, Object... args) {super(String_.Format(fmt, args));} +}