how to add a statement into an empty .CPP file

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to add a statement into an empty .CPP file

Ming Cheng
private void buildMainFunction(IFile file) {
        try {
            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);
            ASTRewrite r = ASTRewrite.create( ast );
            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();
            Change c = r.rewriteAST();
            c.perform(new NullProgressMonitor());            
        } catch (CoreException e) {
            log.error(e.getMessage());
        }
    }

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.

@Override
    public IASTTranslationUnit getAST(IFile file) {
        try {
            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);
            IASTTranslationUnit ast = tu.getAST();
            return ast;
        } catch (CoreException e) {
            log.error(e.getMessage());
            return null;
        }
    }

_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to add a statement into an empty .CPP file

Corbat Thomas

Hi Ming Cheng

 

You need to actually insert/replace/remove a node through the rewriter in order to see something happening. Just creating a new break statement with a factory will not be represented anywhere. For example you could create a new declaration, through the node factory, and insert it at the beginning of the translation unit:

r.insertBefore(ast, null, newDeclaration, null);

 

You might be able to find other applications of the ASTRewrite infrastructure in the refactoring part of the UI plug-in. I hope this helps.

 

Thomas

 

 

From: [hidden email] <[hidden email]> On Behalf Of Ming Cheng
Sent: Montag, 17. Februar 2020 08:38
To: [hidden email]
Subject: [cdt-dev] how to add a statement into an empty .CPP file

 

private void buildMainFunction(IFile file) {

        try {

            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);

            ASTRewrite r = ASTRewrite.create( ast );

            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();

            Change c = r.rewriteAST();

            c.perform(new NullProgressMonitor());            

        } catch (CoreException e) {

            log.error(e.getMessage());

        }

    }

 

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.

 

@Override

    public IASTTranslationUnit getAST(IFile file) {

        try {

            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);

            IASTTranslationUnit ast = tu.getAST();

            return ast;

        } catch (CoreException e) {

            log.error(e.getMessage());

            return null;

        }

    }


_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to add a statement into an empty .CPP file

Ming Cheng
In reply to this post by Ming Cheng
really hope someone can give a detail guide.


From: [hidden email] <[hidden email]> on behalf of Ming Cheng <[hidden email]>
Sent: Monday, February 17, 2020 7:37 AM
To: [hidden email] <[hidden email]>
Subject: [cdt-dev] how to add a statement into an empty .CPP file
 
private void buildMainFunction(IFile file) {
        try {
            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);
            ASTRewrite r = ASTRewrite.create( ast );
            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();
            Change c = r.rewriteAST();
            c.perform(new NullProgressMonitor());            
        } catch (CoreException e) {
            log.error(e.getMessage());
        }
    }

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.

@Override
    public IASTTranslationUnit getAST(IFile file) {
        try {
            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);
            IASTTranslationUnit ast = tu.getAST();
            return ast;
        } catch (CoreException e) {
            log.error(e.getMessage());
            return null;
        }
    }

_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to add a statement into an empty .CPP file

Ming Cheng
Eventually may not receive any help but not bcos I am in ur blacklist 🙂


From: Ming Cheng <[hidden email]>
Sent: Monday, February 17, 2020 11:47 PM
To: [hidden email] <[hidden email]>
Subject: Re: how to add a statement into an empty .CPP file
 
really hope someone can give a detail guide.


From: [hidden email] <[hidden email]> on behalf of Ming Cheng <[hidden email]>
Sent: Monday, February 17, 2020 7:37 AM
To: [hidden email] <[hidden email]>
Subject: [cdt-dev] how to add a statement into an empty .CPP file
 
private void buildMainFunction(IFile file) {
        try {
            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);
            ASTRewrite r = ASTRewrite.create( ast );
            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();
            Change c = r.rewriteAST();
            c.perform(new NullProgressMonitor());            
        } catch (CoreException e) {
            log.error(e.getMessage());
        }
    }

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.

@Override
    public IASTTranslationUnit getAST(IFile file) {
        try {
            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);
            IASTTranslationUnit ast = tu.getAST();
            return ast;
        } catch (CoreException e) {
            log.error(e.getMessage());
            return null;
        }
    }

_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to add a statement into an empty .CPP file

