1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import edu.rice.cs.drjava.model.AbstractDJDocument; 37 import edu.rice.cs.drjava.model.definitions.reducedmodel.*; 38 import javax.swing.text.BadLocationException ; 39 40 41 47 public class QuestionHasCharPrecedingOpenBrace extends IndentRuleQuestion { 48 private char[] _prefix; 49 50 56 public QuestionHasCharPrecedingOpenBrace(char[] prefix, IndentRule yesRule, IndentRule noRule) { 57 super(yesRule, noRule); 58 _prefix = prefix; 59 } 60 61 64 boolean applyRule(AbstractDJDocument doc, int reason) { 65 67 int origin = doc.getCurrentLocation(); 68 int lineStart = doc.getLineStartPos(origin); 69 70 doc.move(lineStart - origin); 72 IndentInfo info = doc.getIndentInformation(); 73 doc.move(origin - lineStart); 74 75 if ((!info.braceType.equals(IndentInfo.openSquiggly)) || 76 (info.distToBrace < 0)) { 77 return false; 79 } 80 int bracePos = lineStart - info.distToBrace; 81 82 int prevNonWS = -1; 84 try { 85 prevNonWS = doc.findPrevNonWSCharPos(bracePos); 86 char c = doc.getText(prevNonWS,1).charAt(0); 87 for (char pchar: _prefix) if (c == pchar) return true; 88 } 89 catch (BadLocationException e) { 90 } 91 return false; 92 } 93 } 94 | Popular Tags |