use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method createCounterValue.
/**
*/
private CSSPrimitiveValueImpl createCounterValue(ITextRegionList regions) {
String funcName = getFunctionName(regions);
if (funcName == null || !funcName.toLowerCase().equals("counter")) {
// $NON-NLS-1$
return null;
}
String[] accepts = { CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT };
ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
int size = valueRegions.size();
if (size != 1 && size != 2) {
return null;
}
CounterImpl value = getCounter();
if (value == null) {
return null;
}
for (int i = 0; i < size; i++) {
ITextRegion region = valueRegions.get(i);
String text = getText(region);
CSSAttrImpl attr = null;
switch(i) {
case 0:
value.setIdentifier(text);
attr = value.getAttributeNode(ICounter.IDENTIFIER);
break;
case 1:
value.setListStyle(text);
attr = value.getAttributeNode(ICounter.LISTSTYLE);
break;
default:
break;
}
if (attr != null) {
attr.setRangeRegion(fParentRegion, region, region);
}
}
return value;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method createAttrValue.
/**
*/
private CSSPrimitiveValueImpl createAttrValue(ITextRegionList regions) {
String funcName = getFunctionName(regions);
if (funcName == null || !funcName.toLowerCase().equals("attr")) {
// $NON-NLS-1$
return null;
}
String[] accepts = { CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT };
ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
if (valueRegions.size() != 1) {
return null;
}
CSSPrimitiveValueImpl value = getCSSPrimitiveValue(CSSPrimitiveValue.CSS_ATTR);
if (value == null) {
return null;
}
ITextRegion region = valueRegions.get(0);
value.setValue(getText(region));
return value;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method createFormatValue.
/**
*/
private CSSPrimitiveValueImpl createFormatValue(ITextRegionList regions) {
String funcName = getFunctionName(regions);
if (funcName == null || !funcName.toLowerCase().equals("format")) {
// $NON-NLS-1$
return null;
}
String[] accepts = { CSSRegionContexts.CSS_DECLARATION_VALUE_STRING };
ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
// format can take variable args.
if (valueRegions.size() == 0) {
return null;
}
CSSPrimitiveValueImpl value = getCSSPrimitiveValue(ICSSPrimitiveValue.CSS_FORMAT);
if (value == null) {
return null;
}
ITextRegion region = valueRegions.get(0);
value.setValue(CSSUtil.extractStringContents(getText(region)));
return value;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSDeclarationItemParser method createCountersValue.
/**
*/
private CSSPrimitiveValueImpl createCountersValue(ITextRegionList regions) {
String funcName = getFunctionName(regions);
if (funcName == null || !funcName.toLowerCase().equals("counters")) {
// $NON-NLS-1$
return null;
}
String[] accepts = { CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT, CSSRegionContexts.CSS_DECLARATION_VALUE_STRING };
ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
int size = valueRegions.size();
if (size != 2 && size != 3) {
return null;
}
CounterImpl value = getCounter();
if (value == null) {
return null;
}
for (int i = 0; i < size; i++) {
ITextRegion region = valueRegions.get(i);
String text = getText(region);
CSSAttrImpl attr = null;
switch(i) {
case 0:
value.setIdentifier(text);
attr = value.getAttributeNode(ICounter.IDENTIFIER);
break;
case 1:
value.setSeparator(text);
attr = value.getAttributeNode(ICounter.SEPARATOR);
break;
case 2:
value.setListStyle(text);
attr = value.getAttributeNode(ICounter.LISTSTYLE);
break;
default:
break;
}
if (attr != null) {
attr.setRangeRegion(fParentRegion, region, region);
}
}
return value;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method compressEmptyElementTag.
/**
* <p>Compress empty element tags if the prefence is set to do so</p>
*
* @copyof org.eclipse.wst.xml.core.internal.cleanup.ElementNodeCleanupHandler#compressEmptyElementTag
*
* @param node the {@link IDOMNode} to possible compress
* @return the compressed node if the given node should be compressed, else the node as it was given
*/
private IDOMNode compressEmptyElementTag(IDOMNode node) {
boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags();
IDOMNode newNode = node;
IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion();
IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion();
// only compress tags if they are empty
if ((compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null)) {
// only compress end tags if its XHTML or not a container
if (isXMLTag((IDOMElement) newNode) || !newNode.isContainer()) {
ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();
ITextRegion lastRegion = regions.get(regions.size() - 1);
// format children and end tag if not empty element tag
if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
NodeList childNodes = newNode.getChildNodes();
if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) {
IDOMModel structuredModel = newNode.getModel();
IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
int startTagStartOffset = newNode.getStartOffset();
int offset = endTagStructuredDocumentRegion.getStart();
int length = endTagStructuredDocumentRegion.getLength();
// $NON-NLS-1$
structuredDocument.replaceText(structuredDocument, offset, length, "");
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart();
// $NON-NLS-1$
structuredDocument.replaceText(structuredDocument, offset, 0, "/");
// save
newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
}
}
}
}
return newNode;
}
Aggregations