mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 357300 - Function parameter line wrapping wraps commas separating
parameters. Corrected fix.
This commit is contained in:
parent
6e0285bb2a
commit
4bca28c52f
3 changed files with 71 additions and 6 deletions
|
@ -211,10 +211,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
spaceBeforeToken, spaceAfterToken);
|
spaceBeforeToken, spaceAfterToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrailingTokenFormatter(int tokenType, boolean spaceBeforeToken, boolean spaceAfterToken) {
|
|
||||||
this(tokenType, scribe.findToken(tokenType), spaceBeforeToken, spaceAfterToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
int offset = scribe.scanner.getCurrentPosition();
|
int offset = scribe.scanner.getCurrentPosition();
|
||||||
if (tokenPosition < 0 || offset > tokenPosition)
|
if (tokenPosition < 0 || offset > tokenPosition)
|
||||||
|
@ -2092,6 +2088,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
if (i < elementsLength - 1) {
|
if (i < elementsLength - 1) {
|
||||||
scribe.setTailFormatter(
|
scribe.setTailFormatter(
|
||||||
new TrailingTokenFormatter(options.fSeparatorToken,
|
new TrailingTokenFormatter(options.fSeparatorToken,
|
||||||
|
findTokenAfterNode(options.fSeparatorToken, node),
|
||||||
options.fSpaceBeforeSeparator,
|
options.fSpaceBeforeSeparator,
|
||||||
options.fSpaceAfterSeparator));
|
options.fSpaceAfterSeparator));
|
||||||
} else {
|
} else {
|
||||||
|
@ -4336,4 +4333,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
int endOffset = location.getNodeOffset() + location.getNodeLength();
|
int endOffset = location.getNodeOffset() + location.getNodeLength();
|
||||||
return scribe.findToken(tokenType, endOffset);
|
return scribe.findToken(tokenType, endOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int findTokenAfterNode(int tokenType, IASTNode node) {
|
||||||
|
IASTFileLocation location = node.getFileLocation();
|
||||||
|
int startOffset = location.getNodeOffset() + location.getNodeLength();
|
||||||
|
return scribe.findToken(tokenType, startOffset, scribe.scannerEndPosition - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1926,7 +1926,7 @@ public class Scribe {
|
||||||
* The scanner position is left unchanged.
|
* The scanner position is left unchanged.
|
||||||
*
|
*
|
||||||
* @param tokenType type of the token to look for
|
* @param tokenType type of the token to look for
|
||||||
* @return <code>true</code> if a matching token was found
|
* @return the position of the matching token, if found, otherwise -1.
|
||||||
*/
|
*/
|
||||||
public int findToken(int tokenType) {
|
public int findToken(int tokenType) {
|
||||||
return findToken(tokenType, scannerEndPosition - 1);
|
return findToken(tokenType, scannerEndPosition - 1);
|
||||||
|
@ -1939,7 +1939,7 @@ public class Scribe {
|
||||||
*
|
*
|
||||||
* @param tokenType type of the token to look for
|
* @param tokenType type of the token to look for
|
||||||
* @param endPosition end position limiting the search
|
* @param endPosition end position limiting the search
|
||||||
* @return <code>true</code> if a matching token was found
|
* @return the position of the matching token, if found, otherwise -1.
|
||||||
*/
|
*/
|
||||||
public int findToken(int tokenType, int endPosition) {
|
public int findToken(int tokenType, int endPosition) {
|
||||||
int startPosition= scanner.getCurrentPosition();
|
int startPosition= scanner.getCurrentPosition();
|
||||||
|
@ -2002,6 +2002,26 @@ public class Scribe {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for the next occurrence of the given token type.
|
||||||
|
* If successful, returns the offset of the found token, otherwise -1.
|
||||||
|
* The scanner position is left unchanged.
|
||||||
|
*
|
||||||
|
* @param tokenType type of the token to look for
|
||||||
|
* @param startPosition position where to start the search
|
||||||
|
* @param endPosition end position limiting the search
|
||||||
|
* @return the position of the matching token, if found, otherwise -1.
|
||||||
|
*/
|
||||||
|
public int findToken(int tokenType, int startPosition, int endPosition) {
|
||||||
|
int currentPosition= scanner.getCurrentPosition();
|
||||||
|
try {
|
||||||
|
scanner.resetTo(startPosition, scannerEndPosition - 1);
|
||||||
|
return findToken(tokenType, endPosition);
|
||||||
|
} finally {
|
||||||
|
scanner.resetTo(currentPosition, scannerEndPosition - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean printCommentPreservingNewLines() {
|
public boolean printCommentPreservingNewLines() {
|
||||||
final boolean savedPreserveNL= preserveNewLines;
|
final boolean savedPreserveNL= preserveNewLines;
|
||||||
preserveNewLines= true;
|
preserveNewLines= true;
|
||||||
|
|
|
@ -1176,6 +1176,48 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//int function_with_a_long_name(int, int);
|
||||||
|
//int function_with_an_even_looooooooooooooooonger_name(int, int);
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
//function_with_a_long_name(function_with_an_even_looooooooooooooooonger_name(1000000,2000000),3000000);
|
||||||
|
//function_with_a_long_name(function_with_an_even_looooooooooooooooonger_name(1000000,20000000),3000000);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//int function_with_a_long_name(int, int);
|
||||||
|
//int function_with_an_even_looooooooooooooooonger_name(int, int);
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
// function_with_a_long_name(
|
||||||
|
// function_with_an_even_looooooooooooooooonger_name(1000000, 2000000),
|
||||||
|
// 3000000);
|
||||||
|
// function_with_a_long_name(
|
||||||
|
// function_with_an_even_looooooooooooooooonger_name(1000000,
|
||||||
|
// 20000000), 3000000);
|
||||||
|
//}
|
||||||
|
public void testFunctionCall_4() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
//template<typename T, typename U>
|
||||||
|
//struct type_with_multiple_template_parameters {};
|
||||||
|
//
|
||||||
|
//void wrap_when_necessary(type_with_multiple_template_parameters<char, float> p1, int p2, int p3) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//template<typename T, typename U>
|
||||||
|
//struct type_with_multiple_template_parameters {
|
||||||
|
//};
|
||||||
|
//
|
||||||
|
//void wrap_when_necessary(type_with_multiple_template_parameters<char, float> p1,
|
||||||
|
// int p2, int p3) {
|
||||||
|
//}
|
||||||
|
public void testFunctionCallWithTemplates_Bug357300() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
//void function(const char* s);
|
//void function(const char* s);
|
||||||
//
|
//
|
||||||
//void test() {
|
//void test() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue