1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for Bug 169382 - default formatter can't format "struct xxx get(){}"

This commit is contained in:
Anton Leherbauer 2007-01-10 12:17:54 +00:00
parent 095910e7bf
commit b27b8766ae
5 changed files with 26 additions and 10 deletions

View file

@ -650,6 +650,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
final int line= scribe.line; final int line= scribe.line;
IASTDeclSpecifier declSpec= node.getDeclSpecifier(); IASTDeclSpecifier declSpec= node.getDeclSpecifier();
declSpec.accept(this); declSpec.accept(this);
if (scribe.printComment()) {
scribe.space();
}
IASTFunctionDeclarator decl= node.getDeclarator(); IASTFunctionDeclarator decl= node.getDeclarator();
decl.accept(this); decl.accept(this);
IASTStatement bodyStmt= node.getBody(); IASTStatement bodyStmt= node.getBody();
@ -781,7 +784,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
declSpec.accept(this); declSpec.accept(this);
final List declarators= Arrays.asList(node.getDeclarators()); final List declarators= Arrays.asList(node.getDeclarators());
if (declarators.size() > 0) { if (declarators.size() > 0) {
scribe.space(); if (scribe.printComment()) {
scribe.space();
}
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT); final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
formatList(declarators, align, false, false); formatList(declarators, align, false, false);
} }
@ -817,13 +822,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTSimpleDeclSpecifier node) { private int visit(IASTSimpleDeclSpecifier node) {
formatNode(node); formatNode(node);
scribe.space();
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(IASTNamedTypeSpecifier node) { private int visit(IASTNamedTypeSpecifier node) {
formatNode(node); formatNode(node);
scribe.space();
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1557,7 +1560,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
private void formatNode(IASTNode node) { private void formatNode(IASTNode node) {
scribe.printComment(); if (scribe.printComment()) {
scribe.space();
}
IASTNodeLocation location= node.getFileLocation(); IASTNodeLocation location= node.getFileLocation();
if (location != null) { if (location != null) {
scribe.printRaw(location.getNodeOffset(), location.getNodeLength()); scribe.printRaw(location.getNodeOffset(), location.getNodeLength());

View file

@ -0,0 +1,5 @@
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169382
struct x {
};
struct x getX() {
}

View file

@ -0,0 +1,3 @@
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=169382
struct x {};
struct x getX() {}

View file

@ -12,16 +12,16 @@ class Foo {
// TEMPLATE_STRUCT // TEMPLATE_STRUCT
template<class Key, class Value, class SortAlgorithm=DefaultSort> struct Map { template<class Key, class Value, class SortAlgorithm=DefaultSort> struct Map {
Key * keys; Key* keys;
Value * values; Value* values;
SortAlgorithm * sortAlgorithm; SortAlgorithm* sortAlgorithm;
Map(); Map();
}; };
// TEMPLATE_CLASS // TEMPLATE_CLASS
template<class T> class nonVector { template<class T> class nonVector {
private: private:
T * head; T* head;
public: public:
nonVector() { nonVector() {
@ -30,7 +30,7 @@ public:
int length() { int length() {
return 1; return 1;
} }
const T &first() const; const T& first() const;
}; };
// TEMPLATE_UNION // TEMPLATE_UNION
@ -52,7 +52,7 @@ class TemplateContainer {
}; };
// TEMPLATE_FUNCTION // TEMPLATE_FUNCTION
template<class T> const T &nonVector<T>::first() const { template<class T> const T& nonVector<T>::first() const {
return *head; return *head;
} }

View file

@ -131,4 +131,7 @@ public class FormatActionTest extends TestCase {
assertFormatResult(); assertFormatResult();
} }
public void testBugs() throws Exception {
}
} }