1 19 20 package org.netbeans.spi.editor.hints; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.text.Position ; 25 import org.openide.filesystems.FileObject; 26 27 44 public final class ChangeInfo { 45 private List <Change> changes = null; 46 47 49 public ChangeInfo(FileObject fileObject, Position start, Position end) { 50 add (fileObject, start, end); 51 } 52 53 public ChangeInfo(Position start, Position end) { 54 add (null, start, end); 55 } 56 57 58 public ChangeInfo() { 59 } 60 61 public final int size() { 62 return changes != null ? changes.size() : 0; 63 } 64 65 public final void add (FileObject fileObject, Position start, Position end) { 66 if (changes == null) { 67 changes = new ArrayList <Change>(5); 68 } 69 changes.add (new ChangeImpl (fileObject, start, end)); 70 } 71 72 public final Change get (int i) { 73 if (changes == null) { 74 throw new ArrayIndexOutOfBoundsException ("No changes"); 75 } 76 return (Change) changes.get(i); 77 } 78 79 public String toString() { 80 int size = size(); 81 if (size == 0) { 82 return "Empty ChangeInfo"; 83 } else { 84 StringBuffer sb = new StringBuffer (100); 85 sb.append ("ChangeInfo ["); 86 for (int i=0; i < size; i++) { 87 sb.append (get(i)); 88 if (i != size-1) { 89 sb.append (','); 90 } 91 } 92 sb.append ("]"); 93 return sb.toString(); 94 } 95 } 96 97 101 public static interface Change { 102 public Position getStart(); 103 public Position getEnd(); 104 public FileObject getFileObject(); 105 } 106 107 private static final class ChangeImpl implements Change { 108 Position start; 109 Position end; 110 FileObject fileObject; 111 112 ChangeImpl(FileObject fileObject, Position start, Position end) { 113 this.fileObject = fileObject; 114 this.start = start; 115 this.end = end; 116 } 117 118 public Position getStart() { 119 return start; 120 } 121 122 public Position getEnd() { 123 return end; 124 } 125 126 public FileObject getFileObject() { 127 return fileObject; 128 } 129 130 public String toString() { 131 return "Change from " + start.getOffset() + " to " + end.getOffset() + " in " + fileObject; 132 } 133 } 134 135 } 136 | Popular Tags |