1 19 20 package org.netbeans.modules.web.core.syntax; 21 22 26 27 28 import org.netbeans.api.jsp.lexer.JspTokenId; 29 import org.netbeans.api.lexer.Token; 30 import org.netbeans.api.lexer.TokenHierarchy; 31 import org.netbeans.api.lexer.TokenSequence; 32 import org.netbeans.editor.ext.ExtSyntaxSupport; 33 import org.netbeans.modules.editor.NbEditorDocument; 34 import org.netbeans.modules.web.core.syntax.spi.ErrorAnnotation; 35 import org.openide.text.Line; 36 import org.openide.text.Line.Set; 37 import org.openide.text.NbDocument; 38 39 public class JspParserErrorAnnotation extends ErrorAnnotation.LineSetAnnotation { 40 41 43 private Line docline; 44 47 private final int line,column; 48 50 private final String error; 51 53 private NbEditorDocument document; 54 55 public JspParserErrorAnnotation(int line, int column, String error, NbEditorDocument document) { 56 this.line = line; 57 this.column = column; 58 this.error = error; 59 this.document = document; 60 } 61 62 public String getShortDescription() { 63 return error; 65 } 66 67 public int getLine(){ 68 return line; 69 } 70 71 public int getColumn(){ 72 return column; 73 } 74 75 public String getError(){ 76 return error; 77 } 78 79 public String getAnnotationType() { 80 return "org-netbeans-modules-web-core-syntax-JspParserErrorAnnotation"; } 82 83 public void attachToLineSet(Set lines) { 84 char string[]; 85 int start,end; 86 Line.Part part; 87 88 try { 89 docline=lines.getCurrent(line-1); 90 } catch (IndexOutOfBoundsException ex) { 91 return; 93 } 94 95 String annTxt = docline.getText(); if (annTxt == null) return; 98 ExtSyntaxSupport support = (ExtSyntaxSupport)document.getSyntaxSupport(); 99 int offset = NbDocument.findLineOffset(document, docline.getLineNumber()) + column+1; start = 0; string = annTxt.toCharArray(); 102 end = string.length - 1; 104 if (offset < 1){ 106 textOnLine(docline); 107 return; 108 } 109 TokenHierarchy tokenHierarchy = TokenHierarchy.get(document); 110 TokenSequence tokenSequence = tokenHierarchy.tokenSequence(); 111 tokenSequence.move(offset - 1); 112 if (!tokenSequence.moveNext() && !tokenSequence.movePrevious()) { 113 textOnLine(docline); 115 return ; 116 } 117 start = NbDocument.findLineColumn(document, tokenSequence.token().offset(tokenHierarchy)); 118 offset = tokenSequence.token().offset(tokenHierarchy); 119 120 if (tokenSequence.token().id() != JspTokenId.EL){ 122 while (!(tokenSequence.token().id() == JspTokenId.SYMBOL 125 && tokenSequence.token().text().toString().charAt(0) == '<' || tokenSequence.token().id() == JspTokenId.TAG) && tokenSequence.token().id() != JspTokenId.EOL 128 && tokenSequence.movePrevious()) { 129 start = NbDocument.findLineColumn(document, tokenSequence.token().offset(tokenHierarchy)); 130 offset = tokenSequence.token().offset(tokenHierarchy); 131 } 132 133 while ((tokenSequence.token().id() != JspTokenId.SYMBOL 135 || tokenSequence.token().text().toString().charAt(tokenSequence.token().text().toString().trim().length()-1) != '>') 136 && tokenSequence.token().id() != JspTokenId.EOL && tokenSequence.moveNext()); 137 } else { 138 } 140 141 end = tokenSequence.token().offset(tokenHierarchy) + tokenSequence.token().length() - offset; 142 143 151 part=docline.createPart(start, end); attach(part); 153 } 154 155 private void textOnLine(Line docline){ 156 int start = 0; char string[] = docline.getText().toCharArray(); 158 int end = string.length - 1; Line.Part part; 160 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 return; 173 } 174 175 public boolean equals(Object obj) { 176 if (obj instanceof JspParserErrorAnnotation) { 177 JspParserErrorAnnotation ann=(JspParserErrorAnnotation)obj; 178 179 if (this==obj) 180 return true; 181 if (line!=ann.getLine()) 182 return false; 183 if (column!=ann.getColumn()) 184 return false; 185 if (!error.equals(ann.getError())) 186 return false; 187 189 return true; 190 } 191 return false; 192 } 193 } 194 | Popular Tags |