public int findReferencePosition(int offset, boolean danglingElse, boolean matchBrace, boolean matchParen, boolean matchCase) { fIndent= 0; fAlign= JavaHeuristicScanner.NOT_FOUND; fPosition= offset;     if (matchBrace) { skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE); return skipToStatementStart(true, true); }   if (matchParen) { skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN); return fPosition; }    if (matchCase) { return matchCaseAlignment(); }  nextToken(); switch (fToken) { case Symbols.TokenRBRACE:  skipScope(); case Symbols.TokenSEMICOLON:    return skipToStatementStart(danglingElse, false);   case Symbols.TokenLPAREN: case Symbols.TokenLBRACE: case Symbols.TokenLBRACKET: return handleScopeIntroduction(offset + 1);  case Symbols.TokenEOF:  return 0;  case Symbols.TokenEQUAL:  fIndent= prefAssignmentIndent(); return fPosition;  case Symbols.TokenCOLON:  fIndent= prefCaseBlockIndent(); return fPosition;  case Symbols.TokenQUESTIONMARK: if (prefTernaryDeepAlign()) { setFirstElementAlignment(fPosition, offset + 1); return fPosition; } else { fIndent= prefTernaryIndent(); return fPosition; }   case Symbols.TokenDO: case Symbols.TokenWHILE: case Symbols.TokenELSE: fIndent= prefSimpleIndent(); return fPosition; case Symbols.TokenRPAREN: if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) { nextToken(); if (fToken == Symbols.TokenIF || fToken == Symbols.TokenWHILE || fToken == Symbols.TokenFOR) { fIndent= prefSimpleIndent(); return fPosition; } }   case Symbols.TokenCOMMA:     default:    return skipToPreviousListItemOrListStart();  }
public int findReferencePosition(int offset) { return findReferencePosition(offset, false);
	public int findReferencePosition(int offset, boolean danglingElse, boolean matchBrace, boolean matchParen, boolean matchCase) {		fIndent= 0; // the indentation modification		fAlign= JavaHeuristicScanner.NOT_FOUND;		fPosition= offset;				// forward cases		// an unindentation happens sometimes if the next token is special, namely on braces, parens and case labels		// align braces		if (matchBrace) {			skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE);			return skipToStatementStart(true, true);		}				// align parenthesis'		if (matchParen) {			skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN);			return fPosition;		}				// the only reliable way to get case labels aligned (due to many different styles of using braces in a block)		// is to go for another case statement, or the scope opening brace		if (matchCase) {			return matchCaseAlignment();		}				nextToken();		switch (fToken) {			case Symbols.TokenRBRACE:				// skip the block and fall through				skipScope();			case Symbols.TokenSEMICOLON:				// this is the 90% case: after a statement block 				// the end of the previous statement / block previous.end				// search to the end of the statement / block before the previous; the token just after that is previous.start				return skipToStatementStart(danglingElse, false);						// scope introduction: special treat who special is			case Symbols.TokenLPAREN:			case Symbols.TokenLBRACE:			case Symbols.TokenLBRACKET:				return handleScopeIntroduction(offset + 1);							case Symbols.TokenEOF:				// trap when hitting start of document				return 0;						case Symbols.TokenEQUAL:				// indent assignments				fIndent= prefAssignmentIndent();				return fPosition;							case Symbols.TokenCOLON:				// TODO handle ternary deep indentation				fIndent= prefCaseBlockIndent();				return fPosition;						case Symbols.TokenQUESTIONMARK:				if (prefTernaryDeepAlign()) {					setFirstElementAlignment(fPosition, offset + 1);					return fPosition;				} else {					fIndent= prefTernaryIndent();					return fPosition;				}							// indentation for blockless introducers:			case Symbols.TokenDO:			case Symbols.TokenWHILE:			case Symbols.TokenELSE:				fIndent= prefSimpleIndent();				return fPosition;			case Symbols.TokenRPAREN:				if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {					nextToken();					if (fToken == Symbols.TokenIF || fToken == Symbols.TokenWHILE || fToken == Symbols.TokenFOR) {						fIndent= prefSimpleIndent();						return fPosition;					}				}				// else: fall through to default							case Symbols.TokenCOMMA:				// inside a list of some type				// easy if there is already a list item before with its own indentation - we just align				// if not: take the start of the list ( LPAREN, LBRACE, LBRACKET ) and either align or				// indent by list-indent			default:				// inside whatever we don't know about: similar to the list case:				// if we are inside a continued expression, then either align with a previous line that has indentation				// or indent from the expression start line (either a scope introducer or the start of the expr).				return skipToPreviousListItemOrListStart();						}	}