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.

BlockNode.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2011 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.tree;
  17. import org.w3c.css.sac.SelectorList;
  18. import com.vaadin.sass.parser.SelectorListImpl;
  19. import com.vaadin.sass.selector.SelectorUtil;
  20. import com.vaadin.sass.util.Clonable;
  21. import com.vaadin.sass.util.DeepCopy;
  22. public class BlockNode extends Node implements Clonable {
  23. private static final long serialVersionUID = 5742962631468325048L;
  24. SelectorList selectorList;
  25. public BlockNode(SelectorList selectorList) {
  26. this.selectorList = selectorList;
  27. }
  28. public SelectorList getSelectorList() {
  29. return selectorList;
  30. }
  31. public void setSelectorList(SelectorList selectorList) {
  32. this.selectorList = selectorList;
  33. }
  34. public String toString(boolean indent) {
  35. StringBuilder string = new StringBuilder();
  36. string.append(SelectorUtil.toString(selectorList));
  37. string.append(" {\n");
  38. for (Node child : children) {
  39. if (indent) {
  40. string.append("\t");
  41. }
  42. string.append("\t" + child.toString() + "\n");
  43. }
  44. if (indent) {
  45. string.append("\t");
  46. }
  47. string.append("}");
  48. return string.toString();
  49. }
  50. @Override
  51. public String toString() {
  52. return toString(false);
  53. }
  54. @Override
  55. public Object clone() throws CloneNotSupportedException {
  56. SelectorListImpl clonedSelectorList = null;
  57. if (selectorList != null) {
  58. clonedSelectorList = new SelectorListImpl();
  59. for (int i = 0; i < selectorList.getLength(); i++) {
  60. clonedSelectorList.addSelector(selectorList.item(i));
  61. }
  62. }
  63. final BlockNode clone = new BlockNode(clonedSelectorList);
  64. for (Node child : getChildren()) {
  65. clone.getChildren().add((Node) DeepCopy.copy(child));
  66. }
  67. return clone;
  68. }
  69. }