Search in sources :

Example 46 with ITextRegionList

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 47 with ITextRegionList

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 48 with ITextRegionList

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 49 with ITextRegionList

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 50 with ITextRegionList

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Aggregations

ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)193 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)171 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)74 Iterator (java.util.Iterator)46 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)27 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)24 ArrayList (java.util.ArrayList)21 List (java.util.List)18 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)16 StyleRange (org.eclipse.swt.custom.StyleRange)13 TextAttribute (org.eclipse.jface.text.TextAttribute)12 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)12 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)9 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8 DOMException (org.w3c.dom.DOMException)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)7