1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 import edu.rice.cs.drjava.model.AbstractDJDocument; 38 import edu.rice.cs.drjava.model.definitions.reducedmodel.*; 39 import edu.rice.cs.util.UnexpectedException; 40 41 46 public class QuestionStartAfterOpenBrace extends IndentRuleQuestion { 47 50 public QuestionStartAfterOpenBrace(IndentRule yesRule, IndentRule noRule) { super(yesRule, noRule); } 51 52 56 boolean applyRule(AbstractDJDocument doc, int reason) { 57 58 int origin = doc.getCurrentLocation(); 59 int lineStart = doc.getLineStartPos(doc.getCurrentLocation()); 61 62 doc.move(lineStart - origin); 64 IndentInfo info = doc.getIndentInformation(); 65 doc.move(origin - lineStart); 66 67 if ((!info.braceType.equals(IndentInfo.openSquiggly)) || 68 (info.distToBrace < 0)) 69 return false; 71 int bracePos = lineStart - info.distToBrace; 72 73 int braceEndLinePos = doc.getLineEndPos(bracePos); 75 76 int nextNonWS = -1; 78 try { nextNonWS = doc.getFirstNonWSCharPos(braceEndLinePos); } 79 catch (BadLocationException e) { 80 throw new UnexpectedException(e); 82 } 83 84 if (nextNonWS == AbstractDJDocument.ERROR_INDEX) return true; 85 86 return (nextNonWS >= lineStart); 87 } 88 } 89 | Popular Tags |