Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Matela2020-09-24 20:36:49 +0000
committerMateusz Matela2020-09-25 14:47:04 +0000
commit984617b8770e11339aeab04088a8c95fb2d28b6e (patch)
tree8bb372712ec0ced0e6823e028f9b3b6894f17a57
parent752c50cbac41dea1ac5f8830e1a6f530a28a1100 (diff)
downloadeclipse.jdt.core-984617b8770e11339aeab04088a8c95fb2d28b6e.tar.gz
eclipse.jdt.core-984617b8770e11339aeab04088a8c95fb2d28b6e.tar.xz
eclipse.jdt.core-984617b8770e11339aeab04088a8c95fb2d28b6e.zip
Bug 222083 - [formatter] Formatting bug for GWT codeI20200927-1800I20200926-1800I20200925-1800
Change-Id: Ide86d89801f2812cee49a0da207483789aac7155 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/FormatterRegressionTests.java13
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java11
2 files changed, 22 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index 2830023f10..976f4c0173 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -15895,4 +15895,17 @@ public void testBug545078j() throws JavaModelException {
this.formatterPrefs.alignment_for_annotations_on_enum_constant = Alignment.M_COMPACT_SPLIT;
formatSourceInWorkspace("test545078", "in.java", "J_out.java");
}
+
+/**
+ * https://bugs.eclipse.org/222083 - [formatter] Formatting bug for GWT code
+ */
+public void testBug222083() {
+ String source =
+ "class C {\n" +
+ " private static native void redirect(String url)/*-{\n" +
+ " $wnd.location = url;\n" +
+ " }-*/;\n" +
+ "}";
+ formatSource(source);
+}
}
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java
index ac03d5fec6..4be5335e40 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2019 Mateusz Matela and others.
+ * Copyright (c) 2014, 2020 Mateusz Matela and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -384,7 +384,14 @@ public class CommentsPreparator extends ASTVisitor {
boolean isHeader = this.tm.isInHeader(commentIndex);
boolean formattingEnabled = (this.options.comment_format_block_comment && !isHeader)
|| (this.options.comment_format_header && isHeader);
- formattingEnabled = formattingEnabled && this.tm.charAt(commentToken.originalStart + 2) != '-';
+ if (this.tm.charAt(commentToken.originalStart + 2) == '-') {
+ if (commentToken.getLineBreaksBefore() > 0 || commentIndex == 0
+ || this.tm.get(commentIndex - 1).getLineBreaksAfter() > 0) {
+ formattingEnabled = false;
+ } else {
+ return;
+ }
+ }
if (formattingEnabled && tokenizeMultilineComment(commentToken)) {
this.commentStructure = commentToken.getInternalStructure();
this.ctm = new TokenManager(this.commentStructure, this.tm);

Back to the top