Search in sources :

Example 21 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_iterator1.

public void test_iterator1() {
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, impl.size());
    added = impl.add(new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, impl.size());
    Iterator it = null;
    assertNotNull("no iterator returned", it = (Iterator) new Accessor(impl, TextRegionListImpl.class).invoke("iterator", new Object[0]));
    assertTrue(it.hasNext());
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) Iterator(java.util.Iterator) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 22 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_size.

public void test_size() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, impl.size());
    added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, impl.size());
    added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, impl.size());
    assertEquals("wrong object", 0, impl.indexOf(regions[0]));
    assertEquals("wrong object", 1, impl.indexOf(regions[1]));
    assertEquals("wrong object", 2, impl.indexOf(regions[2]));
    assertEquals("wrong count", 3, impl.size());
    impl.remove(regions[1]);
    assertEquals("wrong count", 2, impl.size());
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion)

Example 23 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_iterator0.

public void test_iterator0() {
    TextRegionListImpl impl = new TextRegionListImpl();
    Iterator it = null;
    assertNotNull("no iterator returned", it = (Iterator) new Accessor(impl, TextRegionListImpl.class).invoke("iterator", new Object[0]));
    assertFalse(it.hasNext());
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) Iterator(java.util.Iterator) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 24 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_trimToSize0.

public void test_trimToSize0() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, impl.size());
    added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, impl.size());
    added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, impl.size());
    impl.clear();
    assertEquals("count was wrong", 0, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    impl.trimToSize();
    assertEquals("count was wrong", 0, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    assertEquals("not trimmed", 0, ((Object[]) new Accessor(impl, TextRegionListImpl.class).get("fRegions")).length);
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 25 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class CSSModelParser method insertCharsetRule.

/**
 */
private CSSNodeImpl insertCharsetRule(IStructuredDocumentRegion beginDocRegion, IStructuredDocumentRegion endDocRegion) {
    CSSNodeImpl parent = fCreationContext.getTargetNode();
    if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    ITextRegionList regions = new TextRegionListImpl(beginDocRegion.getRegions());
    // must be "@charset"
    regions.remove(0);
    ITextRegion encodingRegion = null;
    while (!regions.isEmpty()) {
        ITextRegion textRegion = regions.remove(0);
        if (textRegion == null) {
            continue;
        }
        String type = textRegion.getType();
        if (type == CSSRegionContexts.CSS_S || type == CSSRegionContexts.CSS_COMMENT) {
            continue;
        }
        if (type == CSSRegionContexts.CSS_STRING) {
            encodingRegion = textRegion;
            break;
        } else {
            break;
        }
    }
    if (encodingRegion == null) {
        return null;
    }
    CSSCharsetRuleImpl rule = fFeeder.getCSSCharsetRule();
    if (rule == null) {
        return null;
    }
    if (!fUpdateContext.isActive()) {
        rule.setAttribute(ICSSCharsetRule.ENCODING, beginDocRegion.getText(encodingRegion));
    }
    // setup flat container
    rule.setRangeStructuredDocumentRegion(beginDocRegion, endDocRegion);
    CSSAttrImpl attr = rule.getAttributeNode(ICSSCharsetRule.ENCODING);
    if (attr != null) {
        attr.setRangeRegion(beginDocRegion, encodingRegion, encodingRegion);
    }
    // insert to tree
    if (!fUpdateContext.isActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = fCreationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)30 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)19 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)19 Accessor (org.eclipse.wst.sse.core.tests.util.Accessor)18 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)10 Iterator (java.util.Iterator)6 ICSSRuleContainer (org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 DOMException (org.w3c.dom.DOMException)1