1 9 10 package org.netbeans.modules.tasklist.checkstyle; 11 12 13 import javax.swing.text.BadLocationException ; 14 import javax.swing.text.Document ; 15 import javax.swing.text.Element ; 16 import javax.swing.text.StyledDocument ; 17 18 import org.netbeans.modules.tasklist.client.Suggestion; 19 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 20 import org.netbeans.modules.tasklist.providers.SuggestionContext; 21 22 import org.openide.ErrorManager; 23 24 28 public final class TrailingSpacesSuggestionPerformer extends AbstractSuggestionPerformer{ 29 30 31 TrailingSpacesSuggestionPerformer( 32 final Document doc, 33 final int lineno) { 34 35 super(doc,lineno,0); 36 } 37 38 public void perform(final Suggestion suggestion) { 39 40 final Element elm = getElement(doc, lineno-1); 41 if (elm == null) { 42 ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null"); 43 return; 44 } 45 final int offset = elm.getStartOffset(); 46 final int endOffset = elm.getEndOffset()-2; int wsStart = endOffset; 48 try { 49 while( doc.getText(wsStart,1).charAt(0) == ' ' ){ 50 --wsStart; 51 } 52 doc.remove(wsStart+1,endOffset-wsStart); 53 } catch (BadLocationException ex) { 54 ErrorManager.getDefault().notify(ErrorManager.WARNING, ex); 55 } 56 } 57 58 protected void performImpl(int docPosition) throws BadLocationException { 59 throw new UnsupportedOperationException ("TrailingSpacesSuggestionProvider overrides perform(..) directly."); 60 } 61 } 62 | Popular Tags |