[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-dev] Introspecting using CDT
|
Hi there,
I'm trying to add a certain line of code, before each declaration using the
CDT API.
The visit method collects changes in a ASTRewrite object.
After the AST traversal is finished, calling Man.Changes.rewriteAST() causes
a java.lang.NullPointerException
The trace dump is annexed below.
Any hints are appreciated.
The configurations are: Eclipse 3.5.2, with CDT 6.0.2, and Sun JDK 1.6u20,
on Windows 7.
Thanks.
class MMan
{
public ASTRewrite Changes;
MMan(IASTTranslationUnit tu){Changes=ASTRewrite.create(tu);}
}
class MVisitor extends ASTVisitor
{
MMan Man;
MVisitor(MMan man) {shouldVisitStatements=true; Man=man;}
public int visit (IASTStatement Stmt)
{
IASTNode NewNode;
IASTNode ParentNode;
IASTNode ThisNode;
if (Stmt instanceof IASTDeclarationStatement)
{
NewNode=Man.Changes.createLiteralNode("//"+Stmt.getRawSignature());
ThisNode=(IASTNode)Stmt;
ParentNode=ThisNode.getParent();
Man.Changes.insertBefore(ParentNode,ThisNode, NewNode,
null);
}
return PROCESS_CONTINUE;
}
java.lang.NullPointerException
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter.writeCom
poundStatement(StatementWriter.java:380)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter.writeSta
tement(StatementWriter.java:123)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor.visit(A
STWriterVisitor.java:187)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWri
terVisitor.visit(ChangeGeneratorWriterVisitor.java:327)
at
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement.accept(
CPPASTCompoundStatement.java:64)
at
org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter.write(ASTWrite
r.java:82)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.sy
nthTreatment(ChangeGenerator.java:219)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.sy
nthTreatment(ChangeGenerator.java:211)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.vi
sit(ChangeGenerator.java:470)
at
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement.accept(
CPPASTCompoundStatement.java:64)
at
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition.accept
(CPPASTFunctionDefinition.java:161)
at
org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTransl
ationUnit.java:266)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.ge
nerateChange(ChangeGenerator.java:113)
at
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.ge
nerateChange(ChangeGenerator.java:105)
at
org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTR
ewriteAnalyzer.java:24)
at
org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:178)
at plug6.actions.SampleAction.run(SampleAction.java:147)
at
org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at
org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:
229)
at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(Action
ContributionItem.java:584)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionI
tem.java:501)
at
org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContribu
tionItem.java:452)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.
java:113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:
194)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(
EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAp
pLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)