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

java.lang.Object
  extended by edu.rice.cs.drjava.model.definitions.indent.IndentRuleWithTrace
      extended by edu.rice.cs.drjava.model.definitions.indent.IndentRuleQuestion
          extended by edu.rice.cs.drjava.model.definitions.indent.QuestionExistsCharInStmt
All Implemented Interfaces:
IndentRule

public class QuestionExistsCharInStmt
extends IndentRuleQuestion

Determines if the given search character is found between the start of the current statement and the end character. Accomplishes this by searching backwards from the end character, for the search character until one of the following characters is found: '}', '{', ';', 0. The given end character must exist on the current line and not be part of a quote or comment. If there is more than end character on the given line, then the first end character is used.

This question is useful for determining if, when a colon is found on a line, it is part of a ternary operator or not (construct this question with '?' for search character and ':' for end character).

It can also be used to determine if a statement contains a particular character by constructing it with the desired character as a search character and the end character as ';'.

Note that characters in comments and quotes are disregarded.

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

Field Summary
private  char _endChar
          The character which marks the end of the search space.
private  char _findChar
          The character to search for
 
Fields inherited from class edu.rice.cs.drjava.model.definitions.indent.IndentRuleWithTrace
NO, TERMINUS_RULE, YES
 
Constructor Summary
QuestionExistsCharInStmt(char findChar, char endChar, IndentRule yesRule, IndentRule noRule)
          Constructs a rule to determine if findChar exists between the start of the current statement and endChar.
 
Method Summary
(package private)  boolean applyRule(AbstractDJDocument doc, Indenter.IndentReason reason)
          Searches backwards from endChar to the start of the statement looking for findChar.
 
Methods inherited from class edu.rice.cs.drjava.model.definitions.indent.IndentRuleQuestion
applyRule, indentLine, testApplyRule, testApplyRule, testIndentLine
 
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

_findChar

private char _findChar
The character to search for


_endChar

private char _endChar
The character which marks the end of the search space. i.e. search from the start of the statment to the end char.

Constructor Detail

QuestionExistsCharInStmt

public QuestionExistsCharInStmt(char findChar,
                                char endChar,
                                IndentRule yesRule,
                                IndentRule noRule)
Constructs a rule to determine if findChar exists between the start of the current statement and endChar.

Parameters:
findChar - Character to search for from the start of the statement to endChar
endChar - Character that marks the end of the search space. Must exist on the current line and not be in quotes or comments.
yesRule - Rule to use if this rule holds
noRule - Rule to use if this rule does not hold
Method Detail

applyRule

boolean applyRule(AbstractDJDocument doc,
                  Indenter.IndentReason reason)
Searches backwards from endChar to the start of the statement looking for findChar. Ignores characters in comments and quotes. Start of the statement is the point right after when one of the following characters is found: ';', '{', '}', 0.

Specified by:
applyRule in class IndentRuleQuestion
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.