use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertStructuredDocumentRegion.
/**
* currently public but may be made default access protected in future.
*/
protected CSSNodeImpl insertStructuredDocumentRegion(IStructuredDocumentRegion region) {
if (fCreationContext == null || region == null) {
return null;
}
String type = ((BasicStructuredDocumentRegion) region).getType();
CSSNodeImpl modified = null;
ICSSNode target = fCreationContext.getTargetNode();
if ((fParseFloating && target == null) || target instanceof ICSSRuleContainer) {
if (type == CSSRegionContexts.CSS_DELIMITER) {
modified = insertSemiColonForRule(region);
} else if (type == CSSRegionContexts.CSS_LBRACE) {
modified = insertBraceOpen(region);
} else if (type == CSSRegionContexts.CSS_RBRACE) {
modified = insertBraceClose(region);
} else if (type == CSSRegionContexts.CSS_MEDIA || type == CSSRegionContexts.CSS_PAGE || type == CSSRegionContexts.CSS_FONT_FACE || CSSUtil.isSelectorText(region)) {
checkNextNode(region, CSSRegionContexts.CSS_LBRACE);
} else if (type == CSSRegionContexts.CSS_IMPORT || type == CSSRegionContexts.CSS_CHARSET) {
checkNextNode(region, CSSRegionContexts.CSS_DELIMITER);
}
} else if ((target instanceof CSSRuleDeclContainer || target instanceof CSSStyleDeclaration) && type == CSSRegionContexts.CSS_DECLARATION_PROPERTY) {
modified = insertStyleDeclarationItem(region);
} else if (target instanceof ICSSStyleDeclItem && type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
modified = insertSemiColonForStyleDeclarationItem(region);
} else if (type == CSSRegionContexts.CSS_RBRACE) {
modified = insertBraceClose(region);
}
// post process
if (modified != null) {
if (modified instanceof CSSStructuredDocumentRegionContainer) {
((CSSStructuredDocumentRegionContainer) modified).propagateRangeStructuredDocumentRegion();
}
}
return modified;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer 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;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertStyleRule.
/**
*/
private CSSNodeImpl insertStyleRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
// get selector regions
ITextRegionList selectorRegions = new TextRegionListImpl(flatNode.getRegions());
CSSUtil.stripSurroundingSpace(selectorRegions);
CSSStyleRuleImpl rule = fFeeder.getCSSStyleRule();
if (rule == null) {
return null;
}
if (!fUpdateContext.isActive()) {
String selectorStr = CSSUtil.getRegionText(flatNode, selectorRegions);
if (selectorStr != null && 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;
}
Aggregations