1 19 package org.netbeans.modules.java.source.builder; 20 21 import org.netbeans.api.java.source.Comment; 22 import org.netbeans.api.java.source.query.CommentSet; 23 import org.netbeans.api.java.source.query.Query; 24 import com.sun.source.tree.Tree; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 31 public class CommentSetImpl implements Cloneable , CommentSet { 32 Tree tree; 33 List <Comment> precedingComments = new ArrayList <Comment>(); 34 List <Comment> trailingComments = new ArrayList <Comment>(); 35 36 39 public void addPrecedingComment(String s) { 40 addPrecedingComment(Comment.create(s)); 41 } 42 43 46 public void addPrecedingComment(Comment c) { 47 precedingComments.add(c); 48 } 49 50 53 public void addPrecedingComments(List <Comment> comments) { 54 precedingComments.addAll(comments); 55 } 56 57 60 public void addTrailingComment(String s) { 61 addTrailingComment(Comment.create(s)); 62 } 63 64 67 public void addTrailingComment(Comment c) { 68 trailingComments.add(c); 69 } 70 71 74 public void addTrailingComments(List <Comment> comments) { 75 trailingComments.addAll(comments); 76 } 77 78 public List <Comment> getPrecedingComments() { 79 return precedingComments; 80 } 81 82 public List <Comment> getTrailingComments() { 83 return trailingComments; 84 } 85 86 public boolean hasComments() { 87 return precedingComments.size() > 0 || trailingComments.size() > 0; 88 } 89 90 96 public int pos() { 97 return precedingComments.size() > 0 ? 98 precedingComments.get(0).pos() : Query.NOPOS; 99 } 100 101 void setTree(Tree newTree) { 102 tree = newTree; 103 } 104 105 public boolean hasChanges() { 106 for (Comment c : precedingComments) 107 if (c.isNew()) 108 return true; 109 for (Comment c : trailingComments) 110 if (c.isNew()) 111 return true; 112 return false; 113 } 114 115 public Object clone() { 116 try { 117 return super.clone(); 118 } catch (CloneNotSupportedException e) { 119 throw new InternalError ("Unexpected " + e); 120 } 121 } 122 123 public String toString() { 124 StringBuffer sb = new StringBuffer (); 125 boolean first = true; 126 sb.append('{'); 127 for (Comment c : precedingComments) { 128 if (!first) 129 sb.append(','); 130 sb.append(c.getText()); 131 first = false; 132 } 133 for (Comment c : trailingComments) { 134 if (!first) 135 sb.append(','); 136 sb.append(c.getText()); 137 first = false; 138 } 139 sb.append('}'); 140 return sb.toString(); 141 } 142 } 143 | Popular Tags |