Package com.google.gwt.thirdparty.common.css.compiler.ast

Examples of com.google.gwt.thirdparty.common.css.compiler.ast.CssTree


  @Override
  public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
      throws UnableToCompleteException {
    CssParsingResult cssParsingResult = cssParsingResultMap.get(method);
    CssTree cssTree = cssParsingResult.tree;

    RenamingResult renamingResult = doClassRenaming(cssTree, method, logger, context);

    // TODO : Should we foresee configuration properties for simplifyCss and eliminateDeadCode
    // booleans ?
View Full Code Here


  }

  @Override
  protected String getCssExpression(TreeLogger logger, ResourceContext context,
      JMethod method) throws UnableToCompleteException {
    CssTree cssTree = cssParsingResultMap.get(method).tree;

    String standard = printCssTree(cssTree);

    // TODO add configuration properties for swapLtrRtlInUrl, swapLeftRightInUrl and
    // shouldFlipConstantReferences booleans
    RecordingBidiFlipper recordingBidiFlipper =
        new RecordingBidiFlipper(cssTree.getMutatingVisitController(), false, false, true);
    recordingBidiFlipper.runPass();

    if (recordingBidiFlipper.nodeFlipped()) {
      String reversed = printCssTree(cssTree);
      return LocaleInfo.class.getName() + ".getCurrentLocale().isRTL() ? "
View Full Code Here

  }

  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();
View Full Code Here

        }
        throw new UnableToCompleteException();
      }
    }

    CssTree tree;

    try {
      tree = new GssParser(sourceCodes).parse();
    } catch (GssParserException e) {
      logger.log(TreeLogger.ERROR, "Unable to parse CSS", e);
View Full Code Here

public class ExtendedEliminateConditionalNodesTest extends BaseGssTest {
  private Set<CssConditionalBlockNode> cssRuntimeConditionalBlockNodes;

  public void testCompileTimeConditional() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (is('custom.one', 'foo') && is('custom.one', 'bar')) {",
        "  .foo {",
        "    padding: 5px;",
        " }",
        "}",
        "",
        "@elseif (!is('custom.two', 'foo') && is('custom.three', 'foo') " +
            "|| is('custom.four', 'foo')) {",
        "  .foo {",
        "    padding: 15px;",
        " }",
        "}"));

    Set<String> trueConditions = Sets.newHashSet("custom.one:foo", "custom.three:foo");

    ExtendedEliminateConditionalNodes visitor =
        new ExtendedEliminateConditionalNodes(cssTree.getMutatingVisitController(),
            trueConditions, cssRuntimeConditionalBlockNodes);

    // when
    visitor.runPass();

    // then
    String expectedTreeToString = "[[.foo]{[padding:[15px]]}]";

    assertEquals(expectedTreeToString, cssTree.getRoot().getBody().toString());
  }
View Full Code Here

    assertEquals(expectedTreeToString, cssTree.getRoot().getBody().toString());
  }

  public void testIgnoreRuntimeConditional() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (eval('com.foo.BAR')) {",
        "  .foo {",
        "    padding: 5px;",
        "  }",
        "  @if (is('ie9')) {",
        "    .foo {",
        "      padding: 55px;",
        "    }",
        "  }",
        "}",
        "@elseif (eval('com.foo.bar()')) {",
        "  .foo {",
        "    padding: 15px;",
        "  }",
        "}"));

    Set<String> trueConditions = Sets.newHashSet("user.agent:ie6");
    ExtendedEliminateConditionalNodes visitor =
        new ExtendedEliminateConditionalNodes(cssTree.getMutatingVisitController(),
            trueConditions, cssRuntimeConditionalBlockNodes);

    // when
    visitor.runPass();

    // then
    // the  "  @if (is('ie9')) {", node is removed because it is evaluated to false
    String expectedTreeToString =
        "[[@if[Java expression : com.foo.BAR]{" +
            "[[.foo]{" +
            "[padding:[5px]]" +
            "}]}, " +
            "@elseif[Java expression : com.foo.bar()]{" +
            "[[.foo]{" +
            "[padding:[15px]]" +
            "}]" +
            "}]]";

    assertEquals(expectedTreeToString, cssTree.getRoot().getBody().toString());
  }
View Full Code Here

    assertEquals(expectedTreeToString, cssTree.getRoot().getBody().toString());
  }

  public void testRemoveUnreachableRuntimeConditional() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        "@if (is('foo', 'BAR')) {",
        "  .foo {",
        "    padding: 5px;",
        "  }",
        "}",
        "@elseif (eval('com.foo.bar()')) {",
        "  @if (eval('com.foo.FOO')) {",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "  @else{",
        "    .foo {",
        "      padding: 15px;",
        "    }",
        "  }",
        "}"));

    Set<String> trueConditions = Sets.newHashSet("foo:BAR");
    ExtendedEliminateConditionalNodes visitor =
        new ExtendedEliminateConditionalNodes(cssTree.getMutatingVisitController(),
            trueConditions, cssRuntimeConditionalBlockNodes);

    // when
    visitor.runPass();

    // then
    String expectedTreeToString = "[[.foo]{[padding:[5px]]}]";

    assertEquals(expectedTreeToString, cssTree.getRoot().getBody().toString());
  }
View Full Code Here

*/
public class RecordingBidiFlipperTest extends BaseGssTest {

  public void testFlipWithRuleValueIsRecorded() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".foo {",
        "  background-position: 10% 20%;",
        "}"));

    RecordingBidiFlipper visitor = new RecordingBidiFlipper(cssTree.getMutatingVisitController(),
        false, false, true);

    // when
    visitor.runPass();

View Full Code Here

    assertEquals(true, visitor.nodeFlipped());
  }

  public void testFlipWithRuleNameIsRecorded() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".foo {",
        "  padding-left: 15px;",
        "}"));

    RecordingBidiFlipper visitor = new RecordingBidiFlipper(cssTree.getMutatingVisitController(),
        false, false, true);

    // when
    visitor.runPass();
View Full Code Here

    assertEquals(true, visitor.nodeFlipped());
  }

  public void testNoFlipNothingIsRecorder() {
    // given
    CssTree cssTree = parseAndBuildTree(lines(
        ".foo {",
        "  background-color: black;",
        "  color: white;",
        "  font-size: 12px;",
        "  padding: 5px;",
        "}"));

    RecordingBidiFlipper visitor = new RecordingBidiFlipper(cssTree.getMutatingVisitController(),
        false, false, true);

    // when
    visitor.runPass();
View Full Code Here

TOP

Related Classes of com.google.gwt.thirdparty.common.css.compiler.ast.CssTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.