Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Matela2015-08-03 22:41:04 +0000
committerManoj Palat2015-08-11 06:35:29 +0000
commit9db26c7bea8b081f74e04400ef73e415034114ae (patch)
tree13266e61f3019c40a2c569bc83d62907657da655
parent32a3c84b06c53016e17ed82bc9b5d193d8ea73ad (diff)
downloadeclipse.jdt.core-9db26c7bea8b081f74e04400ef73e415034114ae.tar.gz
eclipse.jdt.core-9db26c7bea8b081f74e04400ef73e415034114ae.tar.xz
eclipse.jdt.core-9db26c7bea8b081f74e04400ef73e415034114ae.zip
fixed bug 470506: formatter option "align field in columns" changed in MarsI20150811-1400
Change-Id: I12e47137814dcf9cf273a4e874587f95916f3170 Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java17
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/FieldAligner.java27
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java2
3 files changed, 20 insertions, 26 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
index 8ad978af3e..3ee0592456 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -11103,4 +11103,21 @@ public void testBug472962() {
"}";
formatSource(source);
}
+/**
+ * @bug 470506: formatter option "align field in columns" changed in Mars
+ * @test test that fields separated by extra blank lines are not considered separate groups when aligning
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=470506"
+ */
+public void testBug470506() {
+ this.formatterPrefs.align_type_members_on_columns = true;
+ String source =
+ "class C {\r\n" +
+ " private int iii;\r\n" +
+ " String sss;\r\n" +
+ "\r\n" +
+ " protected ArrayList<Integer> aaa;\r\n" +
+ "\r\n" +
+ "}";
+ formatSource(source);
+}
}
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/FieldAligner.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/FieldAligner.java
index 121e36ff10..a548f48de5 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/FieldAligner.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/FieldAligner.java
@@ -25,7 +25,6 @@ import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
import org.eclipse.jdt.internal.formatter.Token;
import org.eclipse.jdt.internal.formatter.TokenManager;
import org.eclipse.jdt.internal.formatter.TokenTraverser;
@@ -68,20 +67,16 @@ public class FieldAligner {
final TokenManager tm;
- private final DefaultCodeFormatterOptions options;
-
- public FieldAligner(TokenManager tokenManager, DefaultCodeFormatterOptions options) {
+ public FieldAligner(TokenManager tokenManager) {
this.tm = tokenManager;
- this.options = options;
}
public void prepareAlign(TypeDeclaration node) {
List<FieldDeclaration> bodyDeclarations = node.bodyDeclarations();
ArrayList<FieldDeclaration> alignGroup = new ArrayList<>();
- BodyDeclaration previous = null;
for (BodyDeclaration declaration : bodyDeclarations) {
if (!alignGroup.isEmpty()) {
- if ((declaration instanceof FieldDeclaration) && !areSeparated(previous, declaration)) {
+ if ((declaration instanceof FieldDeclaration)) {
alignGroup.add((FieldDeclaration) declaration);
} else {
alignFields(alignGroup);
@@ -92,28 +87,10 @@ public class FieldAligner {
if (declaration instanceof FieldDeclaration)
alignGroup.add((FieldDeclaration) declaration);
}
- previous = declaration;
}
alignFields(alignGroup);
}
- private boolean areSeparated(BodyDeclaration declaration1, BodyDeclaration declaration2) {
- // check if there are more empty lines between fields than normal
- if (this.options.number_of_empty_lines_to_preserve <= this.options.blank_lines_before_field)
- return false;
- int maxLineBreaks = 0;
- int from = this.tm.lastIndexIn(declaration1, -1);
- int to = this.tm.firstIndexIn(declaration2, -1);
-
- Token previous = this.tm.get(from);
- for (int i = from + 1; i <= to; i++) {
- Token token = this.tm.get(i);
- maxLineBreaks = Math.max(maxLineBreaks, this.tm.countLineBreaksBetween(previous, token));
- previous = token;
- }
- return maxLineBreaks - 1 > this.options.blank_lines_before_field;
- }
-
private void alignFields(ArrayList<FieldDeclaration> alignGroup) {
if (alignGroup.size() < 2)
return;
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
index 259b3e6594..2e1362c577 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
@@ -182,7 +182,7 @@ public class WrapPreparator extends ASTVisitor {
if (this.options.align_type_members_on_columns) {
if (this.fieldAligner == null) {
- this.fieldAligner = new FieldAligner(this.tm, this.options);
+ this.fieldAligner = new FieldAligner(this.tm);
}
this.fieldAligner.prepareAlign(node);
}

Back to the top