Example usage for com.google.common.css.compiler.ast CssDeclarationNode getPropertyValue

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

Introduction

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

Prototype

public CssPropertyValueNode getPropertyValue() 

Source Link

Usage

From source file:com.google.gwt.resources.gss.ImageSpriteCreator.java

private void createSprite(CssDeclarationNode declaration) {
    List<CssValueNode> valuesNodes = declaration.getPropertyValue().getChildren();

    if (valuesNodes.size() != 1) {
        errorManager.report(new GssError(SPRITE_PROPERTY_NAME + " must have exactly one value",
                declaration.getSourceCodeLocation()));
    }//from   w w  w. j  a va 2 s  . co m

    String imageResource = valuesNodes.get(0).getValue();

    JMethod imageMethod;
    try {
        imageMethod = ResourceGeneratorUtil.getMethodByPath(context.getClientBundleType(),
                getPathElement(imageResource), imageResourceType);
    } catch (NotFoundException e) {
        errorManager.report(new GssError(
                "Unable to find ImageResource method " + imageResource + " in "
                        + context.getClientBundleType().getQualifiedSourceName() + " : " + e.getMessage(),
                declaration.getSourceCodeLocation()));
        return;
    }

    ImageOptions options = imageMethod.getAnnotation(ImageOptions.class);
    RepeatStyle repeatStyle = options != null ? options.repeatStyle() : RepeatStyle.None;

    Builder<CssDeclarationNode> listBuilder = ImmutableList.builder();
    SourceCodeLocation sourceCodeLocation = declaration.getSourceCodeLocation();

    String repeatText;
    switch (repeatStyle) {
    case None:
        repeatText = " no-repeat";
        listBuilder.add(buildHeightDeclaration(imageResource, sourceCodeLocation));
        listBuilder.add(buildWidthDeclaration(imageResource, sourceCodeLocation));
        break;
    case Horizontal:
        repeatText = " repeat-x";
        listBuilder.add(buildHeightDeclaration(imageResource, sourceCodeLocation));
        break;
    case Vertical:
        repeatText = " repeat-y";
        listBuilder.add(buildWidthDeclaration(imageResource, sourceCodeLocation));
        break;
    case Both:
        repeatText = " repeat";
        break;
    default:
        errorManager.report(new GssError("Unknown repeatStyle " + repeatStyle, sourceCodeLocation));
        return;
    }

    listBuilder.add(buildOverflowDeclaration(sourceCodeLocation));
    listBuilder.add(buildBackgroundDeclaration(imageResource, repeatText, sourceCodeLocation));

    visitController.replaceCurrentBlockChildWith(listBuilder.build(), false);
}