Search in sources :

Example 1 with IASTTranslationUnit

use of org.eclipse.cdt.core.dom.ast.IASTTranslationUnit in project arduino-eclipse-plugin by Sloeber.

the class PdePreprocessor method extendMethodDeclarationsForFile.

private static String extendMethodDeclarationsForFile(String body, IIndex index, ITranslationUnit tu) throws CoreException {
    // add declarations made in ino files.
    String localBody = body;
    IASTTranslationUnit asttu = tu.getAST(index, ITranslationUnit.AST_SKIP_FUNCTION_BODIES | ITranslationUnit.AST_SKIP_ALL_HEADERS);
    IASTNode[] astNodes = asttu.getChildren();
    for (IASTNode astNode : astNodes) {
        if (astNode instanceof CPPASTFunctionDefinition) {
            String addString = astNode.getRawSignature();
            addString = addString.replaceAll("\r\n", NEWLINE);
            addString = addString.replaceAll("\r", NEWLINE);
            addString = addString.replaceAll("//[^\n]+\n", " ");
            addString = addString.replaceAll("\n", " ");
            addString = addString.replaceAll("\\{.*\\}", "");
            if (addString.contains("=") || addString.contains("::")) {
            // ignore when there are assignments in the
            // declaration
            // or when it is a class function
            } else {
                localBody += addString + ';' + NEWLINE;
            }
        }
    }
    return localBody;
}
Also used : CPPASTFunctionDefinition(org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode)

Example 2 with IASTTranslationUnit

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

the class NodeWidget method displayBindings.

private void displayBindings(final TreeItem parent, final IASTNode node, final IBinding binding) throws CoreException {
    final IASTTranslationUnit ast = node.getTranslationUnit();
    for (final IASTName decl : ast.getDeclarationsInAST(binding)) {
        createTreeItem(parent, "declaration;" + decl);
    }
    for (final IASTName def : ast.getDefinitionsInAST(binding)) {
        createTreeItem(parent, "definition;" + def);
    }
    for (final IASTName ref : ast.getReferences(binding)) {
        createTreeItem(parent, "reference;" + ref);
    }
    displayTypeIfPresent(parent, binding);
    final TreeItem typeHierarchy = createTreeItem(parent, "Type Hierarchy;");
    displayTypeHierarchy(typeHierarchy, binding);
    final TreeItem fields = createTreeItem(parent, "Fields;");
    displayFields(fields, binding);
    final TreeItem methods = createTreeItem(parent, "Methods;");
    displayMethods(methods, binding);
}
Also used : IASTName(org.eclipse.cdt.core.dom.ast.IASTName) TreeItem(org.eclipse.swt.widgets.TreeItem) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)

Example 3 with IASTTranslationUnit

use of org.eclipse.cdt.core.dom.ast.IASTTranslationUnit 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 4 with IASTTranslationUnit

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

the class TestRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    collectModificationsCalled = ast != null;
}
Also used : IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)

Example 5 with IASTTranslationUnit

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

the class ILTISTestRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    collectModificationsCalled = ast != null;
}
Also used : IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)

Aggregations

IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)12 IASTFunctionDeclarator (org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator)3 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)3 IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)3 IASTSimpleDeclaration (org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration)3 IASTDeclaration (org.eclipse.cdt.core.dom.ast.IASTDeclaration)2 IASTNodeSelector (org.eclipse.cdt.core.dom.ast.IASTNodeSelector)2 ICPPASTLinkageSpecification (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification)2 ICElement (org.eclipse.cdt.core.model.ICElement)2 CoreException (org.eclipse.core.runtime.CoreException)2 ComparisonResult (ch.hsr.ifs.cdttesting.cdttest.comparison.ASTComparison.ComparisonResult)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 IASTArrayModifier (org.eclipse.cdt.core.dom.ast.IASTArrayModifier)1 IASTConditionalExpression (org.eclipse.cdt.core.dom.ast.IASTConditionalExpression)1 IASTExpression (org.eclipse.cdt.core.dom.ast.IASTExpression)1 IASTFunctionDefinition (org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition)1 IASTIdExpression (org.eclipse.cdt.core.dom.ast.IASTIdExpression)1 IASTInitializer (org.eclipse.cdt.core.dom.ast.IASTInitializer)1