1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 import edu.rice.cs.util.UnexpectedException; 39 import edu.rice.cs.drjava.model.AbstractDJDocument; 40 41 52 public class QuestionStartingNewStmt extends IndentRuleQuestion { 53 54 60 public QuestionStartingNewStmt(IndentRule yesRule, IndentRule noRule) { 61 super(yesRule, noRule); 62 } 63 64 71 boolean applyRule(AbstractDJDocument doc, int reason) { 72 73 char[] delims = {';', '{', '}'}; 74 int lineStart = doc.getLineStartPos(doc.getCurrentLocation()); 75 int prevDelimiterPos; 76 77 try { 78 prevDelimiterPos = doc.findPrevDelimiter(lineStart, delims); 79 } catch (BadLocationException e) { 80 throw new UnexpectedException(e); 82 } 83 84 if (prevDelimiterPos == AbstractDJDocument.ERROR_INDEX) { 86 prevDelimiterPos = -1; 87 } 88 89 int firstNonWSAfterDelimiter; 91 try { 92 firstNonWSAfterDelimiter = doc.getFirstNonWSCharPos(prevDelimiterPos+1); 93 } catch (BadLocationException e) { 95 throw new UnexpectedException(e); 96 } 97 98 return (firstNonWSAfterDelimiter >= lineStart 101 || firstNonWSAfterDelimiter == AbstractDJDocument.ERROR_INDEX); 102 } 103 } 104 105 | Popular Tags |