com.google.common.css.compiler.passes.PassRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of closure-stylesheets Show documentation
Show all versions of closure-stylesheets Show documentation
Closure Stylesheets is an extension to CSS that adds variables,
functions,
conditionals, and mixins to standard CSS. The tool also supports
minification, linting, RTL flipping, and CSS class renaming.
/*
* Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.css.compiler.passes;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.css.JobDescription;
import com.google.common.css.PrefixingSubstitutionMap;
import com.google.common.css.RecordingSubstitutionMap;
import com.google.common.css.SubstitutionMap;
import com.google.common.css.compiler.ast.CssCompilerPass;
import com.google.common.css.compiler.ast.CssTree;
import com.google.common.css.compiler.ast.ErrorManager;
import com.google.common.css.compiler.ast.GssFunction;
import java.util.Map;
import javax.annotation.Nullable;
/**
* {@link PassRunner} runs applies a sequence of {@link CssCompilerPass}es to a
* {@link CssTree}.
*
* @author [email protected] (Michael Bolin)
*/
public class PassRunner {
private static final ImmutableMap
EMPTY_GSS_FUNCTION_MAP = ImmutableMap.of();
private final JobDescription job;
private final ErrorManager errorManager;
private final RecordingSubstitutionMap recordingSubstitutionMap;
public PassRunner(JobDescription job, ErrorManager errorManager) {
this(job, errorManager, createSubstitutionMap(job));
}
public PassRunner(JobDescription job, ErrorManager errorManager,
RecordingSubstitutionMap recordingSubstitutionMap) {
this.job = job;
this.errorManager = errorManager;
this.recordingSubstitutionMap = recordingSubstitutionMap;
}
/**
* Runs the passes on the specified {@link CssTree}. This method may be
* invoked multiple times, as one compilation job may have one {@link CssTree}
* per input file.
*/
public void runPasses(CssTree cssTree) {
new CheckDependencyNodes(cssTree.getMutatingVisitController(),
errorManager, job.suppressDependencyCheck).runPass();
new CreateStandardAtRuleNodes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new CreateMixins(cssTree.getMutatingVisitController(),
errorManager).runPass();
new CreateDefinitionNodes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new CreateConstantReferences(cssTree.getMutatingVisitController())
.runPass();
new CreateConditionalNodes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new CreateForLoopNodes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new CreateComponentNodes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new ValidatePropertyValues(cssTree.getVisitController(), errorManager).runPass();
new HandleUnknownAtRuleNodes(cssTree.getMutatingVisitController(),
errorManager, job.allowedAtRules,
true /* report */, false /* remove */).runPass();
new ProcessKeyframes(cssTree.getMutatingVisitController(),
errorManager, job.allowKeyframes || job.allowWebkitKeyframes,
job.simplifyCss).runPass();
new CreateVendorPrefixedKeyframes(cssTree.getMutatingVisitController(),
errorManager).runPass();
new EvaluateCompileConstants(cssTree.getMutatingVisitController(),
job.compileConstants).runPass();
new UnrollLoops(cssTree.getMutatingVisitController(), errorManager).runPass();
new ProcessRefiners(cssTree.getMutatingVisitController(), errorManager,
job.simplifyCss).runPass();
// Eliminate conditional nodes.
new EliminateConditionalNodes(
cssTree.getMutatingVisitController(),
ImmutableSet.copyOf(job.trueConditionNames)).runPass();
// 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