blob: 7113761b99c167e623661de2ebcbe156474183a9 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2014, 2017 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.redocs.wikitext.r.textile.core;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.osgi.util.NLS;
import org.eclipse.statet.ecommons.text.core.ILineInformation;
import org.eclipse.statet.docmlet.wikitext.core.WikitextProblemReporter;
import org.eclipse.statet.docmlet.wikitext.core.model.IWikidocModelInfo;
import org.eclipse.statet.docmlet.wikitext.core.model.IWikitextSourceUnit;
import org.eclipse.statet.docmlet.wikitext.core.model.WikitextModel;
import org.eclipse.statet.internal.redocs.wikitext.r.textile.Messages;
import org.eclipse.statet.ltk.core.SourceContent;
import org.eclipse.statet.ltk.issues.core.IProblem;
import org.eclipse.statet.ltk.issues.core.IProblemRequestor;
import org.eclipse.statet.ltk.issues.core.impl.Problem;
public class TextileValidator extends WikitextProblemReporter {
private static final Pattern BLOCK_START_PATTERN= Pattern.compile("\\A((?:bc|bq|pre|table|p)\\.\\.?+)(.)?"); //$NON-NLS-1$
public TextileValidator() {
}
@Override
public void run(final IWikitextSourceUnit su, final SourceContent content,
final IWikidocModelInfo model,
final IProblemRequestor requestor, final int level, final IProgressMonitor monitor) {
final Matcher matcher= BLOCK_START_PATTERN.matcher(content.getText());
try {
final ILineInformation lines= content.getLines();
final int numLines= lines.getNumberOfLines();
int start= 0;
for (int line= 0; line < numLines; line++) {
final int end= lines.getLineEndOffset(line);
matcher.region(start, end);
if (matcher.find()) {
final String followingCharacter= matcher.group(2);
if (followingCharacter == null || !followingCharacter.equals(" ")) { //$NON-NLS-1$
final String matched= matcher.group(1);
requestor.acceptProblems(new Problem(WikitextModel.WIKIDOC_TYPE_ID,
IProblem.SEVERITY_WARNING, 0,
NLS.bind(Messages.Validation_BlockWhitespace_message, matched),
line, start, matcher.end(1) ));
}
}
start= end;
}
}
catch (final BadLocationException e) {}
}
}