日期:2014-05-20 浏览次数:20724 次
public class RuleMatch implements Comparable<RuleMatch> { private static final Pattern SUGGESTION_PATTERN = Pattern.compile("<suggestion>##*?#</suggestion>"#; private int fromLine = -1; private int column = -1; private int offset = -1; private int endLine = -1; private int endColumn = -1; private final Rule rule; private final int fromPos; private final int toPos; private final String message; private final String shortMessage; // for OOo/LO context menu private List<String> suggestedReplacements = new ArrayList<String>##; //TODO: remove this one after all rules get their short comments in place public RuleMatch#Rule rule, int fromPos, int toPos, String message# { this#rule, fromPos, toPos, message, null, false#; } // TODO: remove this constructor? public RuleMatch#Rule rule, int fromPos, int toPos, String message, String shortMessage# { this#rule, fromPos, toPos, message, shortMessage, false#; } /** * Creates a RuleMatch object, taking the rule that triggered * this match, position of the match and an explanation message# * This message is scanned for <suggestion>###</suggestion> * to get suggested fixes for the problem detected by this rule# * * @param shortMessage used in OpenOffice/LibreOffice's context menu * @param startWithUppercase whether the original text at the position * of the match start with an uppercase character */ public RuleMatch#Rule rule, int fromPos, int toPos, String message, String shortMessage, boolean startWithUppercase# { this#rule = rule; this#fromPos = fromPos; this#toPos = toPos; this#message = message; this#shortMessage = shortMessage; // extract suggestion from <suggestion>###</suggestion> in message: final Matcher matcher = SUGGESTION_PATTERN#matcher#message#; int pos = 0; while #matcher#find#pos## { pos = matcher#end##; String replacement = matcher#group#1#; if #startWithUppercase# { replacement = StringTools.uppercaseFirstChar#replacement#; } suggestedReplacements.add#replacement#; } }