Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHansruedi Patzen2019-06-21 10:12:38 -0400
committerMarco Stornelli2019-06-25 12:32:23 -0400
commit9fe897881749cf5c622d205eba8953ce68986abd (patch)
tree1aaf848fe97a1533f5a918b7c499cb81a767df4a /core/org.eclipse.cdt.core
parente435167a1a912c7f2f94cf02006d4010907510ed (diff)
downloadorg.eclipse.cdt-9fe897881749cf5c622d205eba8953ce68986abd.tar.gz
org.eclipse.cdt-9fe897881749cf5c622d205eba8953ce68986abd.tar.xz
org.eclipse.cdt-9fe897881749cf5c622d205eba8953ce68986abd.zip
Bug 548512: Declarator formatting multiple keywords between pointers
Bugfix and removal of code duplication. Change-Id: Id6a94c4cf59311f287b73e09019ddd323361fdc7 Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch>
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index 61dcd0e17b..406bbf4039 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -22,6 +22,7 @@ import java.util.EmptyStackException;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
+import java.util.function.Predicate;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@@ -1659,22 +1660,23 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
}
private boolean skipConstVolatileRestrict(boolean spaceBefore) {
- boolean skipped = false;
- int token = peekNextToken();
- while (token == Token.t_const || token == Token.t_volatile || token == Token.t_restrict) {
- scribe.printNextToken(token, spaceBefore);
- token = peekNextToken();
- skipped = true;
- }
- return skipped;
+ return skipTokenWhile(token -> token == Token.t_const || token == Token.t_volatile || token == Token.t_restrict,
+ spaceBefore);
}
private boolean skipMutableConstexpr() {
+ return skipTokenWhile(token -> token == Token.t_mutable || token == Token.t_constexpr, true);
+ }
+
+ private boolean skipTokenWhile(Predicate<Integer> pred, boolean spaceBefore) {
boolean skipped = false;
int token = peekNextToken();
- while (token == Token.t_mutable || token == Token.t_constexpr) {
- scribe.printNextToken(token, true);
+ while (pred.test(token)) {
+ scribe.printNextToken(token, spaceBefore);
token = peekNextToken();
+ if (!spaceBefore && pred.test(token)) {
+ scribe.space();
+ }
skipped = true;
}
return skipped;

Back to the top