mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug fixes.
This commit is contained in:
parent
ed9db92e40
commit
da8a1d0b28
3 changed files with 92 additions and 10 deletions
|
@ -263,7 +263,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean needSpace = skipConstVolatileRestrict();
|
boolean needSpace = skipConstVolatileRestrict();
|
||||||
if (node.getExceptionSpecification() != null && peekNextToken() == Token.t_throw)
|
int token = peekNextToken();
|
||||||
|
if (token == Token.t_throw || token == Token.tIDENTIFIER)
|
||||||
return;
|
return;
|
||||||
// Skip the rest (=0)
|
// Skip the rest (=0)
|
||||||
if (needSpace && scribe.printComment()) {
|
if (needSpace && scribe.printComment()) {
|
||||||
|
@ -862,6 +863,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTStatement node) {
|
public int visit(IASTStatement node) {
|
||||||
|
if (startsWithMacroExpansion(node))
|
||||||
|
scribe.printCommentPreservingNewLines();
|
||||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||||
int indentLevel= scribe.indentationLevel;
|
int indentLevel= scribe.indentationLevel;
|
||||||
try {
|
try {
|
||||||
|
@ -1341,21 +1344,51 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
private int visit(ICPPASTFunctionDeclarator node) {
|
private int visit(ICPPASTFunctionDeclarator node) {
|
||||||
final List<ICPPASTParameterDeclaration> parameters = Arrays.asList(node.getParameters());
|
final List<ICPPASTParameterDeclaration> parameters = Arrays.asList(node.getParameters());
|
||||||
final ListOptions options = createListOptionsForFunctionDeclarationParameters();
|
final ListOptions options = createListOptionsForFunctionDeclarationParameters();
|
||||||
|
Runnable tailFormatter = scribe.getTailFormatter();
|
||||||
formatList(parameters, options, true, node.takesVarArgs(),
|
formatList(parameters, options, true, node.takesVarArgs(),
|
||||||
new CPPFunctionDeclaratorTailFormatter(node, scribe.getTailFormatter()));
|
new CPPFunctionDeclaratorTailFormatter(node, tailFormatter));
|
||||||
|
|
||||||
IASTFileLocation fileLocation= node.getFileLocation();
|
IASTFileLocation fileLocation= node.getFileLocation();
|
||||||
if (fileLocation != null &&
|
if (fileLocation != null &&
|
||||||
scribe.scanner.getCurrentPosition() < fileLocation.getNodeOffset() + fileLocation.getNodeLength()) {
|
scribe.scanner.getCurrentPosition() < fileLocation.getNodeOffset() + fileLocation.getNodeLength()) {
|
||||||
skipConstVolatileRestrict();
|
skipConstVolatileRestrict();
|
||||||
|
|
||||||
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
int token = peekNextToken();
|
||||||
if (exceptionSpecification != null && peekNextToken() == Token.t_throw)
|
if (token == Token.t_throw || token == Token.tIDENTIFIER) {
|
||||||
formatExceptionSpecification(exceptionSpecification);
|
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
||||||
// Skip the rest (=0)
|
if (exceptionSpecification != null && token == Token.t_throw)
|
||||||
scribe.printTrailingComment();
|
formatExceptionSpecification(exceptionSpecification);
|
||||||
scribe.space();
|
if (peekNextToken() == Token.tIDENTIFIER) {
|
||||||
skipNode(node);
|
Alignment alignment = scribe.createAlignment(
|
||||||
|
Alignment.TRAILING_TEXT,
|
||||||
|
Alignment.M_COMPACT_SPLIT,
|
||||||
|
1,
|
||||||
|
scribe.scanner.getCurrentPosition());
|
||||||
|
|
||||||
|
scribe.enterAlignment(alignment);
|
||||||
|
boolean ok = false;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
scribe.alignFragment(alignment, 0);
|
||||||
|
// Skip the rest of the declarator.
|
||||||
|
scribe.printTrailingComment();
|
||||||
|
scribe.space();
|
||||||
|
if (tailFormatter != null)
|
||||||
|
tailFormatter.run();
|
||||||
|
skipNode(node);
|
||||||
|
ok = true;
|
||||||
|
} catch (AlignmentException e) {
|
||||||
|
scribe.redoAlignment(e);
|
||||||
|
}
|
||||||
|
} while (!ok);
|
||||||
|
scribe.exitAlignment(alignment, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Skip the rest (=0)
|
||||||
|
scribe.printTrailingComment();
|
||||||
|
scribe.space();
|
||||||
|
skipNode(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,10 @@ public class Alignment {
|
||||||
public static final String EXCEPTION_SPECIFICATION = "exceptionSpecification"; //$NON-NLS-1$
|
public static final String EXCEPTION_SPECIFICATION = "exceptionSpecification"; //$NON-NLS-1$
|
||||||
public static final String FIELD_REFERENCE = "fieldReference"; //$NON-NLS-1$
|
public static final String FIELD_REFERENCE = "fieldReference"; //$NON-NLS-1$
|
||||||
public static final String FOR = "for"; //$NON-NLS-1$
|
public static final String FOR = "for"; //$NON-NLS-1$
|
||||||
public static final String MACRO_ARGUMENTS = "macroArguments"; //$NON-NLS-1$
|
|
||||||
public static final String LIST_ELEMENTS_PREFIX = "listElements_"; //$NON-NLS-1$
|
public static final String LIST_ELEMENTS_PREFIX = "listElements_"; //$NON-NLS-1$
|
||||||
public static final String LIST_FALLBACK_TRAP = "listFallbackTrap"; //$NON-NLS-1$
|
public static final String LIST_FALLBACK_TRAP = "listFallbackTrap"; //$NON-NLS-1$
|
||||||
|
public static final String MACRO_ARGUMENTS = "macroArguments"; //$NON-NLS-1$
|
||||||
|
public static final String TRAILING_TEXT = "trailingText"; //$NON-NLS-1$
|
||||||
|
|
||||||
/** The name of the alignment */
|
/** The name of the alignment */
|
||||||
public String name;
|
public String name;
|
||||||
|
|
|
@ -991,6 +991,27 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#define ABSTRACT = 0
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
// virtual bool function_with_a_loooooong_name(const char* parameter) ABSTRACT;
|
||||||
|
// virtual bool function_with_a_looooooong_name(const char* parameter) ABSTRACT;
|
||||||
|
//};
|
||||||
|
|
||||||
|
//#define ABSTRACT = 0
|
||||||
|
//
|
||||||
|
//class A {
|
||||||
|
// virtual bool function_with_a_loooooong_name(const char* parameter) ABSTRACT;
|
||||||
|
// virtual bool function_with_a_looooooong_name(const char* parameter)
|
||||||
|
// ABSTRACT;
|
||||||
|
//};
|
||||||
|
public void testFunctionDeclarationTrailingMacro() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION,
|
||||||
|
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
//void f1(const char* long_parameter_name,int very_looooooooong_parameter_name){}
|
//void f1(const char* long_parameter_name,int very_looooooooong_parameter_name){}
|
||||||
//void f2(const char* long_parameter_name,int very_loooooooooong_parameter_name){}
|
//void f2(const char* long_parameter_name,int very_loooooooooong_parameter_name){}
|
||||||
|
|
||||||
|
@ -1065,6 +1086,33 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#define STREAM GetStream()
|
||||||
|
//class Stream {
|
||||||
|
//Stream& operator <<(const char*);
|
||||||
|
//};
|
||||||
|
//Stream GetStream();
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
// // comment
|
||||||
|
//STREAM << "text " << "text " << "text " << "text " << "text " << "text " << "text " << "text ";
|
||||||
|
//}
|
||||||
|
|
||||||
|
//#define STREAM GetStream()
|
||||||
|
//class Stream {
|
||||||
|
// Stream& operator <<(const char*);
|
||||||
|
//};
|
||||||
|
//Stream GetStream();
|
||||||
|
//
|
||||||
|
//void test() {
|
||||||
|
// // comment
|
||||||
|
// STREAM << "text " << "text " << "text " << "text " << "text " << "text "
|
||||||
|
// << "text " << "text ";
|
||||||
|
//}
|
||||||
|
public void testMacroAfterComment() throws Exception {
|
||||||
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
//#define MY_MACRO(a, b, c)
|
//#define MY_MACRO(a, b, c)
|
||||||
//
|
//
|
||||||
//MY_MACRO(abcdefghijklmnopqrstuvwxyz,25,"very very very very very very very very very very long text");
|
//MY_MACRO(abcdefghijklmnopqrstuvwxyz,25,"very very very very very very very very very very long text");
|
||||||
|
|
Loading…
Add table
Reference in a new issue