1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

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>
This commit is contained in:
Hansruedi Patzen 2019-06-21 16:12:38 +02:00 committed by Marco Stornelli
parent e435167a1a
commit 9fe8978817
2 changed files with 32 additions and 10 deletions

View file

@ -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;

View file

@ -4337,4 +4337,24 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testAssigmentWithInitList_Bug547684() throws Exception {
assertFormatterResult();
}
//void func(int *const volatile&p) {
//}
//void func(int *const volatile&p) {
//}
public void testConstVolatileParam_Bug548512() throws Exception {
assertFormatterResult();
}
//struct Foo {
// int *const volatile&p;
//};
//struct Foo {
// int *const volatile&p;
//};
public void testConstVolatileMember_Bug548512() throws Exception {
assertFormatterResult();
}
}