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 46 public class QuestionPrevLineStartsWith extends IndentRuleQuestion { 47 private String _prefix; 48 49 56 public QuestionPrevLineStartsWith(String prefix, IndentRule yesRule, IndentRule noRule) { 57 super(yesRule, noRule); 58 _prefix = prefix; 59 } 60 61 65 boolean applyRule(AbstractDJDocument doc, int reason) { 66 67 try { 68 int here = doc.getCurrentLocation(); 70 int startLine = doc.getLineStartPos(here); 71 72 if (startLine > AbstractDJDocument.DOCSTART) { 73 int startPrevLine = doc.getLineStartPos(startLine - 1); 75 int firstChar = doc.getLineFirstCharPos(startPrevLine); 76 77 String actualPrefix = doc.getText(firstChar, _prefix.length()); 79 return _prefix.equals(actualPrefix); 80 } 81 } 82 catch (BadLocationException e) { 83 throw new UnexpectedException(e); 85 } 86 return false; 88 } 89 90 } 91 | Popular Tags |