use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl 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;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSStyleDeclItemImpl method setCssValueTextCore.
private void setCssValueTextCore(String value) throws DOMException {
CSSSourceParser parser = new CSSSourceParser();
parser.setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
parser.reset(value);
IStructuredDocumentRegion node = parser.getDocumentRegions();
if (node == null) {
return;
}
if (node.getNext() != null) {
// $NON-NLS-1$
throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "");
}
CSSDeclarationItemParser itemParser = new CSSDeclarationItemParser(getOwnerDocument());
itemParser.setStructuredDocumentTemporary(true);
// make a copy of nodelist because setupValues will destroy list
ITextRegionList nodeList = new TextRegionListImpl(node.getRegions());
List nodeValuesList = new ArrayList();
;
for (int i = 0; i < nodeList.size(); i++) {
ITextRegion textRegion = nodeList.get(i);
nodeValuesList.add(value.substring(textRegion.getStart(), textRegion.getTextEnd()));
}
itemParser.setupValues(this, node, nodeList, nodeValuesList);
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method getFunctionParameters.
/**
* this method has no validation check, then regions must be passed
* getFunctionName()...
*/
private ITextRegionList getFunctionParameters(ITextRegionList regions, String[] accepts) {
ITextRegionList newRegions = new TextRegionListImpl();
int nAccepts = (accepts != null) ? accepts.length : 0;
Iterator i = regions.iterator();
// skip FUNCTION
i.next();
while (i.hasNext()) {
ITextRegion region = (ITextRegion) i.next();
if (region == null) {
continue;
}
String type = region.getType();
if (isBlank(type)) {
continue;
}
if (nAccepts == 0) {
newRegions.add(region);
} else {
for (int iAccept = 0; iAccept < nAccepts; iAccept++) {
if (type == accepts[iAccept]) {
newRegions.add(region);
break;
}
}
}
}
return newRegions;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method setupDeclarationItem.
/**
*/
CSSStyleDeclItemImpl setupDeclarationItem(IStructuredDocumentRegion flatNode) {
if (flatNode == null) {
return null;
}
if (!hasColonSeparator(flatNode)) {
return null;
}
fParentRegion = flatNode;
// make
ITextRegionList nodeRegions = new TextRegionListImpl(flatNode.getRegions());
// copy
CSSStyleDeclItemImpl newItem = createDeclarationItem(nodeRegions);
if (newItem == null) {
return null;
}
if (!fTempStructuredDocument && flatNode != null) {
newItem.setRangeStructuredDocumentRegion(flatNode, flatNode);
}
CSSUtil.stripSurroundingSpace(nodeRegions);
// Now, nodeRegions just has regions for value.
setupValues(newItem, nodeRegions, null);
return newItem;
}
use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method setupValues.
/**
* nodeRegions must be broken. If you need after, make copy of them.
*/
private void setupValues(ICSSStyleDeclItem item, ITextRegionList nodeRegions, List propertyValueList) {
if (item == null) {
return;
}
ICSSPrimitiveValue value;
ITextRegionList regionBuf = new TextRegionListImpl();
String propertyName = item.getPropertyName().toLowerCase();
boolean bFont = (propertyName.equals(PropCMProperty.P_FONT));
// (short-hand) font
String propertyValue = null;
int status = (propertyName.equals(PropCMProperty.P_VOICE_FAMILY) || propertyName.equals(PropCMProperty.P_FONT_FAMILY)) ? S_COMMA_SEPARATION : S_NORMAL;
while (!nodeRegions.isEmpty()) {
value = null;
ITextRegion region = nodeRegions.remove(0);
if (region == null) {
continue;
}
if (propertyValueList != null && !propertyValueList.isEmpty()) {
propertyValue = (String) propertyValueList.remove(0);
}
String type = region.getType();
// }
switch(status) {
case S_NORMAL:
if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) {
regionBuf.add(region);
regionValues.put(region, propertyValue);
status = S_FUNCTION;
} else if (bFont && type == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR && isValueRegionEqual(region, propertyValue, "/")) {
// $NON-NLS-1$
value = createPrimitiveValue(region, propertyValue);
status = S_FONT_SLASH;
} else if (!isBlank(type)) {
value = createPrimitiveValue(region, propertyValue);
}
break;
case S_FUNCTION:
if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE) {
regionBuf.add(region);
regionValues.put(region, propertyValue);
value = createPrimitiveValue(regionBuf);
regionBuf.clear();
regionValues.clear();
status = S_NORMAL;
} else if (!isBlank(type)) {
regionBuf.add(region);
regionValues.put(region, propertyValue);
}
break;
case S_FONT_SLASH:
if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_DIMENSION) {
value = createPrimitiveValue(region, propertyValue);
status = S_COMMA_SEPARATION;
} else if (!isBlank(type)) {
value = createPrimitiveValue(region, propertyValue);
}
break;
case S_COMMA_SEPARATION:
if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR && isValueRegionEqual(region, propertyValue, ",")) {
// $NON-NLS-1$
value = createPrimitiveValue(regionBuf);
regionBuf.clear();
regionValues.clear();
if (value != null) {
if (fUpdateContext == null || !fUpdateContext.isActive()) {
item.appendValue(value);
}
}
value = createPrimitiveValue(region, propertyValue);
} else {
regionBuf.add(region);
regionValues.put(region, propertyValue);
}
break;
default:
break;
}
if (value != null) {
if (fUpdateContext == null || !fUpdateContext.isActive()) {
item.appendValue(value);
}
}
}
if (!regionBuf.isEmpty()) {
value = createPrimitiveValue(regionBuf);
if (fUpdateContext == null || !fUpdateContext.isActive()) {
item.appendValue(value);
}
regionBuf.clear();
regionValues.clear();
}
}
Aggregations