Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] how to add a statement into an empty .CPP file
  • From: Ming Cheng <chengm349@xxxxxxxxxxx>
  • Date: Mon, 17 Feb 2020 23:47:40 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aZjGTlSi12tCraXl6aQM9jImY78nZZbQ5GiRfzeg5EY=; b=W78I4aekxrRMFWg8KMo4aOFpA/B1OXJ7OZhRL/+mIsAkHKzyWdQm9tFK89TjGOnErlgaF0SEhO+Qij7PEgUW+0JHsPb7BbaSD38XgP9IAc7xwObV7S96pJYo6QjJJeYzFqHPNigAJHynzcsXoxP0VGYl6BzJm3ISMoqlF/J36N5sFAdglALQT3tKOhxPCb2ZFzza2qCQ5AdG2loWLJBvP29BR6eYH2ZwRndzzcQ1hL05Lmbp/OUUjFB5NGZWvJRlo8PLhTGjVdfFJnIwQP7A+pVDWHgiG4/euelMS5UCAsjFVwQVlicmCIkgL2iEJODtGjy/30+NMG2GvILaz8Cqxg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KmvIUfI8ww+4FI4nNCtKfWPoI1ivSUyssEBLdGYL99nguy50SptrEKpe9PaZB4njg+TrMQwXCk/RsET3GZGJ+LcUgn52OyMa3rEXrL9Dz74nHpoVknJtD8Wrz/GJlRdxFjbn2uOTqbMZngc0gzV6c5hcGZA/ByOlNaGApRDNarWVyK/px+/NV2VolDaqNj7IAj90U5VplQtdzE7/3RlAVracBcr9AdoQHuSJLdqn11BDoJ2zPF7hSXUX0cwgPn6mnmofwmK5UDjxvY8GPLBFYzfhzLaqXNHU0CQex4u9Ca+sAxKN5HVbRfWCwuQTsmkO7nJUjMLxHcw+UY8ilPcivQ==
  • Delivered-to: cdt-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/cdt-dev>
  • List-help: <mailto:cdt-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHV5WR3HRtSvq/jIEKUv795wi97MqggDmP5
  • Thread-topic: how to add a statement into an empty .CPP file

really hope someone can give a detail guide.


From: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> on behalf of Ming Cheng <chengm349@xxxxxxxxxxx>
Sent: Monday, February 17, 2020 7:37 AM
To: cdt-dev@xxxxxxxxxxx <cdt-dev@xxxxxxxxxxx>
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;
        }
    }

Back to the top