 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.var.crossfire.model.validation.checks;
22 import java.util.Collections;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
33 import org.jetbrains.annotations.NotNull;
40 public class SuspiciousMsgChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
GameObjectValidator<G, A, R> {
46 private static final Pattern
PATTERN_REPLY = Pattern.compile(
"(@reply|@question)([ ]+)([^ ]+)([ ]+)(.+)");
94 final String msg = gameObject.getMsgText(
true);
95 switch (gameObject.getTypeNo()) {
97 if (msg ==
null || msg.isEmpty()) {
106 for (
final String line : msg.split(
"\n")) {
107 if (line.startsWith(
"@") || line.startsWith(
"match")) {
125 if (!msg.isEmpty() && !msg.endsWith(
"\n")) {
126 throw new IllegalArgumentException(
"message does not end with \\n: " + msg);
135 if (!msg.isEmpty()) {
136 for (
final String line : msg.substring(0, msg.length() - 1).split(
"\n", -1)) {
138 if (line.startsWith(
"@match ")) {
139 final String text = line.substring(7);
140 if (text.equals(
"*")) {
142 }
else if (text.startsWith(
"*")) {
156 }
else if (line.equals(
"@match")) {
166 if (matcher.matches()) {
167 final String keyword = matcher.group(1);
168 if (matcher.group(2).length() > 1) {
169 generator.
errorKeywordError(
"the keyword '" + matcher.group(2).substring(1) + matcher.group(3) +
"' after '" + keyword +
"' starts with a space");
171 if (matcher.group(4).length() > 1) {
172 generator.
errorKeywordError(
"the text '" + matcher.group(4).substring(1) + matcher.group(5) +
"' after '" + keyword +
"' starts with a space");
183 if (matcher2.matches()) {
184 final String keyword = matcher2.group(1);
193 }
else if (line.equals(
"@reply")) {
201 }
else if (line.equals(
"@question")) {
213 if (line.isEmpty()) {
220 if (line.startsWith(
"match")) {
221 generator.
errorSyntaxError(
"a text line starts with 'match'. Maybe '@match' was intended?");
222 }
else if (line.startsWith(
"@")) {
A GameObjectValidator that checks for "msg" values that start with "match ".
void match(@NotNull final ErrorGenerator< G, A, R > generator, @NotNull final Iterable< String > matchKeywords)
Processes a @match line.
void errorMatchAllText()
Adds a new error message for an '@match *' line with text following the '*'.
void reply(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a qreply or @question line.
void text(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a line of text.
Generator for SuspiciousMsgChecker related error messages.
Base package of all Gridarta classes.
void match(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a @match line.
void eof(@NotNull final ErrorGenerator< G, A, R > generator)
Will be called at the end of processing.
SuspiciousMsgChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
void reply(@NotNull final ErrorGenerator< G, A, R > generator, @NotNull final String command, @NotNull final String keyword)
Processes a @reply or @question line.
void eof(@NotNull final ErrorGenerator< G, A, R > generator)
Will be called at the end of processing.
final KeywordValidator< G, A, R > keywordValidator
The KeywordValidator instance.
Parser for Crossfire regular expressions.
final TextValidator< G, A, R > textValidator
The TextValidator instance.
Reflects a game object (object on a map).
static final Pattern PATTERN_REPLY_WITHOUT_TEXT
Matches a @reply or @question line which is missing the text part.
Collection< String > getWords()
Returns the words from the last call to ErrorGenerator).
static final Pattern PATTERN_REPLY
Matches a @reply or @question line.
void parse(@NotNull final String regEx, @NotNull final ErrorGenerator<?, ?, ?> generator)
Parses a regular expression.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
final MagicEarValidator< G, A, R > magicEarValidator
The MagicEarValidator instance.
Configuration parameters for Validators.
void text(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a non-empty line of text.
GameObjects are the objects based on Archetypes found on maps.
Implements Crossfire archetypes.
MapArchObject contains the specific meta data about a map that is stored in the map-arch,...
void reply(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a qreply or @question line.
void empty(@NotNull final ErrorGenerator< G, A, R > generator)
Processes an empty line of text.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
void match(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a @match line.
Interface for MapArchObjects.
void text(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a non-empty line of text.
void errorSyntaxError(@NotNull final String reason)
Reports a general syntax error.
An interface for classes that collect errors.
void reply(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a qreply or @question line.
This is the base class for validators.
This package contains the framework for validating maps.
void match()
Processes a @match line.
void empty(@NotNull final ErrorGenerator< G, A, R > generator)
Processes an empty line of text.
void checkMessage(@NotNull final G gameObject, @NotNull final ErrorCollector< G, A, R > errorCollector, @NotNull final String msg, final boolean magicEar)
Checks the "msg" field of a game object.
void reset()
Resets the checker state.
A magic ear that does not contain a @match line.
void errorKeywordError(@NotNull final String reason)
Reports a keyword related error.
final RegExParser parser
The RegExParser instance.
Handles the Crossfire GameObjects.
Interface for GameObject Validators.
void validateGameObject(@NotNull final G gameObject, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validates a game object.
void eof(@NotNull final ErrorGenerator< G, A, R > generator)
Will be called at the end of processing.
final ReplyValidator< G, A, R > replyValidator
The ReplyValidator instance.
void reset()
Resets the checker state.
void reset()
Resets the checker state.
void setCurrentLine(@NotNull final String line)
Sets the line currently being analyzed.
void reset()
Resets the checker state.