Search in sources :

Example 31 with CSSTextToken

use of org.eclipse.wst.css.core.internal.parserz.CSSTextToken in project webtools.sourceediting by eclipse.

the class BorderStyleShorthandAdapter method extract.

/**
 */
public String extract(String source, PropCMProperty propDest) {
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, source);
    CSSTextToken[] tokens = parser.getTokens();
    if (tokens.length <= 0) {
        return null;
    }
    String[] idents = new String[4];
    int j = 0;
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].kind == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT)
            idents[j++] = tokens[i].image;
        if (j == 4)
            break;
    }
    if (j == 0)
        return null;
    else if (j == 1)
        return idents[0];
    else if (j == 2) {
        if (propDest.getName() == PropCMProperty.P_BORDER_TOP_STYLE || propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_STYLE)
            return idents[0];
        else
            return idents[1];
    } else if (j == 3) {
        if (propDest.getName() == PropCMProperty.P_BORDER_TOP_STYLE)
            return idents[0];
        else if (propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_STYLE)
            return idents[2];
        else
            return idents[1];
    } else {
        if (propDest.getName() == PropCMProperty.P_BORDER_TOP_STYLE)
            return idents[0];
        else if (propDest.getName() == PropCMProperty.P_BORDER_RIGHT_STYLE)
            return idents[1];
        else if (propDest.getName() == PropCMProperty.P_BORDER_BOTTOM_STYLE)
            return idents[2];
        else if (propDest.getName() == PropCMProperty.P_BORDER_LEFT_STYLE)
            return idents[3];
        else
            return null;
    }
}
Also used : CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Example 32 with CSSTextToken

use of org.eclipse.wst.css.core.internal.parserz.CSSTextToken in project webtools.sourceediting by eclipse.

the class CSSSelectorParser method appendAttribute.

/**
 */
private void appendAttribute(CSSSimpleSelector item, List tokens) {
    StringBuffer buf = new StringBuffer();
    CSSTextToken token;
    Iterator i = tokens.iterator();
    while (i.hasNext()) {
        token = (CSSTextToken) i.next();
        buf.append(token.image);
    }
    item.addAttribute(buf.toString());
}
Also used : Iterator(java.util.Iterator) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken)

Example 33 with CSSTextToken

use of org.eclipse.wst.css.core.internal.parserz.CSSTextToken in project webtools.sourceediting by eclipse.

the class CSSSelectorListImpl method parseSelectorText.

/**
 */
private void parseSelectorText() {
    fSelectors = new ArrayList();
    if (fText == null) {
        return;
    }
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_STYLESHEET, fText);
    CSSTextToken[] tokens = parser.getTokens();
    if (tokens.length <= 0) {
        return;
    }
    List tokenGroup = new ArrayList();
    for (int i = 0; i < tokens.length; i++) {
        CSSTextToken token = tokens[i];
        if (token.kind == CSSRegionContexts.CSS_SELECTOR_SEPARATOR && 0 < tokenGroup.size()) {
            ICSSSelector selector = new CSSSelector(tokenGroup);
            if (selector != null) {
                fSelectors.add(selector);
            }
            tokenGroup.clear();
        } else {
            tokenGroup.add(tokens[i]);
        }
    }
    if (0 < tokenGroup.size()) {
        ICSSSelector selector = new CSSSelector(tokenGroup);
        if (selector != null) {
            fSelectors.add(selector);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) List(java.util.List) ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ArrayList(java.util.ArrayList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Aggregations

CSSTextToken (org.eclipse.wst.css.core.internal.parserz.CSSTextToken)33 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)28 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)16 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)1 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1