Bug 267888 - ASTWriterVisitor.writeLeadingComments() should use IASTNode
Summary: ASTWriterVisitor.writeLeadingComments() should use IASTNode
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 5.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 6.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Emanuel Graf CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2009-03-10 11:56 EDT by Richard Miskin CLA
Modified: 2009-04-01 07:24 EDT (History)
0 users

See Also:


Attachments
Patch to remove use of ASTNode (4.87 KB, patch)
2009-03-28 05:59 EDT, Richard Miskin CLA
mschorn.eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Miskin CLA 2009-03-10 11:56:05 EDT
Build ID: I20080617-2000

Currently ASTWriterVisitor.writeLeadingComments() takes an ASTNode (which is an internal class) and the methods that call it cast their to ASTNode without testing. For example:
	@Override
	public int visit(IASTDeclaration declaration) {
		writeLeadingComments((ASTNode) declaration);
		if(!macroHandler.checkisMacroExpansionNode(declaration)) {
			declarationWriter.writeDeclaration(declaration);
		}
		return  ASTVisitor.PROCESS_SKIP;
	}


This works when using an AST produced from the default CDT parser, but when I use my ILanguage implementation this leads to a ClassCastException because my implementations of IASTDeclaration do not extend ASTNode.

If writeLeadingComments is changed to take an IASTNode then the cast is not required and the code seems to work.

More information:
I've hit this problem with CDT 5.0 but the code looks the same in HEAD. A fix for CDT 5.0.x would be helpful.
Comment 1 Richard Miskin CLA 2009-03-28 05:59:34 EDT
Created attachment 130159 [details]
Patch to remove use of ASTNode

Here's a patch to remove the use of ASTNode and the unchecked casts. I reran the AstWriterTestSuite and got the same results with and without the patch (everything passes except DeclaratorTests.CPPFunctionDeclaratorTest).
Comment 2 Markus Schorn CLA 2009-04-01 07:24:01 EDT
Thanks, I have applied your patch.
Fixed in 6.0 > 20090401.