Search in sources :

Example 1 with NoOpDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder in project mylyn.docs by eclipse.

the class HtmlParserTest method assertParseEventOrder.

private void assertParseEventOrder(String content, Object... expectedEventTypes) {
    final List<Object> actualEventTypes = new ArrayList<>();
    DocumentBuilder builder = new NoOpDocumentBuilder() {

        @Override
        public void beginBlock(BlockType type, Attributes attributes) {
            actualEventTypes.add(type);
        }

        @Override
        public void beginSpan(SpanType type, Attributes attributes) {
            actualEventTypes.add(type);
        }

        @Override
        public void characters(String text) {
            actualEventTypes.add(text);
        }

        @Override
        public void endBlock() {
            actualEventTypes.add(END_BLOCK);
        }

        @Override
        public void endSpan() {
            actualEventTypes.add(END_SPAN);
        }
    };
    parse(content, builder);
    assertEquals(ImmutableList.copyOf(expectedEventTypes), actualEventTypes);
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) SpanType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) BlockType(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType) ArrayList(java.util.ArrayList) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes)

Example 2 with NoOpDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder in project mylyn.docs by eclipse.

the class SourceBlocks method calculateSourceBlocks.

public List<SourceBlock> calculateSourceBlocks(final ProcessingContext context, LineSequence lineSequence, Predicate<BlockContext> predicate) {
    final List<SourceBlock> sourceBlocks = new ArrayList<>();
    final NoOpDocumentBuilder builder = new NoOpDocumentBuilder();
    process(lineSequence, new SourceBlockRunnable() {

        @Override
        public void run(LineSequence lineSequence, SourceBlock sourceBlock) {
            sourceBlocks.add(sourceBlock);
            sourceBlock.process(context, builder, lineSequence);
        }
    }, predicate);
    return sourceBlocks;
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) ArrayList(java.util.ArrayList)

Example 3 with NoOpDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder in project mylyn.docs by eclipse.

the class TextileLanguage method processContent.

@Override
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
    if (preprocessFootnotes) {
        boolean previousBlocksOnly = isBlocksOnly();
        boolean previousFilterGenerativeContents = isFilterGenerativeContents();
        setBlocksOnly(true);
        setFilterGenerativeContents(true);
        DocumentBuilder builder = parser.getBuilder();
        parser.setBuilder(new NoOpDocumentBuilder());
        currentState = new TextileContentState();
        TextileContentState preprocessingState = currentState;
        super.processContent(parser, markupContent, asDocument);
        setBlocksOnly(previousBlocksOnly);
        setFilterGenerativeContents(previousFilterGenerativeContents);
        currentState = new TextileContentState();
        currentState.setFootnoteNumbers(preprocessingState.getFootnoteNumbers());
        parser.setBuilder(builder);
        super.processContent(parser, markupContent, asDocument);
        currentState = null;
    } else {
        currentState = null;
        super.processContent(parser, markupContent, asDocument);
    }
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) TextileDocumentBuilder(org.eclipse.mylyn.wikitext.textile.internal.TextileDocumentBuilder) TextileContentState(org.eclipse.mylyn.wikitext.textile.internal.TextileContentState)

Example 4 with NoOpDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder in project mylyn.docs by eclipse.

the class InlineParser method toStringContent.

static String toStringContent(List<Inline> contents) {
    final StringBuilder stringBuilder = new StringBuilder();
    DocumentBuilder altDocumentBuilder = new NoOpDocumentBuilder() {

        @Override
        public void characters(String text) {
            stringBuilder.append(text);
        }

        @Override
        public void entityReference(String entity) {
            stringBuilder.append(Objects.firstNonNull(EntityReferences.instance().equivalentString(entity), ""));
        }
    };
    for (Inline inline : contents) {
        inline.emit(altDocumentBuilder);
    }
    return stringBuilder.toString();
}
Also used : NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder)

Example 5 with NoOpDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder in project mylyn.docs by eclipse.

the class MultiplexingDocumentBuilderTest method flush.

@Test
public void flush() {
    final AtomicBoolean flushed = new AtomicBoolean();
    DocumentBuilder delegate = new NoOpDocumentBuilder() {

        @Override
        public void flush() {
            flushed.set(true);
        }
    };
    multiplexer = new MultiplexingDocumentBuilder(delegate);
    multiplexer.flush();
    assertTrue(flushed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) NoOpDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) MultiplexingDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.MultiplexingDocumentBuilder) EventDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder) MultiplexingDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.MultiplexingDocumentBuilder) Test(org.junit.Test)

Aggregations

NoOpDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.NoOpDocumentBuilder)7 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)5 ArrayList (java.util.ArrayList)3 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)2 EventDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.EventDocumentBuilder)2 MultiplexingDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.MultiplexingDocumentBuilder)2 Test (org.junit.Test)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 BlockType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.BlockType)1 SpanType (org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType)1 LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)1