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;
39 import org.jetbrains.annotations.NotNull;
104 final Class<?> tmpClass;
107 tmpClass = Class.forName(args[0]);
108 }
catch (
final ClassNotFoundException ex) {
110 }
catch (
final ExceptionInInitializerError ex) {
112 }
catch (
final LinkageError ex) {
115 final Class<?> classValidator;
117 classValidator = tmpClass.asSubclass(
Validator.class);
118 }
catch (
final ClassCastException ex) {
121 final Constructor<?>[] constructors = classValidator.getConstructors();
122 if (constructors.length == 0) {
124 }
else if (constructors.length > 1) {
128 @SuppressWarnings(
"unchecked")
final Constructor<? extends Validator<G, A, R>> constructor = (Constructor<? extends Validator<G, A, R>>) constructors[0];
129 final Class<?>[] constructorParameterTypes = constructor.getParameterTypes();
130 final Object[] constructorArguments =
new Object[constructorParameterTypes.length];
132 for (
int i = 0; i < constructorParameterTypes.length; i++) {
133 final Class<?> constructorParameterType = constructorParameterTypes[i];
138 }
else if (constructorParameterType ==
MapWriter.class) {
141 if (pos >= args.length) {
144 final String arg = args[pos++];
145 if (constructorParameterType == Integer[].
class) {
149 }
else if (constructorParameterType ==
int.
class) {
151 }
else if (constructorParameterType == String[].
class) {
154 }
else if (constructorParameterType == Pattern.class) {
157 throw new NoSuchValidatorException(
"class " + args[0] +
"'s constructor requires a parameter of type " + constructorParameterType.getName() +
"; this type is not supported");
164 validator = constructor.newInstance(constructorArguments);
165 }
catch (
final ExceptionInInitializerError ex) {
167 }
catch (
final InstantiationException ex) {
169 }
catch (
final IllegalAccessException ex) {
170 throw new AssertionError(ex);
171 }
catch (
final IllegalArgumentException ex) {
172 throw new AssertionError(ex);
173 }
catch (
final InvocationTargetException ex) {
176 if (pos < args.length) {
182 }
while (pos < args.length);
187 if (tmp.length != 2 && tmp.length != 3) {
192 fromType = Integer.parseInt(tmp[0]);
193 }
catch (
final NumberFormatException ex) {
198 toType = Integer.parseInt(tmp[1]);
199 }
catch (
final NumberFormatException ex) {
202 if (tmp.length == 2) {
203 customTypeChecker.
addIgnore(fromType, toType);
207 envType = Integer.parseInt(tmp[2]);
208 }
catch (
final NumberFormatException ex) {
211 customTypeChecker.
addIgnore(fromType, toType, envType);
214 }
while (pos < args.length);
219 if (tmp.length != 2) {
226 }
while (pos < args.length);
244 final Integer[] result =
new Integer[tmp.length];
245 for (
int i = 0; i < tmp.length; i++) {
247 result[i] = Integer.parseInt(tmp[i]);
248 }
catch (
final NumberFormatException ex) {
271 final String[] result =
new String[args.length - pos];
272 for (
int i = 0; i < result.length; i++) {
274 result[i] = stringParameterBuilder.
replace(args[pos + i]);
292 if (gameObjectMatcher == null) {
295 return gameObjectMatcher;
308 return Integer.parseInt(arg);
309 }
catch (
final NumberFormatException ex) {
324 return Pattern.compile(arg);
325 }
catch (
final PatternSyntaxException ex) {
static Integer createInteger(@NotNull final String arg)
Creates an.
Utility class for string manipulation.
void addIgnore(final int fromType, final int toType)
Adds an allowed type change.
Reading and writing of maps, handling of paths.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
Settings that apply to a project.
Interface for classes that write map files.
This package contains the framework for validating maps.
String replace(@NotNull final CharSequence spec)
Replaces all parameters in a string.
Checks that a game object does not set a custom type.
static final String MAP_PLACEHOLDER
The placeholder in the command's arguments for the map to check.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to pass to the newly created Validator instances.
ValidatorFactory(@NotNull final ValidatorPreferences validatorPreferences, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ProjectSettings projectSettings, @NotNull final MapWriter< G, A, R > mapWriter)
Creates a new instance.
An GameObjectValidator to assert that game objects do not have critical slaying strings.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Executes a script to check a map.
void addAllowedValue(@NotNull final String value)
Adds a value which does not trigger a warning.
Validator< G, A, R > newValidator(@NotNull final CharSequence spec)
Creates a new Validator instance from string representation.
final MapWriter< G, A, R > mapWriter
The MapWriter to pass to the newly created Validator instances.
GameObjectMatcher getMatcher(@NotNull final String... ids)
Returns a matcher by id; returns.
Exception thrown if a map validator cannot be created.
String [] createStringArray(@NotNull final String[] args, final int pos)
Creates an.
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
Maintains GameObjectMatcher instances.
static Integer [] createIntegerArray(@NotNull final CharSequence arg)
Creates an.
Exception thrown for incorrect arguments.
Checks that a game object does not set a custom type.
Super-interface for validators.
static final Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
Replaces placeholders in strings.
A factory for creating Validator instances from string representation.
static final String REAL_MAP_PLACEHOLDER
The placeholder in the command's arguments for the real map path.
final ProjectSettings projectSettings
The ProjectSettings to pass to the newly created Validator instances.
File getArchDirectory()
Returns the archetype directory.
File getCollectedDirectory()
Returns the directory where collected archetypes are stored.
GameObjectMatcher createGameObjectMatcher(@NotNull final String arg)
Creates a GameObjectMatcher instance from string representation.
File getMapsDirectory()
Returns the default maps directory.
void addParameter(@NotNull final String key, @NotNull final String value)
Adds a parameter key/value pair.
final GameObjectMatchers gameObjectMatchers
The GameObjectMatchers for looking up GameObjectMatcher instances from string representation.
Interface for MapArchObjects.
static Pattern createPattern(@NotNull final String arg)
Creates an.
void addMatcher(@NotNull final GameObjectMatcher gameObjectMatcher, @NotNull final Pattern regex)
Adds a matcher to check.