1 19 20 25 26 package org.netbeans.modules.java; 27 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyChangeListener ; 30 import org.netbeans.jmi.javamodel.ErrorType; 31 import org.netbeans.jmi.javamodel.ErrorTypeEnum; 32 import org.openide.text.Line; 33 import org.openide.text.Annotatable; 34 import org.openide.text.Line.Set; 35 36 40 class ParserAnnotation extends LineSetAnnotation implements PropertyChangeListener { 41 42 private final String error; 43 private final int line,column; 44 private int state; 45 private final ErrorType severity; 46 private Line docline; 47 private ParserAnnotation chained; 48 49 private static final int STATE_NEW=1; 50 private static final int STATE_ATTACHED = 2; 51 private static final int STATE_DETACHED = 3; 52 53 54 ParserAnnotation(int l, int c, ErrorType sev, String err) { 55 line=l; 56 column=c; 57 error = err; 58 state = STATE_NEW; 59 severity = sev; 60 } 61 62 public String getAnnotationType() { 63 if (ErrorTypeEnum.ERROR.equals(getSeverity())) { 64 return "org-netbeans-modules-java-parser_annotation_err"; } else { 66 return "org-netbeans-modules-java-parser_annotation_warn"; } 68 } 69 70 public String getShortDescription() { 71 if (chained!=null) 73 return error+"\n\n"+chained.getShortDescription(); return error; 75 } 76 77 int getLine() { 78 return line; 79 } 80 81 int getColumn() { 82 return column; 83 } 84 85 String getError() { 86 return error; 87 } 88 89 ErrorType getSeverity() { 90 return severity; 91 } 92 93 void chain(ParserAnnotation anno) { 94 if (chained!=null) 95 chained.chain(anno); 96 else 97 chained=anno; 98 } 99 100 private int getState() { 101 return state; 102 } 103 104 protected void notifyAttached(final Annotatable toAnno) { 105 super.notifyAttached(toAnno); 106 docline.addPropertyChangeListener(this); 107 state = STATE_ATTACHED; 108 } 109 110 protected void notifyDetached(Annotatable fromAnno) { 111 super.notifyDetached(fromAnno); 112 docline.removePropertyChangeListener(this); 113 state=STATE_DETACHED; 114 } 115 116 public boolean equals(Object obj) { 117 boolean eq=shallowEquals(obj); 118 119 if (!eq) 120 return false; 121 if (chained!=null) 122 return chained.equals(((ParserAnnotation)obj).chained); 123 return true; 124 } 125 126 private boolean shallowEquals(Object obj) { 127 if (obj instanceof ParserAnnotation) { 128 ParserAnnotation ann=(ParserAnnotation)obj; 129 130 if (this==obj) 131 return true; 132 if (line!=ann.getLine()) 133 return false; 134 if (column!=ann.getColumn()) 135 return false; 136 if (!error.equals(ann.getError())) 137 return false; 138 if (getState()==STATE_DETACHED || ann.getState()==STATE_DETACHED) 139 return false; 140 return true; 141 } 142 return false; 143 } 144 145 public void attachToLineSet(Set lines) { 146 char string[]; 147 int start,end; 148 Line.Part part; 149 150 try { 151 docline=lines.getCurrent(line-1); 152 } catch (IndexOutOfBoundsException ex) { 153 return; 155 } 156 String annTxt = docline.getText(); 157 if (annTxt == null) return; string = annTxt.toCharArray(); 159 start=0; 160 end=string.length-1; 161 while (start<=end && string[start]<=' ') { 162 start++; 163 } 164 while (start<=end && string[end]<=' ') { 165 end--; 166 } 167 if (start<=end) 168 part=docline.createPart(start,end-start+1); 169 else 170 part=docline.createPart(0,string.length); 171 attach(part); 172 } 173 174 public void propertyChange(PropertyChangeEvent ev) { 175 String type = ev.getPropertyName(); 176 if (type == null || type == Annotatable.PROP_TEXT) { detach(); 178 } 179 } 180 } 181 | Popular Tags |