1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.*; 37 import edu.rice.cs.util.UnexpectedException; 38 39 import edu.rice.cs.drjava.model.AbstractDJDocument; 40 41 45 public class QuestionCurrLineStartsWith extends IndentRuleQuestion { 46 private String _prefix; 47 48 53 public QuestionCurrLineStartsWith(String prefix, IndentRule yesRule, IndentRule noRule) { 54 super(yesRule, noRule); 55 _prefix = prefix; 56 } 57 58 62 boolean applyRule(AbstractDJDocument doc, int reason) { 63 64 try { 65 int here = doc.getCurrentLocation(); 67 int firstCharPos = doc.getLineFirstCharPos(here); 68 int lineEndPos = doc.getLineEndPos(here); 69 70 if (firstCharPos + _prefix.length() > lineEndPos) { 72 return false; 73 } 74 75 String actualPrefix = doc.getText(firstCharPos, _prefix.length()); 77 return _prefix.equals(actualPrefix); 78 } 79 catch (BadLocationException e) { 80 throw new UnexpectedException(e); 82 } 83 } 84 } 85 | Popular Tags |