Search in sources :

Example 1 with ValidationProblem

use of org.eclipse.mylyn.wikitext.validation.ValidationProblem in project mylyn.docs by eclipse.

the class TestMarkupValidationRule method findProblem.

@Override
public ValidationProblem findProblem(String markup, int offset, int length) {
    Matcher matcher = pattern.matcher(markup);
    if (offset > 0 || length != markup.length()) {
        matcher.region(offset, offset + length);
    }
    if (matcher.find()) {
        String group = matcher.group(1);
        Severity severity;
        if ("ERROR".equals(group)) {
            severity = Severity.ERROR;
        } else {
            severity = Severity.WARNING;
        }
        return new ValidationProblem(severity, "test error", matcher.start(1), matcher.end(1) - matcher.start(1));
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem) Severity(org.eclipse.mylyn.wikitext.validation.ValidationProblem.Severity)

Example 2 with ValidationProblem

use of org.eclipse.mylyn.wikitext.validation.ValidationProblem in project mylyn.docs by eclipse.

the class CommentValidationRuleTest method testOk.

public void testOk() {
    String markup = "a <!-- valid comment -->";
    ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
    assertNull(problem);
}
Also used : ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 3 with ValidationProblem

use of org.eclipse.mylyn.wikitext.validation.ValidationProblem in project mylyn.docs by eclipse.

the class CommentValidationRule method findProblem.

@Override
public ValidationProblem findProblem(String markup, int offset, int length) {
    Matcher matcher = commentPattern.matcher(markup);
    if (offset > 0 || length != markup.length()) {
        matcher.region(offset, offset + length);
    }
    if (matcher.find()) {
        int problemOffset = matcher.start();
        int problemLength = Math.max(2, matcher.end() - problemOffset);
        return new // $NON-NLS-1$
        ValidationProblem(// $NON-NLS-1$
        Severity.WARNING, // $NON-NLS-1$
        Messages.getString("CommentValidationRule.1"), problemOffset, problemLength);
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 4 with ValidationProblem

use of org.eclipse.mylyn.wikitext.validation.ValidationProblem in project mylyn.docs by eclipse.

the class StandaloneMarkupValidatorTest method testSimple.

public void testSimple() {
    List<ValidationProblem> problems = validator.validate("some text ERROR more text WARNING and ERROR");
    assertNotNull(problems);
    assertEquals(3, problems.size());
    ValidationProblem first = problems.get(0);
    assertEquals(Severity.ERROR, first.getSeverity());
    assertEquals(10, first.getOffset());
    assertEquals(5, first.getLength());
    ValidationProblem second = problems.get(1);
    assertEquals(Severity.WARNING, second.getSeverity());
    assertEquals(26, second.getOffset());
    assertEquals(7, second.getLength());
    ValidationProblem third = problems.get(2);
    assertEquals(Severity.ERROR, third.getSeverity());
    assertEquals(38, third.getOffset());
    assertEquals(5, third.getLength());
}
Also used : ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 5 with ValidationProblem

use of org.eclipse.mylyn.wikitext.validation.ValidationProblem in project mylyn.docs by eclipse.

the class ListWhitespaceValidationRule method findProblem.

@Override
public ValidationProblem findProblem(String markup, int offset, int length) {
    Matcher matcher = almostListPattern.matcher(markup);
    if (offset > 0 || length != markup.length()) {
        matcher.region(offset, offset + length);
    }
    while (matcher.find()) {
        String spaces = matcher.group(1);
        if (spaces == null || spaces.length() == 0 || (spaces.length() % 3) != 0 || containsNonSpace(spaces)) {
            int problemOffset = matcher.start();
            int problemLength = Math.max(2, matcher.end(2) - problemOffset);
            return new ValidationProblem(Severity.WARNING, Messages.getString("ListWhitespaceValidationRule.1"), problemOffset, // $NON-NLS-1$
            problemLength);
        }
        String after = matcher.group(5);
        if (after != null) {
            int problemOffset = matcher.start();
            int problemLength = Math.max(2, matcher.end(2) - problemOffset);
            return new // $NON-NLS-1$
            ValidationProblem(// $NON-NLS-1$
            Severity.WARNING, // $NON-NLS-1$
            Messages.getString("ListWhitespaceValidationRule.2"), problemOffset, problemLength);
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Aggregations

ValidationProblem (org.eclipse.mylyn.wikitext.validation.ValidationProblem)27 Matcher (java.util.regex.Matcher)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BuildException (org.apache.tools.ant.BuildException)2 StandaloneMarkupValidator (org.eclipse.mylyn.wikitext.validation.StandaloneMarkupValidator)2 Map (java.util.Map)1 IMarker (org.eclipse.core.resources.IMarker)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ISynchronizable (org.eclipse.jface.text.ISynchronizable)1 Position (org.eclipse.jface.text.Position)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)1 MarkdownLanguage (org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage)1 LinkDefinitionUsageTracker (org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker)1 Position (org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker.Position)1 MarkdownContentState (org.eclipse.mylyn.wikitext.markdown.internal.MarkdownContentState)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1 Severity (org.eclipse.mylyn.wikitext.validation.ValidationProblem.Severity)1