|
From: Christopher W. <caw...@us...> - 2006-02-18 16:51:04
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27341/src/org/rubypeople/rdt/internal/formatter Modified Files: OldCodeFormatter.java Log Message: take into account initial indent level (given by newer format method call). If invoked the old way, guess the initial indent level as we used to. Index: OldCodeFormatter.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OldCodeFormatter.java 10 Feb 2006 18:32:16 -0000 1.1 --- OldCodeFormatter.java 18 Feb 2006 16:50:59 -0000 1.2 *************** *** 104,109 **** firstAbstractBlockMarker.print(); } try { ! return this.formatString(unformatted, firstAbstractBlockMarker); } catch (PatternSyntaxException ex) { return unformatted; --- 104,110 ---- firstAbstractBlockMarker.print(); } + int initialIndentLevel = Indents.measureIndentUnits(unformatted, preferences.tab_size, preferences.indentation_size); try { ! return this.formatString(unformatted, firstAbstractBlockMarker, initialIndentLevel); } catch (PatternSyntaxException ex) { return unformatted; *************** *** 118,122 **** } ! protected String formatString(String unformatted, AbstractBlockMarker abstractBlockMarker) throws PatternSyntaxException { Pattern pat = Pattern.compile("\n"); --- 119,123 ---- } ! protected String formatString(String unformatted, AbstractBlockMarker abstractBlockMarker, int initialIndentLevel) throws PatternSyntaxException { Pattern pat = Pattern.compile("\n"); *************** *** 125,137 **** StringBuffer formatted = new StringBuffer(); Pattern whitespacePattern = Pattern.compile("^[\t ]*"); ! for (int i = 0; i < lines.length; i++) { ! String line = lines[i]; ! int initialIndentLevel = Indents.measureIndentUnits(line, preferences.tab_size, preferences.indentation_size); ! Matcher whitespaceMatcher = whitespacePattern.matcher(lines[i]); whitespaceMatcher.find(); int leadingWhitespace = whitespaceMatcher.end(0); if (state == null) { ! state = new IndentationState(unformatted, preferences.indentation_size, leadingWhitespace, initialIndentLevel); } --- 126,135 ---- StringBuffer formatted = new StringBuffer(); Pattern whitespacePattern = Pattern.compile("^[\t ]*"); ! for (int i = 0; i < lines.length; i++) { Matcher whitespaceMatcher = whitespacePattern.matcher(lines[i]); whitespaceMatcher.find(); int leadingWhitespace = whitespaceMatcher.end(0); if (state == null) { ! state = new IndentationState(unformatted, preferences.indentation_size, leadingWhitespace, initialIndentLevel); } *************** *** 455,461 **** public TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator) { ! String newText = formatString(source.substring(offset, length)); return new ReplaceEdit(offset, length, newText); } } --- 453,471 ---- public TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator) { ! String newText = formatString(source.substring(offset, length), indentationLevel); return new ReplaceEdit(offset, length, newText); } + private String formatString(String unformatted, int indentationLevel) { + AbstractBlockMarker firstAbstractBlockMarker = this.createBlockMarkerList(unformatted); + if (isDebug()) { + firstAbstractBlockMarker.print(); + } + try { + return this.formatString(unformatted, firstAbstractBlockMarker, indentationLevel); + } catch (PatternSyntaxException ex) { + return unformatted; + } + } + } |