if (declarations == null)
declarations = new LinkedHashMap<String, StyleDeclaration>();
StyleSelector selector = declaration.getSelector();
String selectorString = selector.toString();
StyleDeclaration existingDeclaration = declarations.get(selectorString);
// This may be the first time we've seen this declaration
if (existingDeclaration == null)
{
existingDeclaration = declaration;
declarations.put(selectorString, existingDeclaration);
}
// TODO: We should resolve the differences between Descriptor and
// StyleProperty and just merge them into the same entity. Special
// processing could be done on those descriptors directly.
// Extract the properties from the declaration and record them in a
// style declaration block. We merge properties from new declaration
// blocks to existing declaration blocks because selectors can be
// declared multiple times with different properties. This is primarily
// done to avoid redundant ClassReferences when it can be determined at
// compile time that only the last occurrence of a selector with the
// same property will matter at runtime (because the last one wins).
// This helps keep SWF size down by avoiding linking in unused classes.
StyleDeclarationBlock block = existingDeclaration.getDeclarationBlock(selector, mediaList);
extractProperties(declaration, block.getProperties(), block.getEffectStyles());
// If the new declaration does not have a media list, we merge its
// properties into all other existing declaration blocks for this
// selector that have any of the same properties. This is necessary to
// ensure that later declaration blocks clobber all earlier declaration
// blocks.
if (mediaList == null)
{
Map<String, StyleProperty> properties = block.getProperties();
List<StyleDeclarationBlock> existingBlocks = existingDeclaration.getDeclarationBlocks();
for (StyleDeclarationBlock existingBlock : existingBlocks)
{
if (existingBlock != block)
{
Map<String, StyleProperty> existingProperties = existingBlock.getProperties();