Search in sources :

Example 31 with CSSTextParser

use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser 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 CSSTextParser

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

the class CSSTextParserTest method textParserTest.

private void textParserTest(String filename) throws IOException {
    // $NON-NLS-1$
    String source = createString(filename);
    CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_STYLESHEET, source);
    String result = dumpRegions(parser.getTokenList());
    // $NON-NLS-1$
    compareResult(result, "CSSTextParserTest-" + filename);
}
Also used : CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser)

Example 33 with CSSTextParser

use of org.eclipse.wst.css.core.internal.parserz.CSSTextParser 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

CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)33 CSSTextToken (org.eclipse.wst.css.core.internal.parserz.CSSTextToken)28 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)18 Iterator (java.util.Iterator)3 Collection (java.util.Collection)2 List (java.util.List)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 ICSSValueList (org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)2 ArrayList (java.util.ArrayList)1 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