1 19 20 package org.netbeans.api.java.source; 21 22 import org.netbeans.api.java.source.query.Query; 23 24 28 public final class Comment { 29 private Style style; 30 private int pos; 31 private int endPos; 32 private int indent; 33 private String text; 34 35 38 public enum Style { 39 42 LINE, 43 44 47 BLOCK, 48 49 52 JAVADOC, 53 } 54 55 59 public static Comment create(String s) { 60 return new Comment(Style.BLOCK, Query.NOPOS, Query.NOPOS, Query.NOPOS, s); 61 } 62 63 public static Comment create(Style style, int pos, int endPos, int indent, String text) { 64 return new Comment(style, pos, endPos, indent, text); 65 } 66 67 70 private Comment(Style style, int pos, int endPos, int indent, String text) { 71 this.style = style; 72 this.pos = pos; 73 this.endPos = endPos; 74 this.indent = indent; 75 this.text = text; 76 } 77 78 public Style style() { 79 return style; 80 } 81 82 86 public int pos() { 87 return pos; 88 } 89 90 94 public int endPos() { 95 return endPos; 96 } 97 98 102 public int indent() { 103 return indent; 104 } 105 106 107 public boolean isDocComment() { 108 return style == Style.JAVADOC; 109 } 110 111 114 public String getText() { 115 return text; 116 } 117 118 public boolean isNew() { 119 return pos == Query.NOPOS; 120 } 121 122 public String toString() { 123 StringBuilder sb = new StringBuilder (style.toString()); 124 sb.append(" pos="); 125 sb.append(pos); 126 sb.append(" endPos="); 127 sb.append(endPos); 128 sb.append(" indent="); 129 sb.append(indent); 130 sb.append(' '); 131 sb.append(text); 132 return sb.toString(); 133 } 134 135 public boolean equals(Object obj) { 136 if (!(obj instanceof Comment)) 137 return false; 138 Comment c = (Comment)obj; 139 return c.style == style && c.pos == pos && c.endPos == endPos && 140 c.indent == indent && c.text.equals(text); 141 } 142 143 public int hashCode() { 144 return style.hashCode() + pos + endPos + indent + text.hashCode(); 145 } 146 } 147 | Popular Tags |