in compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java [386:659]
private String encodeRule(ICSSRule rule)
{
final StringBuilder result = new StringBuilder();
ImmutableList<ICSSMediaQueryCondition> mqlist = rule.getMediaQueryConditions();
int n = mqlist.size();
if (n > 0)
{
if (mqlist.get(0).toString().equals("-royale-swf"))
return null;
result.append(n);
for (ICSSMediaQueryCondition mqcond : mqlist)
{
result.append(",\n");
result.append("\"" + mqcond.toString() + "\"");
}
}
else
result.append(n);
result.append(",\n");
ImmutableList<ICSSSelector> slist = rule.getSelectorGroup();
result.append(slist.size());
for (ICSSSelector sel : slist)
{
result.append(",\n");
String selName = this.resolvedSelectors.get(sel);
if (selName == null || selName.equals("null"))
result.append("\"" + escapeDoubleQuotes(sel.toString()) + "\"");
else
{
selName = formatQualifiedName(selName);
ImmutableList<ICSSSelectorCondition> conds = sel.getConditions();
for (ICSSSelectorCondition cond : conds)
{
String condString = escapeDoubleQuotes(cond.toString());
selName += condString;
}
result.append("\"" + selName + "\"");
}
}
result.append(",\n");
result.append("function() {");
ArrayList<String> listOfProps = new ArrayList<String>();
for (final ICSSProperty prop : rule.getProperties())
{
StringBuilder line = new StringBuilder();
line.append("this[\"" + prop.getName() + "\"] = ");
ICSSPropertyValue value = prop.getValue();
if (value instanceof CSSArrayPropertyValue)
{
ImmutableList<? extends ICSSPropertyValue> values = ((CSSArrayPropertyValue)value).getElements();
line.append("[");
boolean firstone = true;
for (ICSSPropertyValue val : values)
{
if (firstone)
firstone = false;
else
line.append(", ");
if (val instanceof CSSStringPropertyValue)
{
line.append("\"" + escapeDoubleQuotes(((CSSStringPropertyValue)val).getValue()) + "\"");
}
else if (val instanceof CSSColorPropertyValue)
{
line.append(Integer.valueOf(((CSSColorPropertyValue)val).getColorAsInt()));
}
else if (val instanceof CSSRgbColorPropertyValue)
{
line.append(Integer.valueOf(((CSSRgbColorPropertyValue)val).getColorAsInt()));
}
else if (value instanceof CSSRgbaColorPropertyValue)
{
//todo: handle alpha in the RGBA ?
line.append(Long.valueOf(((CSSRgbaColorPropertyValue)value).getColorAsLong()));
}
else if (val instanceof CSSKeywordPropertyValue)
{
CSSKeywordPropertyValue keywordValue = (CSSKeywordPropertyValue)val;
String keywordString = keywordValue.getKeyword();
if (IASLanguageConstants.TRUE.equals(keywordString))
line.append("true");
else if (IASLanguageConstants.FALSE.equals(keywordString))
line.append("false");
else
line.append("\"" + ((CSSKeywordPropertyValue)val).getKeyword() + "\"");
}
else if (val instanceof CSSNumberPropertyValue)
{
line.append(Double.valueOf(((CSSNumberPropertyValue)val).getNumber().doubleValue()));
}
else if (val instanceof CSSURLAndFormatPropertyValue)
{
line.append("\"" + escapeDoubleQuotes(((CSSURLAndFormatPropertyValue)val).toString()) + "\"");
}
else if (val instanceof CSSMultiValuePropertyValue)
{
line.append("\"" + ((CSSMultiValuePropertyValue)val).toString() + "\"");
}
else
{
line.append("unexpected value type: " + val.toString());
}
}
line.append("]");
}
else if (value instanceof CSSMultiValuePropertyValue)
{
ImmutableList<? extends ICSSPropertyValue> values = ((CSSMultiValuePropertyValue)value).getElements();
line.append("[");
boolean firstone = true;
for (ICSSPropertyValue val : values)
{
if (firstone)
firstone = false;
else
line.append(", ");
if (val instanceof CSSStringPropertyValue)
{
line.append("\"" + escapeDoubleQuotes(((CSSStringPropertyValue)val).getValue()) + "\"");
}
else if (val instanceof CSSColorPropertyValue)
{
line.append(Integer.valueOf(((CSSColorPropertyValue)val).getColorAsInt()));
}
else if (val instanceof CSSRgbColorPropertyValue)
{
line.append(Integer.valueOf(((CSSRgbColorPropertyValue)val).getColorAsInt()));
}
else if (val instanceof CSSRgbaColorPropertyValue)
{
//todo: handle alpha in the RGBA ?
line.append(Long.valueOf(((CSSRgbaColorPropertyValue)val).getColorAsLong()));
}
else if (val instanceof CSSKeywordPropertyValue)
{
CSSKeywordPropertyValue keywordValue = (CSSKeywordPropertyValue)val;
String keywordString = keywordValue.getKeyword();
if (IASLanguageConstants.TRUE.equals(keywordString))
line.append("true");
else if (IASLanguageConstants.FALSE.equals(keywordString))
line.append("false");
else
line.append("\"" + ((CSSKeywordPropertyValue)val).getKeyword() + "\"");
}
else if (val instanceof CSSNumberPropertyValue)
{
line.append(Double.valueOf(((CSSNumberPropertyValue)val).getNumber().doubleValue()));
}
else if (val instanceof CSSURLAndFormatPropertyValue)
{
line.append("\"" + escapeDoubleQuotes(((CSSURLAndFormatPropertyValue)val).toString()) + "\"");
}
else if (val instanceof CSSMultiValuePropertyValue)
{
line.append("\"" + ((CSSMultiValuePropertyValue)val).toString() + "\"");
}
else
{
line.append("unexpected value type: " + val.toString());
}
}
line.append("]");
}
else if (value instanceof CSSStringPropertyValue)
{
line.append("\"" + replaceUnicodeEncoded(((CSSStringPropertyValue)value).getValue()) + "\"");
}
else if (value instanceof CSSColorPropertyValue)
{
line.append(Integer.valueOf(((CSSColorPropertyValue)value).getColorAsInt()));
}
else if (value instanceof CSSRgbColorPropertyValue)
{
line.append(Integer.valueOf(((CSSRgbColorPropertyValue)value).getColorAsInt()));
}
else if (value instanceof CSSRgbaColorPropertyValue)
{
//todo: handle alpha in the RGBA ?
line.append(Long.valueOf(((CSSRgbaColorPropertyValue)value).getColorAsLong()));
}
else if (value instanceof CSSKeywordPropertyValue)
{
CSSKeywordPropertyValue keywordValue = (CSSKeywordPropertyValue)value;
String keywordString = keywordValue.getKeyword();
if (IASLanguageConstants.TRUE.equals(keywordString))
line.append("true");
else if (IASLanguageConstants.FALSE.equals(keywordString))
line.append("false");
else
line.append("\"" + ((CSSKeywordPropertyValue)value).getKeyword() + "\"");
}
else if (value instanceof CSSNumberPropertyValue)
{
line.append(Double.valueOf(((CSSNumberPropertyValue)value).getNumber().doubleValue()));
}
else if (value instanceof CSSFunctionCallPropertyValue)
{
final CSSFunctionCallPropertyValue functionCall = (CSSFunctionCallPropertyValue)value;
if ("ClassReference".equals(functionCall.name))
{
final String className = CSSFunctionCallPropertyValue.getSingleArgumentFromRaw(functionCall.rawArguments);
if ("null".equals(className))
{
// ClassReference(null) resets the property's class reference.
line.append("null");
}
else
{
line.append(formatQualifiedName(className));
requires.add(className);
}
}
else if ("url".equals(functionCall.name))
{
final String urlString = CSSFunctionCallPropertyValue.getSingleArgumentFromRaw(functionCall.rawArguments);
line.append("\"" + urlString + "\"");
}
else if ("PropertyReference".equals(functionCall.name))
{
// TODO: implement me
}
else if ("calc".equals(functionCall.name))
{
// TODO: implement me
line.append("null");
}
else if ("var".equals(functionCall.name))
{
// TODO: implement me
line.append("null");
}
else if ("Embed".equals(functionCall.name))
{
// TODO: implement me
/*
final ICompilerProblem e = new CSSCodeGenProblem(
new IllegalStateException("Unable to find compilation unit for " + functionCall));
problems.add(e);
*/
}
else if (otherCSSFunctions.contains(functionCall.name))
{
// ignore for now?
line.append("null");
}
else
{
assert false : "CSS parser bug: unexpected function call property value: " + functionCall;
throw new IllegalStateException("Unexpected function call property value: " + functionCall);
}
}
listOfProps.add(line.toString());
}
Collections.sort(listOfProps);
boolean firstProp = true;
for (final String line2 : listOfProps)
{
if (!firstProp)
result.append(";\n");
firstProp = false;
result.append(line2);
}
result.append("}");
return result.toString();
}