Search in sources :

Example 11 with ICSSPrimitiveValue

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

Aggregations

ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)11 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)6 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)2 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)2 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)2 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 ICSSValueList (org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSRegionContainer (org.eclipse.wst.css.core.internal.document.CSSRegionContainer)1 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)1 ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)1