try {    boolean danglingElse= false; boolean unindent= false; boolean matchBrace= false; boolean matchParen= false;  if (position < fDocument.getLength()) { IRegion line= fDocument.getLineInformationOfOffset(position); int next= fScanner.nextToken(position, line.getOffset() + line.getLength()); int prevPos= Math.max(position - 1, 0); switch (next) { case Symbols.TokenEOF: case Symbols.TokenELSE: danglingElse= true; break; case Symbols.TokenCASE: case Symbols.TokenDEFAULT:  if (prefAlignCaseWithSwitch() || fScanner.previousToken(prevPos, JavaHeuristicScanner.UNBOUND) != Symbols.TokenLBRACE) unindent= true; break; case Symbols.TokenLBRACE: if (fScanner.isBracelessBlockStart(prevPos, JavaHeuristicScanner.UNBOUND)) unindent= true; break; case Symbols.TokenRBRACE: matchBrace= true; break; case Symbols.TokenWHILE: break; case Symbols.TokenRPAREN: matchParen= true; break; } } else { danglingElse= true; }   int unit= findReferencePosition(position, danglingElse, matchBrace, matchParen);   if (fAlign != JavaHeuristicScanner.NOT_FOUND) {
StringBuffer indent= getReferenceIndentation(offset);   if (fAlign != JavaHeuristicScanner.NOT_FOUND) { try {
	public String computeIndentation(int position) {				try {			// account for unindenation characters already typed in, but after position			// also account for a dangling else						boolean danglingElse= false;			boolean unindent= false;			boolean matchBrace= false;			boolean matchParen= false;						if (position < fDocument.getLength()) {				IRegion line= fDocument.getLineInformationOfOffset(position);				int next= fScanner.nextToken(position, line.getOffset() + line.getLength());				int prevPos= Math.max(position - 1, 0);				switch (next) {					case Symbols.TokenEOF:					case Symbols.TokenELSE:						danglingElse= true;						break;					case Symbols.TokenCASE:					case Symbols.TokenDEFAULT:						// only if not right after the brace!						if (prefAlignCaseWithSwitch() || fScanner.previousToken(prevPos, JavaHeuristicScanner.UNBOUND) != Symbols.TokenLBRACE)							unindent= true;						break;					case Symbols.TokenLBRACE: // for opening-brace-on-new-line style						if (fScanner.isBracelessBlockStart(prevPos, JavaHeuristicScanner.UNBOUND))							unindent= true;						break;					case Symbols.TokenRBRACE: // closing braces get unindented						matchBrace= true;						break;					case Symbols.TokenWHILE:						break;					case Symbols.TokenRPAREN:						matchParen= true;						break;				}			} else {				danglingElse= true; // assume an else could come - align with 'if' 			}						// find the base position			int unit= findReferencePosition(position, danglingElse, matchBrace, matchParen);						// handle special alignment			if (fAlign != JavaHeuristicScanner.NOT_FOUND) {				// a special case has been detected.				IRegion line= fDocument.getLineInformationOfOffset(fAlign);				int offset= line.getOffset();				return createIndent(offset, fAlign);			}						// if we were unable to find anything, return null			if (unit == JavaHeuristicScanner.NOT_FOUND)				return null; //$NON-NLS-1$						// get base indent at the reference location			IRegion line= fDocument.getLineInformationOfOffset(unit);			int offset= line.getOffset();			int nonWS= fScanner.findNonWhitespaceForwardInAnyPartition(offset, offset + line.getLength());			StringBuffer indent= new StringBuffer(fDocument.get(offset, nonWS - offset));						// add additional indent			indent.append(createIndent(fIndent));			if (fIndent < 0)				unindent= true;						if (unindent)				unindent(indent);							return indent.toString();					} catch (BadLocationException e) {		}				return null; //$NON-NLS-1$	}