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: Tue, 18 Feb 2020 01:36:07 +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=XiguLNeqEeBhPGdzUQyz7c+UXHRUPIhMhzky+WLqxXQ=; b=Lu4gjOBxZouuaykNbr/C3go27hB5XN5ulYU7Wuvox6ZPMb9rh5WskEHYPDluK6yaSOm0WhpReOck5lAuzGzpRwQWaEIij6dBQGg3K2hwUbLpYDZqt9/hm7rChRMTYgLhK8B8MG6d+GOg9HRMuYgK/5pPY8GGv/LmDM0bFIpe1RV0kTv0mdiTnOfbrAKhL8c95vjOUDqBOWpLiw+OG2dFK7wLAUNeXFLmPfCutcF9Agf4nSNEkukupfmJp++qLN66OUWIuefrA7URkDd3kUz27bGoKNE2AWpEPrO6ObYWrR/56EIdrIZNKXBYSWm9V1j76FyT/oPzHg76xj1ET+Tghw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=emggMUJ97IatS4VKyNLBxSDdnBp2LeA/o20kPZhPAsWMEJIgCeUDK6qi0C2eOF17bUthESKBG6I5xLMxGdZazpjHfFFkKYkqA5BeWgIP8tr80omWmMJe8vyQH6ZZDhOPqPZsW0XWP/qb72HfLEN/zplufDJDqLpX6mxgIuByS0BvuVwCw3VkvRRAc3P7yd8/kragfi7MIVQwLeKmbcSLdejOgzMMpy9GCLPlhGntaXpKSZ7nk/Nbp2V8T+e6Uin6cUNcaQjOhMYQQzgOZhLU6BAdiSPduaoA/FePisBsWijlNOqVs8ynKdRNrxT0oZaV3OhLqiw0hSrANrAKKc6KJA==
  • 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/jIEKUv795wi97MqggDmP5gAAeFY0=
  • Thread-topic: how to add a statement into an empty .CPP file

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


From: Ming Cheng <chengm349@xxxxxxxxxxx>
Sent: Monday, February 17, 2020 11:47 PM
To: cdt-dev@xxxxxxxxxxx <cdt-dev@xxxxxxxxxxx>
Subject: Re: 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