|
From: Markus B. <mba...@us...> - 2006-04-25 22:22:23
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5134/src/org/rubypeople/rdt/internal/formatter Modified Files: OldCodeFormatter.java AbstractBlockMarker.java NoFormattingMarker.java IndentationState.java NeutralMarker.java FixLengthMarker.java Log Message: Cleaned up IndentationState, fixed errors in test suite Index: IndentationState.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/IndentationState.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndentationState.java 10 Feb 2006 18:32:41 -0000 1.2 --- IndentationState.java 25 Apr 2006 22:22:18 -0000 1.3 *************** *** 1,26 **** package org.rubypeople.rdt.internal.formatter; public class IndentationState { ! private int lastIndentation ; private int indentationLevel ; - private int indentationLength ; private int offset ; private int pos ; ! private int indentation ; private String unformattedText ; ! public IndentationState(String unformattedText, int indentationLength, int offset, int initialIndentLevel) { this.unformattedText = unformattedText ; ! this.indentationLength = indentationLength ; ! this.offset = offset; ! indentationLevel = initialIndentLevel; pos = 0 ; ! this.calculateIndentation() ; } public void decIndentationLevel() { ! indentationLevel -= 1 ; ! this.calculateIndentation() ; } --- 1,33 ---- package org.rubypeople.rdt.internal.formatter; + import java.util.Map; + + import org.rubypeople.rdt.core.formatter.Indents; public class IndentationState { ! private String lastIndentationBasedOnLevel = ""; private int indentationLevel ; private int offset ; private int pos ; ! ! // indentation for parameter over multiple lines, like ! // method(param1 ! // .......param2) ! private int fixIndentation ; ! private String unformattedText ; + ! public IndentationState(String unformattedText, int offset, int initialIndentLevel) { this.unformattedText = unformattedText ; ! this.offset = offset ; ! indentationLevel = initialIndentLevel ; pos = 0 ; ! resetFixIndentation() ; } public void decIndentationLevel() { ! indentationLevel -= 1 ; ! resetFixIndentation() ; } *************** *** 28,32 **** public void incIndentationLevel() { indentationLevel += 1 ; ! this.calculateIndentation() ; } --- 35,39 ---- public void incIndentationLevel() { indentationLevel += 1 ; ! resetFixIndentation() ; } *************** *** 35,49 **** } ! public void calculateIndentation() { ! indentation = offset + indentationLength * indentationLevel ; ! } ! ! public int getIndentation() { ! return indentation; } ! public int getIndentationLength() { ! return indentationLength; } --- 42,52 ---- } ! public void resetFixIndentation() { ! fixIndentation = -1 ; } ! public int getIndentation() { ! return fixIndentation; } *************** *** 69,74 **** ! public void setIndentation(int indentation) { ! this.indentation = indentation; } --- 72,77 ---- ! public void setFixIndentation(int indentation) { ! this.fixIndentation = indentation; } *************** *** 76,80 **** public void setIndentationLevel(int indentationLevel) { this.indentationLevel = indentationLevel; ! this.calculateIndentation() ; } --- 79,83 ---- public void setIndentationLevel(int indentationLevel) { this.indentationLevel = indentationLevel; ! this.resetFixIndentation() ; } *************** *** 82,86 **** public void setOffset(int offset) { this.offset = offset; ! this.calculateIndentation() ; } --- 85,89 ---- public void setOffset(int offset) { this.offset = offset; ! this.resetFixIndentation() ; } *************** *** 90,100 **** } ! public void saveIndentation() { ! this.lastIndentation = indentation ; } - public int getLastIndentation() { - return lastIndentation ; - } } --- 93,112 ---- } ! protected String getIndentationString(Map options) { ! StringBuffer sb = new StringBuffer() ; ! for (int i = 0; i < this.getOffset(); i++) { ! sb.append(" "); ! } ! if (this.getIndentation() != -1) { ! sb.append(lastIndentationBasedOnLevel) ; ! sb.append(Indents.createFixIndentString(this.getIndentation(), options)); ! } ! else { ! lastIndentationBasedOnLevel = Indents.createIndentString(this.getIndentationLevel(), options); ! sb.append(lastIndentationBasedOnLevel) ; ! } ! return sb.toString() ; } } Index: AbstractBlockMarker.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/AbstractBlockMarker.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractBlockMarker.java 10 Feb 2006 18:32:41 -0000 1.2 --- AbstractBlockMarker.java 25 Apr 2006 22:22:18 -0000 1.3 *************** *** 3,8 **** import java.util.Map; - import org.rubypeople.rdt.core.formatter.Indents; - public abstract class AbstractBlockMarker { protected int pos; --- 3,6 ---- *************** *** 39,48 **** public void appendIndentedLine(StringBuffer sb, IndentationState state, String originalLine, String strippedLine, Map options) { ! String spaces = ""; ! for (int i = 0; i < state.getOffset(); i++) { ! spaces+= " "; ! } ! sb.append(spaces); ! sb.append(Indents.createIndentString(state.getIndentationLevel(), options)); sb.append(strippedLine); } --- 37,41 ---- public void appendIndentedLine(StringBuffer sb, IndentationState state, String originalLine, String strippedLine, Map options) { ! sb.append(state.getIndentationString(options)); sb.append(strippedLine); } Index: NeutralMarker.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/NeutralMarker.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NeutralMarker.java 11 Apr 2003 22:12:10 -0000 1.1 --- NeutralMarker.java 25 Apr 2006 22:22:18 -0000 1.2 *************** *** 14,18 **** protected void indentBeforePrint(IndentationState state) { ! state.calculateIndentation() ; } --- 14,18 ---- protected void indentBeforePrint(IndentationState state) { ! state.resetFixIndentation() ; } Index: NoFormattingMarker.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/NoFormattingMarker.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NoFormattingMarker.java 11 Apr 2003 22:12:10 -0000 1.1 --- NoFormattingMarker.java 25 Apr 2006 22:22:18 -0000 1.2 *************** *** 1,4 **** --- 1,6 ---- package org.rubypeople.rdt.internal.formatter; + import java.util.Map; + public class NoFormattingMarker extends AbstractBlockMarker { *************** *** 25,29 **** } ! public void appendIndentedLine(StringBuffer sb, IndentationState state, String originalLine, String strippedLine) { sb.append(originalLine) ; } --- 27,31 ---- } ! public void appendIndentedLine(StringBuffer sb, IndentationState state, String originalLine, String strippedLine, Map options) { sb.append(originalLine) ; } Index: OldCodeFormatter.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OldCodeFormatter.java 22 Feb 2006 20:03:37 -0000 1.3 --- OldCodeFormatter.java 25 Apr 2006 22:22:18 -0000 1.4 *************** *** 131,136 **** int leadingWhitespace = whitespaceMatcher.end(0); if (state == null) { ! state = new IndentationState(unformatted, preferences.indentation_size, ! leadingWhitespace, initialIndentLevel); } state.incPos(leadingWhitespace); --- 131,135 ---- int leadingWhitespace = whitespaceMatcher.end(0); if (state == null) { ! state = new IndentationState(unformatted, leadingWhitespace, initialIndentLevel); } state.incPos(leadingWhitespace); *************** *** 141,145 **** newBlockMarker.indentBeforePrint(state); newBlockMarker.appendIndentedLine(formatted, state, lines[i], strippedLine, options); - state.saveIndentation(); newBlockMarker.indentAfterPrint(state); abstractBlockMarker = newBlockMarker; --- 140,143 ---- Index: FixLengthMarker.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/FixLengthMarker.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixLengthMarker.java 11 Apr 2003 22:12:10 -0000 1.1 --- FixLengthMarker.java 25 Apr 2006 22:22:18 -0000 1.2 *************** *** 34,38 **** protected void indentBeforePrint(IndentationState state) { ! state.setIndentation(state.getLastIndentation() + this.getPosInLine(state)) ; } --- 34,38 ---- protected void indentBeforePrint(IndentationState state) { ! state.setFixIndentation(this.getPosInLine(state)) ; } |