}
private ConstantDefinitions optimizeTree(CssParsingResult cssParsingResult, ResourceContext context,
boolean simplifyCss, boolean eliminateDeadStyles, TreeLogger logger)
throws UnableToCompleteException {
CssTree cssTree = cssParsingResult.tree;
// Collect mixin definitions and replace mixins
CollectMixinDefinitions collectMixinDefinitions = new CollectMixinDefinitions(
cssTree.getMutatingVisitController(), errorManager);
collectMixinDefinitions.runPass();
new ReplaceMixins(cssTree.getMutatingVisitController(), errorManager,
collectMixinDefinitions.getDefinitions()).runPass();
new ProcessComponents<Object>(cssTree.getMutatingVisitController(), errorManager).runPass();
RuntimeConditionalBlockCollector runtimeConditionalBlockCollector = new
RuntimeConditionalBlockCollector(cssTree.getVisitController());
runtimeConditionalBlockCollector.runPass();
new ExtendedEliminateConditionalNodes(cssTree.getMutatingVisitController(),
getPermutationsConditions(context, cssParsingResult.permutationAxes, logger),
runtimeConditionalBlockCollector.getRuntimeConditionalBlock()).runPass();
new ValidateRuntimeConditionalNode(cssTree.getVisitController(), errorManager,
lenientConversion).runPass();
// Don't continue if errors exist
checkErrors();
CollectConstantDefinitions collectConstantDefinitionsPass = new CollectConstantDefinitions(
cssTree);
collectConstantDefinitionsPass.runPass();
ReplaceConstantReferences replaceConstantReferences = new ReplaceConstantReferences(cssTree,
collectConstantDefinitionsPass.getConstantDefinitions(), true, errorManager, false);
replaceConstantReferences.runPass();
new ImageSpriteCreator(cssTree.getMutatingVisitController(), context, errorManager).runPass();
Map<String, GssFunction> gssFunctionMap = new GwtGssFunctionMapProvider(context).get();
new ResolveCustomFunctionNodes(cssTree.getMutatingVisitController(), errorManager,
gssFunctionMap, true, allowedNonStandardFunctions).runPass();
if (simplifyCss) {
// Eliminate empty rules.
new EliminateEmptyRulesetNodes(cssTree.getMutatingVisitController()).runPass();
// Eliminating units for zero values.
new EliminateUnitsFromZeroNumericValues(cssTree.getMutatingVisitController()).runPass();
// Optimize color values.
new ColorValueOptimizer(cssTree.getMutatingVisitController()).runPass();
// Compress redundant top-right-bottom-left value lists.
new AbbreviatePositionalValues(cssTree.getMutatingVisitController()).runPass();
}
if (eliminateDeadStyles) {
// Report errors for duplicate declarations
new DisallowDuplicateDeclarations(cssTree.getVisitController(), errorManager).runPass();
// Split rules by selector and declaration.
new SplitRulesetNodes(cssTree.getMutatingVisitController()).runPass();
// Dead code elimination.
new MarkRemovableRulesetNodes(cssTree).runPass();
new EliminateUselessRulesetNodes(cssTree).runPass();
// Merge of rules with same selector.
new MergeAdjacentRulesetNodesWithSameSelector(cssTree).runPass();