Search in sources :

Example 11 with ValidationProblem

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

the class BlockWhitespaceRuleTest method testMatch2.

public void testMatch2() {
    final String markup = "\nbc.\nfoo";
    ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
    assertNotNull(problem);
    assertEquals(1, problem.getOffset());
}
Also used : ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 12 with ValidationProblem

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

the class BlockWhitespaceRuleTest method testNoMatch2.

public void testNoMatch2() {
    final String markup = "\nabc.\nfoo";
    ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
    assertNull(problem);
}
Also used : ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 13 with ValidationProblem

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

the class BlockWhitespaceRuleTest method testMatch.

public void testMatch() {
    final String markup = "bc.\nfoo";
    ValidationProblem problem = rule.findProblem(markup, 0, markup.length());
    assertNotNull(problem);
    assertEquals(0, problem.getOffset());
}
Also used : ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem)

Example 14 with ValidationProblem

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

the class LinkDefinitionValidationRule method findProblems.

@Override
public List<ValidationProblem> findProblems(String markup, int offset, int length) {
    MarkupParser parser = new MarkupParser(new MarkdownLanguage());
    MarkdownContentStateDocumentBuilder builder = new MarkdownContentStateDocumentBuilder();
    parser.setBuilder(builder);
    parser.parse(markup);
    MarkdownContentState markdownContentState = builder.markdownContentState;
    LinkDefinitionUsageTracker linkDefinitionUsageTracker = markdownContentState.getLinkDefinitionUsageTracker();
    List<ValidationProblem> problems = new ArrayList<ValidationProblem>();
    List<Position> missingLinkDefinitionPositions = linkDefinitionUsageTracker.getMissingLinkDefinitionPositions();
    for (Position position : missingLinkDefinitionPositions) {
        problems.add(new ValidationProblem(Severity.ERROR, MessageFormat.format(// $NON-NLS-1$
        Messages.getString("LinkDefinitionValidationRule.missing"), position.getId()), position.getOffset(), position.getLength()));
    }
    List<Position> unusedLinkDefinitionPositions = linkDefinitionUsageTracker.getUnusedLinkDefinitionPositions();
    for (Position position : unusedLinkDefinitionPositions) {
        problems.add(new ValidationProblem(Severity.WARNING, MessageFormat.format(// $NON-NLS-1$
        Messages.getString("LinkDefinitionValidationRule.unused"), position.getId()), position.getOffset(), position.getLength()));
    }
    return problems;
}
Also used : LinkDefinitionUsageTracker(org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker) Position(org.eclipse.mylyn.wikitext.markdown.internal.LinkDefinitionUsageTracker.Position) MarkdownLanguage(org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage) ArrayList(java.util.ArrayList) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem) MarkdownContentState(org.eclipse.mylyn.wikitext.markdown.internal.MarkdownContentState) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 15 with ValidationProblem

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

the class MarkupTask method performValidation.

protected void performValidation(File source, String markupContent) {
    if (!validate) {
        return;
    }
    if (markupLanguage == null) {
        throw new IllegalStateException();
    }
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupTask.1"), source), Project.MSG_VERBOSE);
    StandaloneMarkupValidator markupValidator = StandaloneMarkupValidator.getValidator(markupLanguage);
    List<ValidationProblem> problems = markupValidator.validate(markupContent);
    int errorCount = 0;
    int warningCount = 0;
    for (ValidationProblem problem : problems) {
        int messageLevel = Project.MSG_ERR;
        if (problem.getSeverity() == Severity.ERROR) {
            ++errorCount;
        } else if (problem.getSeverity() == Severity.WARNING) {
            ++warningCount;
            messageLevel = Project.MSG_WARN;
        }
        // $NON-NLS-1$
        log(String.format("%s:%s %s", source.getName(), problem.getOffset(), problem.getMessage()), messageLevel);
    }
    if ((errorCount > 0 && failOnValidationError) || (warningCount > 0 && failOnValidationWarning)) {
        throw new BuildException(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("MarkupTask.3"), // $NON-NLS-1$
        errorCount, warningCount, source));
    }
}
Also used : StandaloneMarkupValidator(org.eclipse.mylyn.wikitext.validation.StandaloneMarkupValidator) ValidationProblem(org.eclipse.mylyn.wikitext.validation.ValidationProblem) BuildException(org.apache.tools.ant.BuildException)

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