edu.rice.cs.drjava.model.definitions.indent
Class IndentRuleQuestion

java.lang.Object
  extended by edu.rice.cs.drjava.model.definitions.indent.IndentRuleWithTrace
      extended by edu.rice.cs.drjava.model.definitions.indent.IndentRuleQuestion
All Implemented Interfaces:
IndentRule
Direct Known Subclasses:
QuestionBraceIsCurly, QuestionBraceIsParenOrBracket, QuestionCurrLineEmpty, QuestionCurrLineEmptyOrEnterPress, QuestionCurrLineIsWingComment, QuestionCurrLineStartsWith, QuestionCurrLineStartsWithSkipComments, QuestionExistsCharInPrevStmt, QuestionExistsCharInStmt, QuestionFollowedByStar, QuestionHasCharPrecedingOpenBrace, QuestionInsideComment, QuestionLineContains, QuestionNewParenPhrase, QuestionPrevLineStartsComment, QuestionPrevLineStartsJavaDocWithText, QuestionPrevLineStartsWith, QuestionStartAfterOpenBrace, QuestionStartingNewStmt

public abstract class IndentRuleQuestion
extends IndentRuleWithTrace

A question node in the decision tree for the indentation system. Calls to indentLine on an IndentRuleQuestion will make a decision based on context and call the same method on one of its children. The leaves of the tree are represented by IndentRuleAction objects.

Version:
$Id: IndentRuleQuestion.java 5175 2010-01-20 08:46:32Z mgricken $

Field Summary
private  IndentRule _noRule
          Node in decision tree to use if the rule does not hold in this context.
private  IndentRule _yesRule
          Node in decision tree to use if the rule holds in this context.
 
Fields inherited from class edu.rice.cs.drjava.model.definitions.indent.IndentRuleWithTrace
NO, TERMINUS_RULE, YES
 
Constructor Summary
IndentRuleQuestion(IndentRule yesRule, IndentRule noRule)
          Constructs a new Question indent rule using the two given children.
 
Method Summary
(package private) abstract  boolean applyRule(AbstractDJDocument doc, Indenter.IndentReason reason)
          Determines if the given rule holds in this context.
(package private)  boolean applyRule(AbstractDJDocument doc, int pos, Indenter.IndentReason reason)
          Determines if the given rule holds in this context.
 boolean indentLine(AbstractDJDocument doc, Indenter.IndentReason reason)
          Determines if the given rule holds in this context and calls the same method on one of its child nodes.
(package private)  boolean testApplyRule(AbstractDJDocument doc, Indenter.IndentReason reason)
          Convenience method that wraps calls on applyRule in a read lock.
(package private)  boolean testApplyRule(AbstractDJDocument doc, int pos, Indenter.IndentReason reason)
          Convenience method that wraps calls on applyRule in a read lock.
 boolean testIndentLine(AbstractDJDocument doc, Indenter.IndentReason reason)
          Convenience method that wraps calls on indentLine in a write lock.
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.indent.IndentRuleWithTrace
_addToIndentTrace, getRuleName, getTrace, indentLine, printLastIndentTrace, setRuleTraceEnabled, testIndentLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_yesRule

private final IndentRule _yesRule
Node in decision tree to use if the rule holds in this context.


_noRule

private final IndentRule _noRule
Node in decision tree to use if the rule does not hold in this context.

Constructor Detail

IndentRuleQuestion

public IndentRuleQuestion(IndentRule yesRule,
                          IndentRule noRule)
Constructs a new Question indent rule using the two given children.

Parameters:
yesRule - Rule to use if this rule holds
noRule - Rule to use if this rule does not hold
Method Detail

applyRule

abstract boolean applyRule(AbstractDJDocument doc,
                           Indenter.IndentReason reason)
Determines if the given rule holds in this context.

Parameters:
doc - AbstractDJDocument containing the line to be indented.
reason - The reason that indentation was initiated, specified in Indenter
Returns:
true if this node's rule holds.

applyRule

boolean applyRule(AbstractDJDocument doc,
                  int pos,
                  Indenter.IndentReason reason)
Determines if the given rule holds in this context.

Parameters:
doc - The AbstractDJDocument containing the line to be indented.
pos - The Position within line to be indented.
reason - The reason that indentation was initiated, specified in Indenter
Returns:
true if this node's rule holds.

indentLine

public boolean indentLine(AbstractDJDocument doc,
                          Indenter.IndentReason reason)
Determines if the given rule holds in this context and calls the same method on one of its child nodes.

Specified by:
indentLine in interface IndentRule
Overrides:
indentLine in class IndentRuleWithTrace
Parameters:
doc - AbstractDJDocument containing the line to be indented.
reason - The reason that indentation was initiated, specified in Indenter
Returns:
true if the caller should update the current location itself, false if the indenter has already handled this

testApplyRule

boolean testApplyRule(AbstractDJDocument doc,
                      Indenter.IndentReason reason)
Convenience method that wraps calls on applyRule in a read lock. Only used in testing.


testApplyRule

boolean testApplyRule(AbstractDJDocument doc,
                      int pos,
                      Indenter.IndentReason reason)
Convenience method that wraps calls on applyRule in a read lock. Only used in testing.


testIndentLine

public boolean testIndentLine(AbstractDJDocument doc,
                              Indenter.IndentReason reason)
Convenience method that wraps calls on indentLine in a write lock. Only used in testing.

Overrides:
testIndentLine in class IndentRuleWithTrace