PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/XML/sidekick/css/parser/CSSNode.java

#
Java | 117 lines | 94 code | 23 blank | 0 comment | 14 complexity | ed045ce733b912c5fe05f119cf8e45d0 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. package sidekick.css.parser;
  2. import java.util.*;
  3. import javax.swing.text.Position;
  4. import sidekick.util.*;
  5. import org.gjt.sp.jedit.jEdit;
  6. public class CSSNode implements SideKickElement, Comparable<CSSNode> {
  7. private String name = "";
  8. private List<CSSNode> children = new ArrayList<CSSNode>();
  9. private Location start = null;
  10. private Location end = null;
  11. private Position startPosition = null;
  12. private Position endPosition = null;
  13. public CSSNode() {}
  14. public CSSNode( String name ) {
  15. this.name = name;
  16. }
  17. public void setName( String name ) {
  18. if ( name != null ) {
  19. this.name = name;
  20. }
  21. }
  22. public String getName() {
  23. return name;
  24. }
  25. public String toString() {
  26. String name = getName();
  27. if (jEdit.getBooleanProperty( "sidekick.css.showLineNums", false )) {
  28. StringBuilder sb = new StringBuilder();
  29. sb.append(getStartLocation().line).append(": ").append(name);
  30. name = sb.toString();
  31. }
  32. return name;
  33. }
  34. public void setStartLocation( Location loc ) {
  35. start = loc;
  36. }
  37. public Location getStartLocation() {
  38. if ( start == null ) {
  39. start = new Location();
  40. }
  41. return start;
  42. }
  43. public void setEndLocation( Location loc ) {
  44. end = loc;
  45. }
  46. public Location getEndLocation() {
  47. if ( end == null ) {
  48. end = new Location();
  49. }
  50. return end;
  51. }
  52. public void setStartPosition( Position s ) {
  53. startPosition = s;
  54. }
  55. public Position getStartPosition() {
  56. return startPosition;
  57. }
  58. public void setEndPosition( Position s ) {
  59. endPosition = s;
  60. }
  61. public Position getEndPosition() {
  62. return endPosition;
  63. }
  64. public void addChild( CSSNode child ) {
  65. children.add( child );
  66. }
  67. public void addChildren( List<CSSNode> kids ) {
  68. children.addAll( kids );
  69. }
  70. public List<CSSNode> getChildren() {
  71. Collections.sort(children);
  72. return children;
  73. }
  74. public boolean hasChildren() {
  75. return children != null && children.size() > 0;
  76. }
  77. public boolean equals( Object o ) {
  78. return getName().equals( o ) && getChildren().equals(((CSSNode)o).getChildren());
  79. }
  80. public int hashCode() {
  81. return getName().hashCode();
  82. }
  83. public int compareTo( CSSNode node ) {
  84. String my_name = getName().toLowerCase();
  85. if ( my_name.startsWith( "." ) || my_name.startsWith( "#" ) ) {
  86. my_name = my_name.substring( 1 );
  87. }
  88. String your_name = node.getName().toLowerCase();
  89. if ( your_name.startsWith( "." ) || your_name.startsWith( "#" ) ) {
  90. your_name = your_name.substring( 1 );
  91. }
  92. return my_name.compareTo( your_name );
  93. }
  94. }