Skip to content

Commit

Permalink
Merge branch 'development' into participant
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Feb 3, 2012
2 parents a99b0ed + bbbb6e5 commit f8e440b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
package com.aptana.editor.ruby.formatter.internal.nodes;

import com.aptana.editor.ruby.formatter.RubyFormatterConstants;
import com.aptana.formatter.IFormatterContext;
import com.aptana.formatter.IFormatterDocument;
import com.aptana.formatter.IFormatterWriter;
import com.aptana.formatter.nodes.FormatterCommentNode;

/**
Expand All @@ -17,6 +19,11 @@
public class FormatterRubyCommentNode extends FormatterCommentNode
{

/**
* A block comment 'begin' syntax. We make sure that those blocks don't get indented.
*/
private static final String BLOCK_COMMENT_BEGIN = "=begin"; //$NON-NLS-1$

/**
* @param document
* @param startOffset
Expand All @@ -36,4 +43,27 @@ public String getWrappingKey()
{
return RubyFormatterConstants.WRAP_COMMENTS;
}

/*
* (non-Javadoc)
* @see com.aptana.formatter.nodes.FormatterCommentNode#accept(com.aptana.formatter.IFormatterContext,
* com.aptana.formatter.IFormatterWriter)
*/
@Override
public void accept(IFormatterContext context, IFormatterWriter visitor) throws Exception
{
String text = getText();
int indent = context.getIndent();
boolean isBlockComment = (text != null && text.startsWith(BLOCK_COMMENT_BEGIN));
if (isBlockComment)
{
// We need to make sure we don't indent that block.
context.setIndent(0);
}
super.accept(context, visitor);
if (isBlockComment)
{
context.setIndent(indent);
}
}
}
43 changes: 43 additions & 0 deletions tests/com.aptana.editor.ruby.formatter.tests/formatting/test016.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
==PREFS==
ruby.formatter.indent.class=true
ruby.formatter.indent.module=true
ruby.formatter.indent.method=true
ruby.formatter.indent.blocks=true
ruby.formatter.indent.case=false
ruby.formatter.indent.when=true
ruby.formatter.indent.if=true
ruby.formatter.line.file.require.after=1
ruby.formatter.line.file.module.between=1
ruby.formatter.line.file.class.between=1
ruby.formatter.line.file.method.between=1
ruby.formatter.line.first.before=0
ruby.formatter.line.module.before=1
ruby.formatter.line.class.before=1
ruby.formatter.line.method.before=1
ruby.formatter.lines.preserve=1
ruby.formatter.wrap.comments=false
ruby.formatter.wrap.comments.length=80
ruby.formatter.formatter.tabulation.char=editor
ruby.formatter.formatter.tabulation.size=2
ruby.formatter.formatter.indentation.size=2
ruby.formatter.formatter.on.off.enabled=false
ruby.formatter.formatter.on=@formatter:on
ruby.formatter.formatter.off=@formatter:off
==CONTENT==
class MyClass
=begin
my comment
=end
def initialize
@a=0
end
end
==FORMATTED==
class MyClass
=begin
my comment
=end
def initialize
@a=0
end
end

0 comments on commit f8e440b

Please sign in to comment.