1 19 package org.netbeans.modules.editor.hints; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import javax.swing.text.BadLocationException ; 24 import org.netbeans.spi.editor.hints.LazyFixList; 25 import org.netbeans.spi.editor.hints.Severity; 26 import org.openide.text.Annotation; 27 import org.openide.util.WeakListeners; 28 29 33 public class ParseErrorAnnotation extends Annotation implements PropertyChangeListener { 34 35 private final Severity severity; 36 private final LazyFixList fixes; 37 private final String description; 38 private final int lineNumber; 40 private final AnnotationHolder holder; 41 42 43 public ParseErrorAnnotation(Severity severity, LazyFixList fixes, String description, int lineNumber, AnnotationHolder holder) { 44 this.severity = severity; 45 this.fixes = fixes; 46 this.description = description; 47 this.lineNumber = lineNumber; 48 this.holder = holder; 49 50 if (fixes.probablyContainsFixes() && !fixes.isComputed()) 51 fixes.addPropertyChangeListener(WeakListeners.propertyChange(this, fixes)); 52 } 53 54 public String getAnnotationType() { 55 boolean hasFixes = fixes.isComputed() && !fixes.getFixes().isEmpty(); 56 57 switch (severity) { 58 case ERROR: 59 if (hasFixes) 60 return "org-netbeans-spi-editor-hints-parser_annotation_err_fixable"; 61 else 62 return "org-netbeans-spi-editor-hints-parser_annotation_err"; 63 64 case WARNING: 65 if (hasFixes) 66 return "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"; 67 else 68 return "org-netbeans-spi-editor-hints-parser_annotation_warn"; 69 case VERIFIER: 70 if (hasFixes) 71 return "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"; 72 else 73 return "org-netbeans-spi-editor-hints-parser_annotation_verifier"; 74 case HINT: 75 if (hasFixes) 76 return "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"; 77 else 78 return "org-netbeans-spi-editor-hints-parser_annotation_hint"; 79 case TODO: 80 if (hasFixes) 81 return "org-netbeans-spi-editor-hints-parser_annotation_todo_fixable"; 82 else 83 return "org-netbeans-spi-editor-hints-parser_annotation_todo"; 84 default: 85 throw new IllegalArgumentException (String.valueOf(severity)); 86 } 87 } 88 89 public String getShortDescription() { 90 return description; 91 } 92 93 public void propertyChange(PropertyChangeEvent evt) { 94 if (fixes.isComputed()) { 95 try { 96 holder.detachAnnotation(this); 97 holder.attachAnnotation(lineNumber, this); 98 } catch (BadLocationException ex) { 99 throw new IllegalStateException (ex); 100 } 101 } 102 } 103 104 public LazyFixList getFixes() { 105 return fixes; 106 } 107 108 public String getDescription() { 109 return description; 110 } 111 112 public int getLineNumber() { 113 return lineNumber; 114 } 115 116 Severity getSeverity() { 117 return severity; 118 } 119 } 120 | Popular Tags |