20 package net.sf.gridarta.model.validation.checks;
22 import java.lang.reflect.Constructor;
23 import java.lang.reflect.InvocationTargetException;
24 import java.util.regex.Pattern;
25 import java.util.regex.PatternSyntaxException;
40 import org.jetbrains.annotations.NotNull;
113 @SuppressWarnings(
"ChainOfInstanceofChecks")
116 final Class<?> tmpClass;
119 tmpClass = Class.forName(args[0]);
120 }
catch (
final ClassNotFoundException | LinkageError ex) {
123 final Class<?> classValidator;
125 classValidator = tmpClass.asSubclass(
Validator.class);
126 }
catch (
final ClassCastException ex) {
129 final Constructor<?>[] constructors = classValidator.getConstructors();
130 if (constructors.length == 0) {
133 if (constructors.length > 1) {
137 @SuppressWarnings(
"unchecked")
final Constructor<? extends Validator<G, A, R>> constructor = (Constructor<? extends Validator<G, A, R>>) constructors[0];
138 final Class<?>[] constructorParameterTypes = constructor.getParameterTypes();
139 final Object[] constructorArguments =
new Object[constructorParameterTypes.length];
141 for (
int i = 0; i < constructorParameterTypes.length; i++) {
142 final Class<?> constructorParameterType = constructorParameterTypes[i];
147 }
else if (constructorParameterType ==
MapWriter.class) {
149 }
else if (constructorParameterType ==
MapManager.class) {
152 if (pos >= args.length) {
155 final String arg = args[pos++];
156 if (constructorParameterType == Integer[].
class) {
160 }
else if (constructorParameterType ==
int.
class) {
162 }
else if (constructorParameterType == String[].
class) {
165 }
else if (constructorParameterType == Pattern.class) {
168 throw new NoSuchValidatorException(
"class " + args[0] +
"'s constructor requires a parameter of type " + constructorParameterType.getName() +
"; this type is not supported");
175 validator = constructor.newInstance(constructorArguments);
176 }
catch (
final ExceptionInInitializerError ex) {
178 }
catch (
final InstantiationException ex) {
180 }
catch (
final IllegalAccessException | IllegalArgumentException ex) {
181 throw new AssertionError(ex);
182 }
catch (
final InvocationTargetException ex) {
185 if (pos < args.length) {
191 }
while (pos < args.length);
196 if (tmp.length != 2 && tmp.length != 3) {
201 fromType = Integer.parseInt(tmp[0]);
202 }
catch (
final NumberFormatException ex) {
207 toType = Integer.parseInt(tmp[1]);
208 }
catch (
final NumberFormatException ex) {
211 if (tmp.length == 2) {
212 customTypeChecker.
addIgnore(fromType, toType);
216 envType = Integer.parseInt(tmp[2]);
217 }
catch (
final NumberFormatException ex) {
220 customTypeChecker.
addIgnore(fromType, toType, envType);
223 }
while (pos < args.length);
228 if (tmp.length != 2) {
235 }
while (pos < args.length);
253 final Integer[] result =
new Integer[tmp.length];
254 for (
int i = 0; i < tmp.length; i++) {
256 result[i] = Integer.parseInt(tmp[i]);
257 }
catch (
final NumberFormatException ex) {
280 final String[] result =
new String[args.length - pos];
281 for (
int i = 0; i < result.length; i++) {
283 result[i] = stringParameterBuilder.
replace(args[pos + i]);
301 if (gameObjectMatcher ==
null) {
304 return gameObjectMatcher;
317 return Integer.parseInt(arg);
318 }
catch (
final NumberFormatException ex) {
333 return Pattern.compile(arg);
334 }
catch (
final PatternSyntaxException ex) {