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:
parent
059bc26f02
commit
b81075824d
5 changed files with 43 additions and 24 deletions
|
@ -715,10 +715,11 @@ 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()) {
|
IASTFunctionDeclarator decl= node.getDeclarator();
|
||||||
|
boolean needSpace= scribe.printComment() || (decl.getPointerOperators().length == 0 && decl.getNestedDeclarator() == null);
|
||||||
|
if (needSpace) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
IASTFunctionDeclarator decl= node.getDeclarator();
|
|
||||||
decl.accept(this);
|
decl.accept(this);
|
||||||
IASTStatement bodyStmt= node.getBody();
|
IASTStatement bodyStmt= node.getBody();
|
||||||
if (bodyStmt instanceof IASTCompoundStatement) {
|
if (bodyStmt instanceof IASTCompoundStatement) {
|
||||||
|
@ -742,13 +743,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
|
|
||||||
private int visit(ICPPASTFunctionDeclarator node) {
|
private int visit(ICPPASTFunctionDeclarator node) {
|
||||||
visit((IASTStandardFunctionDeclarator)node);
|
visit((IASTStandardFunctionDeclarator)node);
|
||||||
|
skipConstVolatile();
|
||||||
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
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
|
// TLETODO [formatter] need special alignment for exception specification
|
||||||
scribe.printNextToken(Token.t_throw, true);
|
scribe.printNextToken(Token.t_throw, true);
|
||||||
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
||||||
formatList(Arrays.asList(exceptionSpecification), align, true, false);
|
formatList(Arrays.asList(exceptionSpecification), align, true, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
|
final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
|
||||||
if (constructorChain != null && constructorChain.length > 0) {
|
if (constructorChain != null && constructorChain.length > 0) {
|
||||||
// TLETODO [formatter] need special constructor chain alignment
|
// 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);
|
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
||||||
formatList(Arrays.asList(constructorChain), align, false, false);
|
formatList(Arrays.asList(constructorChain), align, false, false);
|
||||||
scribe.unIndent();
|
scribe.unIndent();
|
||||||
}
|
} else {
|
||||||
// skip the rest (const, etc.)
|
// skip the rest (=0)
|
||||||
skipNode(node);
|
skipNode(node);
|
||||||
|
}
|
||||||
return PROCESS_SKIP;
|
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) {
|
private int visit(IASTStandardFunctionDeclarator node) {
|
||||||
final List parameters = Arrays.asList(node.getParameters());
|
final List parameters = Arrays.asList(node.getParameters());
|
||||||
final ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration);
|
final ListAlignment align= new ListAlignment(preferences.alignment_for_parameters_in_method_declaration);
|
||||||
|
@ -905,7 +918,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
scribe.printComment();
|
scribe.printComment();
|
||||||
final int line= scribe.line;
|
final int line= scribe.line;
|
||||||
|
|
||||||
|
|
||||||
// storage class and other modifiers
|
// storage class and other modifiers
|
||||||
scribe.printModifiers();
|
scribe.printModifiers();
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -627,12 +627,6 @@ public class Scribe {
|
||||||
scanner.resetTo(startOffset, startOffset + length - 1);
|
scanner.resetTo(startOffset, startOffset + length - 1);
|
||||||
while (true) {
|
while (true) {
|
||||||
boolean hasWhitespace= printComment();
|
boolean hasWhitespace= printComment();
|
||||||
if (currentToken == null) {
|
|
||||||
if (hasWhitespace) {
|
|
||||||
space();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
currentToken= scanner.nextToken();
|
currentToken= scanner.nextToken();
|
||||||
if (currentToken == null) {
|
if (currentToken == null) {
|
||||||
if (hasWhitespace) {
|
if (hasWhitespace) {
|
||||||
|
|
|
@ -12,9 +12,14 @@ protected:
|
||||||
};
|
};
|
||||||
class AClass : public ABaseClass {
|
class AClass : public ABaseClass {
|
||||||
AClass(int x) throw(int);
|
AClass(int x) throw(int);
|
||||||
|
void test1() const throw(int);
|
||||||
|
void test2() throw();
|
||||||
};
|
};
|
||||||
AClass::AClass(int x) throw(int) :
|
AClass::AClass(int x) throw(int) :
|
||||||
ABaseClass(x) {
|
ABaseClass(x) {
|
||||||
for (int i=0; i < 12;i++) {
|
for (int i=0; i < 12;i++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// keep space between decl spec and declarator
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
}
|
||||||
|
|
|
@ -5,5 +5,9 @@ struct x getX() {}
|
||||||
int bug=sizeof(int);
|
int bug=sizeof(int);
|
||||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=173837
|
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=173837
|
||||||
class ABaseClass {protected:ABaseClass(int x);};
|
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++) {}}
|
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) {
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.jface.text.source.SourceViewer;
|
||||||
import org.eclipse.swt.custom.StyledText;
|
import org.eclipse.swt.custom.StyledText;
|
||||||
import org.eclipse.swt.widgets.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -66,7 +67,6 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
|
|
||||||
protected void tearDown () throws Exception {
|
protected void tearDown () throws Exception {
|
||||||
EditorTestHelper.closeEditor(fEditor);
|
EditorTestHelper.closeEditor(fEditor);
|
||||||
|
|
||||||
if (fCProject != null)
|
if (fCProject != null)
|
||||||
CProjectHelper.delete(fCProject);
|
CProjectHelper.delete(fCProject);
|
||||||
if (fNonCProject != null) {
|
if (fNonCProject != null) {
|
||||||
|
@ -76,8 +76,10 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpEditor(String file) throws PartInitException {
|
private void setUpEditor(String file) throws PartInitException {
|
||||||
fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
|
IEditorPart editor= EditorTestHelper.openInEditor(ResourceTestHelper.findFile(file), true);
|
||||||
assertNotNull(fEditor);
|
assertNotNull(editor);
|
||||||
|
assertTrue(editor instanceof CEditor);
|
||||||
|
fEditor= (CEditor) editor;
|
||||||
fTextWidget= fEditor.getViewer().getTextWidget();
|
fTextWidget= fEditor.getViewer().getTextWidget();
|
||||||
assertNotNull(fTextWidget);
|
assertNotNull(fTextWidget);
|
||||||
fAccessor= new Accessor(fTextWidget, StyledText.class);
|
fAccessor= new Accessor(fTextWidget, StyledText.class);
|
||||||
|
@ -86,8 +88,10 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpEditor(File file) throws PartInitException, CModelException {
|
private void setUpEditor(File file) throws PartInitException, CModelException {
|
||||||
fEditor= (CEditor) EditorUtility.openInEditor(new ExternalTranslationUnit(fCProject, Path.fromOSString(file.toString()), CCorePlugin.CONTENT_TYPE_CXXSOURCE));
|
IEditorPart editor= EditorUtility.openInEditor(new ExternalTranslationUnit(fCProject, Path.fromOSString(file.toString()), CCorePlugin.CONTENT_TYPE_CXXSOURCE));
|
||||||
assertNotNull(fEditor);
|
assertNotNull(editor);
|
||||||
|
assertTrue(editor instanceof CEditor);
|
||||||
|
fEditor= (CEditor) editor;
|
||||||
fTextWidget= fEditor.getViewer().getTextWidget();
|
fTextWidget= fEditor.getViewer().getTextWidget();
|
||||||
assertNotNull(fTextWidget);
|
assertNotNull(fTextWidget);
|
||||||
fAccessor= new Accessor(fTextWidget, StyledText.class);
|
fAccessor= new Accessor(fTextWidget, StyledText.class);
|
||||||
|
|
Loading…
Add table
Reference in a new issue