return_before_codeFragment.xsl

Weaving Rule that weaves a code fragment before a return statement.
  • srcML element: src:return
  • advice type: before
  • codeModifier type: codeFragment

Example 1

int foo() {
  int i = 10;
  return i;
}

Code Modifier

<codeModifier type="codeFragment">
  <text>i = i * 2;</text>
</codeModifier>

Modified Code

int foo() {
  int i = 10;
  i = i * 2;
  return i;
}

Example 2

If the return statement is inside an if/for/while/do without a block, a block is added by the weaver.

int foo() {
  if( true )
    return 10;
  else
    return 20;
}

Code Modifier

<codeModifier type="codeFragment">
  <text>printf("function returns");</text>
</codeModifier>

Modified Code

int foo() {
  if( true ) {
    printf("function returns");
    return 10;
  } else {
    printf("function returns");
    return 20;
  }
}

Examples in AspectX Sample Library

Examples in AspectX Test Suite

CVS Id:
Author:
ibirrer
Copyright:
2004, P&P Software GmbH