Search in sources :

Example 1 with MarkdownContentState

use of org.eclipse.mylyn.wikitext.markdown.internal.MarkdownContentState 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)

Aggregations

ArrayList (java.util.ArrayList)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 ValidationProblem (org.eclipse.mylyn.wikitext.validation.ValidationProblem)1