Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Matela2015-12-29 01:29:31 +0000
committerMateusz Matela2016-01-07 15:48:53 +0000
commitf94892cb877651745b96250343f9ee01803c2183 (patch)
tree0527966216367469643396dbcd23bbe00c595895
parenta85c891541d5a782db03ec1dd6f5ad51ed405d0b (diff)
downloadeclipse.jdt.core-f94892cb877651745b96250343f9ee01803c2183.tar.gz
eclipse.jdt.core-f94892cb877651745b96250343f9ee01803c2183.tar.xz
eclipse.jdt.core-f94892cb877651745b96250343f9ee01803c2183.zip
Bug 484957 - [formatter] Extra blank lines between consecutive javadoc comments
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java33
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java20
2 files changed, 45 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
index e0624630c6..00be383cdc 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
@@ -7321,4 +7321,37 @@ public void testBug121728() {
"}";
formatSource(source);
}
+/**
+ * https://bugs.eclipse.org/484957 - [formatter] Extra blank lines between consecutive javadoc comments
+ */
+public void testBug484957() {
+ String source =
+ "import java.io.Serializable;\n" +
+ "\n" +
+ "/**********/\n" +
+ "/*** A ****/\n" +
+ "/**********/\n" +
+ "\n" +
+ "public class MyClass implements Serializable {\n" +
+ "\tprivate int field1;\n" +
+ "\n" +
+ "\t/**********/\n" +
+ "\t/*** B ****/\n" +
+ "\t/**********/\n" +
+ "\tpublic void foo() {\n" +
+ "\t}\n" +
+ "\n" +
+ "\t/**********/\n" +
+ "\t/*** C ****/\n" +
+ "\t/**********/\n" +
+ "\tprivate int field2;\n" +
+ "\n" +
+ "\t/**********/\n" +
+ "\t/*** D ****/\n" +
+ "\t/**********/\n" +
+ "\tprivate class NestedType {\n" +
+ "\t}\n" +
+ "}";
+ formatSource(source);
+}
}
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
index c0f4e1301e..3b20152ce2 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java
@@ -98,11 +98,9 @@ public class LineBreaksPreparator extends ASTVisitor {
List<AnnotationTypeDeclaration> types = node.types();
if (!types.isEmpty()) {
if (!imports.isEmpty())
- this.tm.firstTokenIn(types.get(0), -1).putLineBreaksBefore(this.options.blank_lines_after_imports + 1);
- for (int i = 1; i < types.size(); i++) {
- this.tm.firstTokenIn(types.get(i), -1).putLineBreaksBefore(
- this.options.blank_lines_between_type_declarations + 1);
- }
+ putBlankLinesBefore(types.get(0), this.options.blank_lines_after_imports);
+ for (int i = 1; i < types.size(); i++)
+ putBlankLinesBefore(types.get(i), this.options.blank_lines_between_type_declarations);
}
return true;
}
@@ -147,8 +145,7 @@ public class LineBreaksPreparator extends ASTVisitor {
BodyDeclaration previous = null;
for (BodyDeclaration bodyDeclaration : bodyDeclarations) {
if (previous == null) {
- this.tm.firstTokenIn(bodyDeclaration, -1).putLineBreaksBefore(
- this.options.blank_lines_before_first_class_body_declaration + 1);
+ putBlankLinesBefore(bodyDeclaration, this.options.blank_lines_before_first_class_body_declaration);
} else {
int blankLines = 0;
if (bodyDeclaration instanceof FieldDeclaration) {
@@ -163,7 +160,7 @@ public class LineBreaksPreparator extends ASTVisitor {
if (!sameChunk(previous, bodyDeclaration))
blankLines = Math.max(blankLines, this.options.blank_lines_before_new_chunk);
- this.tm.firstTokenIn(bodyDeclaration, -1).putLineBreaksBefore(blankLines + 1);
+ putBlankLinesBefore(bodyDeclaration, blankLines);
}
previous = bodyDeclaration;
}
@@ -180,6 +177,13 @@ public class LineBreaksPreparator extends ASTVisitor {
return false;
}
+ private void putBlankLinesBefore(ASTNode node, int linesCount) {
+ int index = this.tm.firstIndexIn(node, -1);
+ while (index > 0 && this.tm.get(index - 1).tokenType == TokenNameCOMMENT_JAVADOC)
+ index--;
+ this.tm.get(index).putLineBreaksBefore(linesCount + 1);
+ }
+
@Override
public boolean visit(EnumDeclaration node) {
handleBracedCode(node, node.getName(), this.options.brace_position_for_enum_declaration,

Back to the top