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 import edu.rice.cs.drjava.model.AbstractDJDocument; 39 40 46 public class QuestionNewParenPhrase extends IndentRuleQuestion { 47 48 54 public QuestionNewParenPhrase(IndentRule yesRule, IndentRule noRule) { 55 super(yesRule, noRule); 56 } 57 58 64 boolean applyRule(AbstractDJDocument doc, int reason) { 65 66 try { 67 int here = doc.getCurrentLocation(); 69 int startLine = doc.getLineStartPos(here); 70 71 if (startLine > AbstractDJDocument.DOCSTART) { 72 char[] delims = {';', ',', '(', '[', 74 '&', '|', '+', '-', '*', '/', '%', 75 '=', '<', '>', '}' 76 }; 77 int prevDelim = doc.findPrevDelimiter(startLine, delims, false); 78 if (prevDelim == AbstractDJDocument.ERROR_INDEX) { 79 return false; 80 } 81 82 int nextNonWS = doc.getFirstNonWSCharPos(prevDelim + 1); 84 if (nextNonWS == AbstractDJDocument.ERROR_INDEX) { 85 nextNonWS = startLine; 86 } 87 return (nextNonWS >= startLine); 88 } 89 } 90 catch (BadLocationException e) { 91 throw new UnexpectedException(e); 93 } 94 return false; 96 } 97 } 98 | Popular Tags |