Extensibility - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Extensibility

Description:

Weaver insert if statement surround the inserted advice body. Two if statements. At weaving time ... Advice body can be only inserted either before, after, or around. ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 11
Provided by: appsrvCs
Category:

less

Transcript and Presenter's Notes

Title: Extensibility


1
Extensibility
  • Pang Wai Man (Raymond)
  • 10 Feb 2006

2
Extensibility
  • Designator
  • Context exposure
  • Inter-type declaration
  • Body

3
Define new pointcut designator
  • Using static method in Java with Javassist
  • Method have to return a boolean value
  • aspect compiler translate into call of the static
    method of the new designator
  • Example
  • paramType1("ColorPoint")
  • static boolean paramType1(CtMethod m, String
    args, JoshContext jc) ..

4
Example
  • static boolean paramType1(CtMethod m,
  • String args, JoshContext jc)
  • CtClass parType
  • m.getMethod().getParameterTypes()0
  • CtClass argType jc.getType(args0)
  • if (parType.subtypeOf(argType))
  • return true
  • if (argType.subtypeOf(parType))
  • jc.setIf("1 instanceof " argType.getName())
  • return true
  • else
  • return false

5
Dynamic designator
  • Dynamic designator run-time type check
  • Weaver insert if statement surround the inserted
    advice body
  • Two if statements
  • At weaving time
  • At runtime
  • Insert if at runtime setIf in JoshContext

6
Context exposure
  • expose method in JoshContext
  • E.g jc.expose("String cname \"" c.getName()
    "\"")
  • Inserted at beginning of advice body
  • String cname "Point"
  • / advice body /
  • Dynamic context is also possible

7
Inter-type declaration
  • Similar to Designator, but void return
  • static void addThrows(CtMethod m,String args,
    JoshContext jc)
  • CtClass type jc.getType(args0)
  • m.addExceptionType(type)
  • Appends exception type to throws list

8
Body
  • Addressing the problem of Section 2.2 of paper
    (Visitor pattern)
  • intro() within("Expr")
  • void accept(Visitor v)
  • v.visitlt josh.getCtClass().getName() gt(this)
  • Substitute at compile time and inserted by weaver
  • "void accept(Visitor v) v.visit"
  • josh.getCtClass().getName()
  • "(this)"

9
Javassist
  • Compile time reflection library
  • Provide a set of join-point objects for inspect
    and alter type signature of class
  • obtain set of join-point objects included in the
    method body (CtMethod)
  • Provide various class information including name,
    signature, exceptions etc of a method
    (MethodCall)
  • Replace method to substitutes given source text

10
Javassist
  • Limitations
  • Cant define a new kind of join-point object
  • Advice body can be only inserted either before,
    after, or around.
  • Limited inspect and alter ability
  • No Control or data flow information among join
    points
  • It is enough for implementing relatively complex
    designator or etc.
Write a Comment
User Comments (0)
About PowerShow.com