| 1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import edu.rice.cs.drjava.model.AbstractDJDocument; 37 38 46 public abstract class IndentRuleQuestion extends IndentRuleWithTrace { 47 50 private final IndentRule _yesRule; 51 52 55 private final IndentRule _noRule; 56 57 62 public IndentRuleQuestion(final IndentRule yesRule, final IndentRule noRule) { 63 _yesRule = yesRule; 64 _noRule = noRule; 65 } 66 67 72 abstract boolean applyRule(AbstractDJDocument doc, int reason); 73 74 80 boolean applyRule(AbstractDJDocument doc, int pos, int reason) { 81 int oldPos = doc.getCurrentLocation(); 82 doc.setCurrentLocation(pos); 83 boolean result = applyRule(doc, reason); 84 if (oldPos > doc.getLength()) { 85 oldPos = doc.getLength(); 86 } 87 doc.setCurrentLocation(oldPos); 88 return result; 89 } 90 91 99 public boolean indentLine(AbstractDJDocument doc, int reason) { 100 if (applyRule(doc, reason)) { 101 _addToIndentTrace(getRuleName(), YES, false); 102 return _yesRule.indentLine(doc, reason); 103 } 104 else { 105 _addToIndentTrace(getRuleName(), NO, false); 106 return _noRule.indentLine(doc, reason); 107 } 108 } 109 } 110 111 112 113 114 115 | Popular Tags |