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

Fix for Bug 173837 - source formatter has problems with exception specifications

This commit is contained in:
Anton Leherbauer 2007-02-19 15:25:32 +00:00
parent 059bc26f02
commit b81075824d
5 changed files with 43 additions and 24 deletions

View file

@ -715,10 +715,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
final int line= scribe.line;
IASTDeclSpecifier declSpec= node.getDeclSpecifier();
declSpec.accept(this);
if (scribe.printComment()) {
IASTFunctionDeclarator decl= node.getDeclarator();
boolean needSpace= scribe.printComment() || (decl.getPointerOperators().length == 0 && decl.getNestedDeclarator() == null);
if (needSpace) {
scribe.space();
}
IASTFunctionDeclarator decl= node.getDeclarator();
decl.accept(this);
IASTStatement bodyStmt= node.getBody();
if (bodyStmt instanceof IASTCompoundStatement) {
@ -742,13 +743,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(ICPPASTFunctionDeclarator node) {
visit((IASTStandardFunctionDeclarator)node);
skipConstVolatile();
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
if (exceptionSpecification != null && exceptionSpecification.length > 0) {
if (exceptionSpecification != null) {
if (peekNextToken() == Token.t_throw) {
// TLETODO [formatter] need special alignment for exception specification
scribe.printNextToken(Token.t_throw, true);
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
formatList(Arrays.asList(exceptionSpecification), align, true, false);
}
}
final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
if (constructorChain != null && constructorChain.length > 0) {
// TLETODO [formatter] need special constructor chain alignment
@ -759,12 +763,21 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
formatList(Arrays.asList(constructorChain), align, false, false);
scribe.unIndent();
}
// skip the rest (const, etc.)
} else {
// skip the rest (=0)
skipNode(node);
}
return PROCESS_SKIP;
}
private void skipConstVolatile() {
int token= peekNextToken();
while (token == Token.t_const || token == Token.t_volatile) {
scribe.printNextToken(token, true);
token= peekNextToken();
}
}
private int visit(IASTStandardFunctionDeclarator node) {
final List parameters = Arrays.asList(node.getParameters());
final ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration);
@ -905,7 +918,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.printComment();
final int line= scribe.line;
// storage class and other modifiers
scribe.printModifiers();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -627,12 +627,6 @@ public class Scribe {
scanner.resetTo(startOffset, startOffset + length - 1);
while (true) {
boolean hasWhitespace= printComment();
if (currentToken == null) {
if (hasWhitespace) {
space();
}
break;
}
currentToken= scanner.nextToken();
if (currentToken == null) {
if (hasWhitespace) {

View file

@ -12,9 +12,14 @@ protected:
};
class AClass : public ABaseClass {
AClass(int x) throw(int);
void test1() const throw(int);
void test2() throw();
};
AClass::AClass(int x) throw(int) :
ABaseClass(x) {
for (int i=0; i < 12;i++) {
}
}
// keep space between decl spec and declarator
int main(int argc, char **argv) {
}

View file

@ -5,5 +5,9 @@ struct x getX() {}
int bug=sizeof(int);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=173837
class ABaseClass {protected:ABaseClass(int x);};
class AClass : public ABaseClass {AClass(int x) throw(int);};
class AClass : public ABaseClass {AClass(int x) throw(int); void test1() const throw(int); void test2() throw();};
AClass::AClass(int x)throw(int):ABaseClass(x){for (int i=0;i < 12;i++) {}}
// keep space between decl spec and declarator
int
main(int argc, char **argv) {
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -26,6 +26,7 @@ import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.cdt.core.CCorePlugin;
@ -66,7 +67,6 @@ public class BasicCEditorTest extends BaseUITestCase {
protected void tearDown () throws Exception {
EditorTestHelper.closeEditor(fEditor);
if (fCProject != null)
CProjectHelper.delete(fCProject);
if (fNonCProject != null) {
@ -76,8 +76,10 @@ public class BasicCEditorTest extends BaseUITestCase {
}
private void setUpEditor(String file) throws PartInitException {
fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
assertNotNull(fEditor);
IEditorPart editor= EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
assertNotNull(editor);
assertTrue(editor instanceof CEditor);
fEditor= (CEditor) editor;
fTextWidget= fEditor.getViewer().getTextWidget();
assertNotNull(fTextWidget);
fAccessor= new Accessor(fTextWidget, StyledText.class);
@ -86,8 +88,10 @@ public class BasicCEditorTest extends BaseUITestCase {
}
private void setUpEditor(File file) throws PartInitException, CModelException {
fEditor= (CEditor) EditorUtility.openInEditor(new ExternalTranslationUnit(fCProject, Path.fromOSString(file.toString()), CCorePlugin.CONTENT_TYPE_CXXSOURCE));
assertNotNull(fEditor);
IEditorPart editor= EditorUtility.openInEditor(new ExternalTranslationUnit(fCProject, Path.fromOSString(file.toString()), CCorePlugin.CONTENT_TYPE_CXXSOURCE));
assertNotNull(editor);
assertTrue(editor instanceof CEditor);
fEditor= (CEditor) editor;
fTextWidget= fEditor.getViewer().getTextWidget();
assertNotNull(fTextWidget);
fAccessor= new Accessor(fTextWidget, StyledText.class);