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;
}
}
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);
}
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);
}
}
}
Aggregations