|
From: <caw...@us...> - 2007-07-24 15:28:27
|
Revision: 2830
http://svn.sourceforge.net/rubyeclipse/?rev=2830&view=rev
Author: cawilliams
Date: 2007-07-24 08:28:26 -0700 (Tue, 24 Jul 2007)
Log Message:
-----------
hook indent empty lines pref up. Add new pref for indenting "when" in case statements.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter/DefaultCodeFormatterConstants.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/DefaultCodeFormatterOptions.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter/DefaultCodeFormatterConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter/DefaultCodeFormatterConstants.java 2007-07-24 15:28:19 UTC (rev 2829)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/formatter/DefaultCodeFormatterConstants.java 2007-07-24 15:28:26 UTC (rev 2830)
@@ -111,6 +111,21 @@
*/
public static final String FORMATTER_INDENT_EMPTY_LINES = RubyCore.PLUGIN_ID
+ ".formatter.indent_empty_lines"; //$NON-NLS-1$
+
+ /**
+ * <pre>
+ * FORMATTER / Option to ident empty lines
+ * - option id: "org.rubypeople.rdt.core.formatter.indent_case_body"
+ * - possible values: { TRUE, FALSE }
+ * - default: FALSE
+ * </pre>
+ *
+ * @see #TRUE
+ * @see #FALSE
+ * @since 1.0
+ */
+ public static final String FORMATTER_INDENT_CASE_BODY = RubyCore.PLUGIN_ID
+ + ".formatter.indent_case_body"; //$NON-NLS-1$
/**
* <pre>
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/DefaultCodeFormatterOptions.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/DefaultCodeFormatterOptions.java 2007-07-24 15:28:19 UTC (rev 2829)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/DefaultCodeFormatterOptions.java 2007-07-24 15:28:26 UTC (rev 2830)
@@ -19,6 +19,9 @@
public int tab_char;
public int tab_size;
public int comment_line_length;
+
+ public boolean indent_case_body = true;
+ public boolean indent_empty_lines = true;
public static DefaultCodeFormatterOptions getDefaultSettings() {
DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions();
@@ -52,6 +55,8 @@
this.tab_char = TAB;
this.tab_size = DEFAULT_TAB_SIZE;
this.indentation_size = DEFAULT_INDENT_SIZE;
+ this.indent_case_body = true;
+ this.indent_empty_lines = true;
}
public void setEclipseDefaultSettings() {
@@ -63,6 +68,8 @@
this.tab_char = SPACE;
this.tab_size = 2;
this.indentation_size = 2;
+ this.indent_case_body = true;
+ this.indent_empty_lines = true;
}
public Map getMap() {
@@ -84,10 +91,34 @@
}
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer
.toString(this.tab_size));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_CASE_BODY, Boolean
+ .toString(this.indent_case_body));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, Boolean
+ .toString(this.indent_empty_lines));
return options;
}
public void set(Map settings) {
+ final Object indentCaseBodyOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_CASE_BODY);
+ if (indentCaseBodyOption != null) {
+ try {
+ this.indent_case_body = Boolean.parseBoolean((String) indentCaseBodyOption);
+ } catch (NumberFormatException e) {
+ this.indent_case_body = true;
+ } catch(ClassCastException e) {
+ this.indent_case_body = true;
+ }
+ }
+ final Object indentEmptyLinesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES);
+ if (indentEmptyLinesOption != null) {
+ try {
+ this.indent_empty_lines = Boolean.parseBoolean((String) indentEmptyLinesOption);
+ } catch (NumberFormatException e) {
+ this.indent_empty_lines = true;
+ } catch(ClassCastException e) {
+ this.indent_empty_lines = true;
+ }
+ }
final Object commentLineLengthOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH);
if (commentLineLengthOption != null) {
try {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java 2007-07-24 15:28:19 UTC (rev 2829)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java 2007-07-24 15:28:26 UTC (rev 2830)
@@ -16,7 +16,7 @@
public class OldCodeFormatter extends CodeFormatter {
private final static String BLOCK_BEGIN_RE = "(class|module|def|if|unless|case|while|until|for|begin|do)";
- private final static String BLOCK_MID_RE = "(else|elsif|rescue|ensure)";
+ private String BLOCK_MID_RE = "(else|elsif|rescue|ensure)";
private final static String BLOCK_END_RE = "(end)";
private final static String DELIMITER_RE = "[?$/(){}#\\`.:\\]\\[]";
private final static String[] LITERAL_BEGIN_LITERALS = { "\"", "'", "=begin", "%[Qqrxw]?.",
@@ -174,7 +174,7 @@
try {
pat = Pattern.compile("(^|[\\s]|;)" + BLOCK_BEGIN_RE + "($|[\\s]|" + DELIMITER_RE
- + ")|(^|[\\s])" + BLOCK_MID_RE + "($|[\\s]|" + DELIMITER_RE + ")|(^|[\\s]|;)"
+ + ")|(^|[\\s])" + getBlockMiddleRegex() + "($|[\\s]|" + DELIMITER_RE + ")|(^|[\\s]|;)"
+ BLOCK_END_RE + "($|[\\s]|;)|" + LITERAL_BEGIN_RE + "|" + DELIMITER_RE);
} catch (PatternSyntaxException e) {
System.out.println(e);
@@ -327,6 +327,15 @@
return firstBlockMarker;
}
+ private String getBlockMiddleRegex() {
+ if (this.preferences.indent_case_body) {
+ return BLOCK_MID_RE;
+ }
+ StringBuffer buffer = new StringBuffer(BLOCK_MID_RE);
+ buffer.insert(1, "when|");
+ return buffer.toString();
+ }
+
/*
* (defun ruby-forward-string (term &optional end no-error expand) (let ((n
* 1) (c (string-to-char term)) (re (if expand (concat
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|