use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertPageRule.
/**
*/
private CSSNodeImpl insertPageRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
// get selector regions
ITextRegionList selectorRegions = new TextRegionListImpl(flatNode.getRegions());
// must be "@page"
selectorRegions.remove(0);
CSSUtil.stripSurroundingSpace(selectorRegions);
CSSPageRuleImpl rule = fFeeder.getCSSPageRule();
if (rule == null) {
return null;
}
if (!fUpdateContext.isActive()) {
String selectorStr = CSSUtil.getRegionText(flatNode, selectorRegions);
if (0 < selectorStr.length()) {
rule.setSelectorText(selectorStr);
}
}
// setup flat container
rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
CSSAttrImpl attr = rule.getAttributeNode(ICSSPageRule.SELECTOR);
if (attr != null && selectorRegions != null && !selectorRegions.isEmpty()) {
attr.setRangeRegion(flatNode, selectorRegions.get(0), selectorRegions.get(selectorRegions.size() - 1));
}
// 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);
}
}
fCreationContext.setTargetNode(rule);
return rule;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertImportRule.
/**
*/
private CSSNodeImpl insertImportRule(IStructuredDocumentRegion beginDocRegion, IStructuredDocumentRegion endDocRegion) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
ITextRegionList regions = new TextRegionListImpl(beginDocRegion.getRegions());
// must be "@import"
regions.remove(0);
ITextRegion hrefRegion = 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_URI || type == CSSRegionContexts.CSS_STRING) {
hrefRegion = textRegion;
break;
} else {
break;
}
}
if (hrefRegion == null) {
return null;
}
CSSImportRuleImpl rule = fFeeder.getCSSImportRule();
if (rule == null) {
return null;
}
CSSUtil.stripSurroundingSpace(regions);
MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
setMediaList(mediaList, beginDocRegion, regions);
if (!fUpdateContext.isActive()) {
rule.setAttribute(ICSSImportRule.HREF, beginDocRegion.getText(hrefRegion));
}
// setup flat container
rule.setRangeStructuredDocumentRegion(beginDocRegion, endDocRegion);
CSSAttrImpl attr = rule.getAttributeNode(ICSSImportRule.HREF);
if (attr != null) {
attr.setRangeRegion(beginDocRegion, hrefRegion, hrefRegion);
}
// 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;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertMediaRule.
/**
*/
private CSSNodeImpl insertMediaRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
CSSMediaRuleImpl rule = fFeeder.getCSSMediaRule();
if (rule == null) {
return null;
}
ITextRegionList regions = new TextRegionListImpl(flatNode.getRegions());
// must be "@media"
regions.remove(0);
CSSUtil.stripSurroundingSpace(regions);
MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
setMediaList(mediaList, flatNode, regions);
// setup flat container
rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
// 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);
}
}
fCreationContext.setTargetNode(rule);
return rule;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class TestRegionList method test_indexOf.
public void test_indexOf() {
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, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
assertTrue("region not added", added);
assertEquals("count was wrong", 2, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
assertTrue("region not added", added);
assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
assertEquals("wrong object", 0, impl.indexOf(regions[0]));
assertEquals("wrong object", 1, impl.indexOf(regions[1]));
assertEquals("wrong object", 2, impl.indexOf(regions[2]));
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class TestRegionList method test_getOver.
public void test_getOver() {
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, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
assertTrue("region not added", added);
assertEquals("count was wrong", 2, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
assertTrue("region not added", added);
assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
assertEquals("wrong object", regions[0], impl.get(0));
assertEquals("wrong object", regions[1], impl.get(1));
assertEquals("wrong object", regions[2], impl.get(2));
ArrayIndexOutOfBoundsException e = null;
try {
impl.get(impl.size());
} catch (ArrayIndexOutOfBoundsException e2) {
e = e2;
}
assertNotNull("no ArrayIndexOutOfBoundsException thrown when expected", e);
}
Aggregations