Example usage for com.google.common.css.compiler.ast BasicErrorManager BasicErrorManager

List of usage examples for com.google.common.css.compiler.ast BasicErrorManager BasicErrorManager

Introduction

In this page you can find the example usage for com.google.common.css.compiler.ast BasicErrorManager BasicErrorManager.

Prototype

BasicErrorManager

Source Link

Usage

From source file:io.bazel.rules.closure.webfiles.WebfilesValidator.java

private void validateCss(final Path path, final Webpath origin, String source) {
    CssTree stylesheet = cssParser.parse(path.toString(), source);
    new PassRunner(new JobDescriptionBuilder().getJobDescription(), new BasicErrorManager() {
        @Override//from   w w w  .jav  a 2 s .c  o m
        public void print(String message) {
            WebfilesValidator.this.errors.put(CSS_VALIDATION_ERROR, String.format("%s: %s", path, message));
        }
    }).runPasses(stylesheet);
    stylesheet.getVisitController().startVisit(new DefaultTreeVisitor() {
        private boolean inUrlFunction;

        @Override
        public boolean enterFunctionNode(CssFunctionNode function) {
            return (inUrlFunction = function.getFunction().getFunctionName().equals("url"));
        }

        @Override
        public void leaveFunctionNode(CssFunctionNode value) {
            inUrlFunction = false;
        }

        @Override
        public boolean enterArgumentNode(CssValueNode argument) {
            if (inUrlFunction) {
                String uri = nullToEmpty(argument.getValue());
                if (!shouldIgnoreUri(uri)) {
                    addRelationship(path, origin, Webpath.get(uri));
                }
            }
            return false;
        }
    });
}