Search in sources :

Example 1 with ASTRewrite

use of org.eclipse.cdt.core.dom.rewrite.ASTRewrite in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ILTISDummyRenameRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    IASTSimpleDeclaration funcDeclaration = (IASTSimpleDeclaration) ast.getDeclarations()[0];
    IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) funcDeclaration.getDeclarators()[0];
    IASTFunctionDeclarator newDeclarator = declarator.copy();
    IASTName newName = CPPNodeFactory.getDefault().newName("b".toCharArray());
    newDeclarator.setName(newName);
    ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
    rewrite.replace(declarator, newDeclarator, new TextEditGroup(""));
}
Also used : IASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) ASTRewrite(org.eclipse.cdt.core.dom.rewrite.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 2 with ASTRewrite

use of org.eclipse.cdt.core.dom.rewrite.ASTRewrite in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class DummyRenameRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    IASTSimpleDeclaration funcDeclaration = (IASTSimpleDeclaration) ast.getDeclarations()[0];
    IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) funcDeclaration.getDeclarators()[0];
    IASTFunctionDeclarator newDeclarator = declarator.copy();
    IASTName newName = CPPNodeFactory.getDefault().newName("b".toCharArray());
    newDeclarator.setName(newName);
    ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
    rewrite.replace(declarator, newDeclarator, new TextEditGroup(""));
}
Also used : IASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) ASTRewrite(org.eclipse.cdt.core.dom.rewrite.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Aggregations

IASTFunctionDeclarator (org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator)2 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)2 IASTSimpleDeclaration (org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration)2 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)2 ASTRewrite (org.eclipse.cdt.core.dom.rewrite.ASTRewrite)2 TextEditGroup (org.eclipse.text.edits.TextEditGroup)2