|
From: Markus B. <mba...@us...> - 2006-04-25 22:22:23
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5134/src/org/rubypeople/rdt/core/formatter Modified Files: Indents.java Log Message: Cleaned up IndentationState, fixed errors in test suite Index: Indents.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter/Indents.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Indents.java 10 Feb 2006 18:27:42 -0000 1.1 --- Indents.java 25 Apr 2006 22:22:18 -0000 1.2 *************** *** 118,121 **** --- 118,160 ---- } + public static String createFixIndentString(int fixIndentation, Map options) { + if (options == null || fixIndentation < 0) { + throw new IllegalArgumentException(); + } + + String tabChar= getStringValue(options, DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, RubyCore.TAB); + + final int tabs, spaces; + if (RubyCore.SPACE.equals(tabChar)) { + tabs= 0; + spaces= fixIndentation; + } else if (RubyCore.TAB.equals(tabChar)) { + int tabWidth= getTabWidth(options); + tabs= fixIndentation / tabWidth; + spaces= 0; + } else if (DefaultCodeFormatterConstants.MIXED.equals(tabChar)){ + int tabWidth= getTabWidth(options); + if (tabWidth > 0) { + tabs= fixIndentation / tabWidth; + spaces= fixIndentation % tabWidth; + } else { + tabs= 0; + spaces= fixIndentation; + } + } else { + // new indent type not yet handled + Assert.isTrue(false); + return null; + } + + StringBuffer buffer= new StringBuffer(tabs + spaces); + for(int i= 0; i < tabs; i++) + buffer.append('\t'); + for(int i= 0; i < spaces; i++) + buffer.append(' '); + return buffer.toString(); + + } + private static String getStringValue(Map options, String key, String def) { Object value= options.get(key); |