Corbat Thomas
In reply to this post by Ming Cheng

You didn’t receive my reply, did you?

 

Otherwise, I wrote this:

“””

Hi Ming Cheng

 

You need to actually insert/replace/remove a node through the rewriter in order to see something happening. Just creating a new break statement with a factory will not be represented anywhere. For example you could create a new declaration, through the node factory, and insert it at the beginning of the translation unit:

r.insertBefore(ast, null, newDeclaration, null);

 

You might be able to find other applications of the ASTRewrite infrastructure in the refactoring part of the UI plug-in. I hope this helps.

 

Thomas

“””

 

 

From: [hidden email] <[hidden email]> On Behalf Of Ming Cheng
Sent: Dienstag, 18. Februar 2020 00:48
To: [hidden email]
Subject: Re: [cdt-dev] how to add a statement into an empty .CPP file

 

really hope someone can give a detail guide.

 


From: [hidden email] <[hidden email]> on behalf of Ming Cheng <[hidden email]>
Sent: Monday, February 17, 2020 7:37 AM
To: [hidden email] <[hidden email]>
Subject: [cdt-dev] how to add a statement into an empty .CPP file

 

private void buildMainFunction(IFile file) {

        try {

            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);

            ASTRewrite r = ASTRewrite.create( ast );

            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();

            Change c = r.rewriteAST();

            c.perform(new NullProgressMonitor());            

        } catch (CoreException e) {

            log.error(e.getMessage());

        }

    }

 

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.



@Override

    public IASTTranslationUnit getAST(IFile file) {

        try {

            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);

            IASTTranslationUnit ast = tu.getAST();

            return ast;

        } catch (CoreException e) {

            log.error(e.getMessage());

            return null;

        }

    }


_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to add a statement into an empty .CPP file

Ming Cheng
Thomas,

really did not receive any reply.

thanks and I can see break after adding r.insertBefore(ast, null, breakStatement, null); .


From: [hidden email] <[hidden email]> on behalf of Corbat Thomas <[hidden email]>
Sent: Tuesday, February 18, 2020 8:20 AM
To: CDT General developers list. <[hidden email]>
Subject: Re: [cdt-dev] how to add a statement into an empty .CPP file
 

You didn’t receive my reply, did you?

 

Otherwise, I wrote this:

“””

Hi Ming Cheng

 

You need to actually insert/replace/remove a node through the rewriter in order to see something happening. Just creating a new break statement with a factory will not be represented anywhere. For example you could create a new declaration, through the node factory, and insert it at the beginning of the translation unit:

r.insertBefore(ast, null, newDeclaration, null);

 

You might be able to find other applications of the ASTRewrite infrastructure in the refactoring part of the UI plug-in. I hope this helps.

 

Thomas

“””

 

 

From: [hidden email] <[hidden email]> On Behalf Of Ming Cheng
Sent: Dienstag, 18. Februar 2020 00:48
To: [hidden email]
Subject: Re: [cdt-dev] how to add a statement into an empty .CPP file

 

really hope someone can give a detail guide.

 


From: [hidden email] <[hidden email]> on behalf of Ming Cheng <[hidden email]>
Sent: Monday, February 17, 2020 7:37 AM
To: [hidden email] <[hidden email]>
Subject: [cdt-dev] how to add a statement into an empty .CPP file

 

private void buildMainFunction(IFile file) {

        try {

            IASTTranslationUnit ast = CurrentGui.getInstance().getGui().getAST(file);

            ASTRewrite r = ASTRewrite.create( ast );

            IASTBreakStatement breakStatement = ast.getASTNodeFactory().newBreakStatement();

            Change c = r.rewriteAST();

            c.perform(new NullProgressMonitor());            

        } catch (CoreException e) {

            log.error(e.getMessage());

        }

    }

 

PS. file was created successfully. But after this buildMainFunction() call, the file is still empty. If I try ASTRewrite replace(), my program will complain org.umlet.plugin null.



@Override

    public IASTTranslationUnit getAST(IFile file) {

        try {

            ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(file);

            IASTTranslationUnit ast = tu.getAST();

            return ast;

        } catch (CoreException e) {

            log.error(e.getMessage());

            return null;

        }

    }


_______________________________________________
cdt-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev