Skip to content

Instantly share code, notes, and snippets.

@minostro
Last active May 30, 2017 22:02
Show Gist options
  • Save minostro/5ed4a4e5c1377b0cc88476aa00c7f7d0 to your computer and use it in GitHub Desktop.
Save minostro/5ed4a4e5c1377b0cc88476aa00c7f7d0 to your computer and use it in GitHub Desktop.
Join Point Interfaces
JPITypeDecl : TypeDecl ::=
ReturnType:Access Parameters:ParameterDeclaration* Exception:Access*; SuperTypeName:Access SuperArgumentName:Access*;
ExhibitBodyDecl : BodyDecl ::=
ReturnType:Access JPIName:Access Parameter:ParameterDeclaration* Pointcut:PointcutExpr;
CJPAdviceDecl : AdviceDecl;
CJPPointcutExpr: PointcutExpr;
CJPBeforeSpec : BeforeSpec ::= JPIName:Access;
/*the rest of the advice specifications are omitted from this listing*/
jpi void CheckingOut(double price, Customer cus);
aspect Discount {
pointcut CheckingOut(double pPrice, Customer pCustomer):
execution(* ShoppingSession.checkOut(..))
&& args(*,pPrice,*,pCustomer);
void around (double aPrice, Customer aCustomer) : CheckingOut(aPrice, aCustomer) {
double factor = aCustomer.hasBirthdayToday() ? 0.95 : 1;
proceed(aPrice*factor, aCustomer);
}
}
aspect Discount {
void around CheckingOut(double price, Customer c) {
double factor = c.hasBirthday()? 0.95 : 1;
proceed(price*factor, c); }
}
TypeDecl type_declaration = jpi_declaration.d {:return d; :};
BodyDecl class_member_declaration = exhibit_declaration.d {: return d; :};
BodyDecl aspect_body_declaration = cjp_advice_declaration.d {: return d; :};
public static void checkingOut() throws Exception {
throw new Exception();
}
void around(): call(* checkingOut(..) ) {
proceed();
//throw new Exception();
}
public void initLexerKeywords(AbcLexer lexer) {
lexer.addGlobalKeyword(
"jpi", //"exhibits"
new LexerAction_c(
new Integer(Terminals.JPI), //Terminals.EXHIBITS
new Integer(lexer.pointcut_state())
)
);
}
class ShoppingSession {
ShoppingCart cart;
double totalValue;
void checkOut(Item item, double price, int amount, Customer cus){
cart.add(item, amount); //fill shopping cart cus.charge(price); //charge customer
totalValue += price; //increase total value of session
}
}
class ShoppingSession {
exhibits void CheckingOut(double price, Customer c):
execution(* checkOut(..))
&& args(*, price, *, c);
void checkOut(Item item, double price, int amount, Customer cus){
cart.add(item, amount); //fill shopping cart cus.charge(price); //charge customer
totalValue += price; //increase total value of session
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment