Example usage for org.eclipse.jdt.core.dom Statement getLocationInParent

List of usage examples for org.eclipse.jdt.core.dom Statement getLocationInParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Statement getLocationInParent.

Prototype

public final StructuralPropertyDescriptor getLocationInParent() 

Source Link

Document

Returns the location of this node within its parent, or null if this is a root node.

Usage

From source file:de.ovgu.cide.export.physical.ahead.JakFeatureRefactorer.java

License:Open Source License

static void replaceStatement(Statement target, Statement replacement) {
    ASTNode p = target.getParent();//from   w  w w. j  a  va 2  s  . c o  m

    if (target instanceof Block && !(replacement instanceof Block)) {
        Block b = replacement.getAST().newBlock();
        b.statements().add(replacement);
        replacement = b;
    }

    StructuralPropertyDescriptor prop = target.getLocationInParent();
    if (prop.isSimpleProperty() || prop.isChildProperty()) {
        p.setStructuralProperty(prop, replacement);
    } else if (prop.isChildListProperty()) {
        assert false;
    }

}

From source file:edu.illinois.jflow.core.transformations.code.ExtractClosureRefactoring.java

License:Open Source License

private void createChannels(final CompilationUnitChange result) {
    Statement forStatement = locateEnclosingLoopStatement();

    TextEditGroup insertChannelDesc = new TextEditGroup(
            JFlowRefactoringCoreMessages.ExtractClosureRefactoring_channel_textedit_description);
    result.addTextEditGroup(insertChannelDesc);

    List<Statement> channelStatements = createChannelStatements();

    ChildListPropertyDescriptor forStatementDescriptor = (ChildListPropertyDescriptor) forStatement
            .getLocationInParent();// ww  w .  ja  v a2  s .c  o m
    ListRewrite forStatementListRewrite = fRewriter.getListRewrite(forStatement.getParent(),
            forStatementDescriptor);

    // We use the loop at the anchor point and insert everything before it in alphabetical channel name order
    for (Statement stmt : channelStatements) {
        forStatementListRewrite.insertBefore(stmt, forStatement, insertChannelDesc);
    }
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java

License:Open Source License

/**
 * Visit {@link ASTNode}'s "unconditionally accessible" starting from given {@link Statement}.
 *///from   w  w w .j  a  va  2 s  .c o  m
private static void visitStatement(VisitingContext context, ExecutionFlowDescription flowDescription,
        Statement statement, ExecutionFlowFrameVisitor visitor) {
    // check if we already visited MethodDeclaration
    if (statement.getLocationInParent() == MethodDeclaration.BODY_PROPERTY) {
        MethodDeclaration methodDeclaration = (MethodDeclaration) statement.getParent();
        if (context.visitedMethods.contains(methodDeclaration)) {
            return;
        }
        context.visitedMethods.add(methodDeclaration);
    }
    // visit "binary flow" methods that should be visited BEFORE current Statement
    visitBinaryFlowMethods(true, context, flowDescription, statement, visitor);
    // visit current Statement
    flowDescription.enterStatement(statement);
    try {
        visitStatement0(context, flowDescription, statement, visitor);
    } finally {
        flowDescription.leaveStatement(statement);
    }
    // visit "binary flow" methods that should be visited AFTER current Statement
    visitBinaryFlowMethods(false, context, flowDescription, statement, visitor);
}