You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SimpleNode.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.sass.internal.tree;
  17. import java.util.ArrayList;
  18. import com.vaadin.sass.internal.ScssStylesheet;
  19. import com.vaadin.sass.internal.util.StringUtil;
  20. /**
  21. * A simple BlockNode where input text equals output. <b>Note : </b> ignores any
  22. * possible children so only use it when you are sure no child nodes will be
  23. * applied.
  24. *
  25. * @author Sebastian Nyholm @ Vaadin Ltd
  26. *
  27. */
  28. public class SimpleNode extends Node implements IVariableNode {
  29. private String text;
  30. public SimpleNode(String text) {
  31. this.text = text;
  32. }
  33. @Override
  34. public String printState() {
  35. return text;
  36. }
  37. @Override
  38. public String toString() {
  39. return printState();
  40. }
  41. @Override
  42. public void replaceVariables(ArrayList<VariableNode> variables) {
  43. for (final VariableNode node : variables) {
  44. if (StringUtil.containsVariable(text, node.getName())) {
  45. text = StringUtil.replaceVariable(text, node.getName(), node
  46. .getExpr().printState());
  47. }
  48. }
  49. }
  50. @Override
  51. public void traverse() {
  52. replaceVariables(ScssStylesheet.getVariables());
  53. }
  54. }