mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Few formatting fixes.
This commit is contained in:
parent
a88fc6d3b5
commit
f360d64c77
3 changed files with 80 additions and 12 deletions
|
@ -2275,7 +2275,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
scribe.alignFragment(alignment, 0);
|
// In case of macros we may have already passed the expression position.
|
||||||
|
if (positiveExpression != null &&
|
||||||
|
scribe.scanner.getCurrentPosition() <= positiveExpression.getFileLocation().getNodeOffset()) {
|
||||||
|
scribe.alignFragment(alignment, 0);
|
||||||
|
}
|
||||||
scribe.setTailFormatter(new TrailingTokenFormatter(Token.tCOLON, node,
|
scribe.setTailFormatter(new TrailingTokenFormatter(Token.tCOLON, node,
|
||||||
preferences.insert_space_before_colon_in_conditional,
|
preferences.insert_space_before_colon_in_conditional,
|
||||||
preferences.insert_space_after_colon_in_conditional));
|
preferences.insert_space_after_colon_in_conditional));
|
||||||
|
@ -2286,7 +2290,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.runTailFormatter();
|
scribe.runTailFormatter();
|
||||||
|
|
||||||
if (!(negativeExpression instanceof IASTConditionalExpression)) {
|
if (!(negativeExpression instanceof IASTConditionalExpression)) {
|
||||||
scribe.alignFragment(alignment, 1);
|
// In case of macros we may have already passed the expression position.
|
||||||
|
if (scribe.scanner.getCurrentPosition() <= negativeExpression.getFileLocation().getNodeOffset()) {
|
||||||
|
scribe.alignFragment(alignment, 1);
|
||||||
|
}
|
||||||
scribe.setTailFormatter(tailFormatter);
|
scribe.setTailFormatter(tailFormatter);
|
||||||
negativeExpression.accept(this);
|
negativeExpression.accept(this);
|
||||||
scribe.runTailFormatter();
|
scribe.runTailFormatter();
|
||||||
|
@ -2817,16 +2824,19 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < elements.size(); i++) {
|
for (int i = 0; i < elements.size(); i++) {
|
||||||
scribe.alignFragment(alignment, i);
|
node= elements.get(i);
|
||||||
int token= peekNextToken();
|
// In case of macros we may have already passed the operator position.
|
||||||
if (token == Token.tSHIFTL) {
|
if (scribe.scanner.getCurrentPosition() < node.getFileLocation().getNodeOffset()) {
|
||||||
scribe.printNextToken(token, preferences.insert_space_before_binary_operator);
|
scribe.alignFragment(alignment, i);
|
||||||
scribe.printTrailingComment();
|
int token= peekNextToken();
|
||||||
if (preferences.insert_space_after_binary_operator) {
|
if (token == Token.tSHIFTL) {
|
||||||
scribe.space();
|
scribe.printNextToken(token, preferences.insert_space_before_binary_operator);
|
||||||
|
scribe.printTrailingComment();
|
||||||
|
if (preferences.insert_space_after_binary_operator) {
|
||||||
|
scribe.space();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node= elements.get(i);
|
|
||||||
if (i == alignment.fragmentCount - 1) {
|
if (i == alignment.fragmentCount - 1) {
|
||||||
scribe.setTailFormatter(tailFormatter);
|
scribe.setTailFormatter(tailFormatter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ public class Alignment {
|
||||||
i = this.fragmentIndex;
|
i = this.fragmentIndex;
|
||||||
do {
|
do {
|
||||||
if (this.fragmentBreaks[i] == NONE) {
|
if (this.fragmentBreaks[i] == NONE) {
|
||||||
if ((this.mode & M_INDENT_ON_COLUMN) != 0 && i == 0) {
|
if ((this.mode & M_INDENT_ON_COLUMN) != 0 && isFirstBreakableFragment(i)) {
|
||||||
if (this.breakIndentationLevel <= this.alternativeBreakIndentationLevel) {
|
if (this.breakIndentationLevel <= this.alternativeBreakIndentationLevel) {
|
||||||
// Does not make sense to break here unless indentation is reduced.
|
// Does not make sense to break here unless indentation is reduced.
|
||||||
break;
|
break;
|
||||||
|
@ -371,6 +371,14 @@ public class Alignment {
|
||||||
return false; // Cannot split better
|
return false; // Cannot split better
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isFirstBreakableFragment(int i) {
|
||||||
|
while (--i >= 0) {
|
||||||
|
if (this.fragmentBreaks[i] != BREAK_NOT_ALLOWED)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void eraseExistingBreaks(int startFragmentIndex) {
|
private void eraseExistingBreaks(int startFragmentIndex) {
|
||||||
for (int j = startFragmentIndex + 1; j < this.fragmentIndentations.length; j++) {
|
for (int j = startFragmentIndex + 1; j < this.fragmentIndentations.length; j++) {
|
||||||
if (this.fragmentBreaks[j] == BREAK) {
|
if (this.fragmentBreaks[j] == BREAK) {
|
||||||
|
|
|
@ -2535,6 +2535,57 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//bool loooooooooooong_name(int, int);
|
||||||
|
//int loooong_name;
|
||||||
|
//int very_loooooooooooooooooooooooong_name;
|
||||||
|
//
|
||||||
|
//struct Stream {
|
||||||
|
//Stream& operator <<(const char*);
|
||||||
|
//};
|
||||||
|
//Stream GetStream();
|
||||||
|
//
|
||||||
|
//struct Voidifier {
|
||||||
|
//void operator&(Stream&);
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#define MY_MACRO(a) (a) ? (void) 0 : Voidifier() & GetStream() << " "
|
||||||
|
//
|
||||||
|
//void test(const char* variable_with_a_loooong_name) {
|
||||||
|
// MY_MACRO(loooooooooooong_name(loooong_name,
|
||||||
|
// very_loooooooooooooooooooooooong_name))
|
||||||
|
// << variable_with_a_loooong_name;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//bool loooooooooooong_name(int, int);
|
||||||
|
//int loooong_name;
|
||||||
|
//int very_loooooooooooooooooooooooong_name;
|
||||||
|
//
|
||||||
|
//struct Stream {
|
||||||
|
// Stream& operator <<(const char*);
|
||||||
|
//};
|
||||||
|
//Stream GetStream();
|
||||||
|
//
|
||||||
|
//struct Voidifier {
|
||||||
|
// void operator&(Stream&);
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//#define MY_MACRO(a) (a) ? (void) 0 : Voidifier() & GetStream() << " "
|
||||||
|
//
|
||||||
|
//void test(const char* variable_with_a_loooong_name) {
|
||||||
|
// MY_MACRO(loooooooooooong_name(loooong_name,
|
||||||
|
// very_loooooooooooooooooooooooong_name))
|
||||||
|
// << variable_with_a_loooong_name;
|
||||||
|
//}
|
||||||
|
public void testOverloadedLeftShiftChain_7() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "2");
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_OVERLOADED_LEFT_SHIFT_CHAIN,
|
||||||
|
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION,
|
||||||
|
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
//struct Stream {
|
//struct Stream {
|
||||||
//Stream& operator <<(const char*);
|
//Stream& operator <<(const char*);
|
||||||
//};
|
//};
|
||||||
|
@ -2572,7 +2623,6 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
//int main() {
|
//int main() {
|
||||||
// std::vector<std::vector<int>> test;
|
// std::vector<std::vector<int>> test;
|
||||||
// // some comment
|
// // some comment
|
||||||
|
|
Loading…
Add table
Reference in a new issue