Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] how to add a statement into an empty .CPP file
  • From: Ming Cheng <chengm349@xxxxxxxxxxx>
  • Date: Mon, 17 Feb 2020 07:37:54 +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=eWXZdQcmsjBp9njuwQwB+zsBPGwxcKPEG3Pvy9aViLQ=; b=SlfsZGBRVOeBKOMp+NQUpx4PtkrXITyEibjy7sjY/FiDlcVp51upSat5QMo7gMVTeVqadvAomkeynNt6Y+tFEC1iixXDHb53HGVahcKFFJdmt1n2sCFvv0iDiTtqvaFAdEXgPtrvokt/+XS+kOgYvZaNdaKWkct88pMaSVpDQf/VMiI2173ChCGp2M1Ds4j1K9JCDBoE5Rjvu/ZegUIaYz07o/92F4OL4kCjuAJfMAWvPTPR4G4Ok82dUoA3WyMUkj3sT2tI6mmPrUbaH4d+MIwSiYvxdamHr/X62VDfAcQtEoawWxEnqZa2cHtK8MWDRiPJ6Murz3/CBpVcmE5ScQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JnnshChbAdmufprg880JwVRd5DvnO1sPe9BpH+2UQX061z8CYpzVhkw6gtLcMyKKA8Di1760XrdRPKNkvCOGvUNRaAASlx5qLhH28oIr+5RjU8afcuREK8ZroO1MD8MpGl6AA/kcIiakAHIiUCZKbfNaoextDQQtUG2BKdEPGlIbFllXJqFcgY0Cz8M3jMmPRCBuYz/vBrcYS6Nodr3Xv6Wdm0+iHPwyvq/eKuKKnXAIWBPXwPwrrw75z6QF/0CUh7a+isc7raBZIWqcH4qRQXPKxQYbWyZLLC8i87nzHXl+I++cQbr0fhwKMwMpuckuK5ar9JRYxocT9EAEjMCZUw==
  • 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/jIEKUv795wi97Mg==
  • Thread-topic: 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