Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8e5b6dbe0892eff65b077fe4476d9c3a6b6cf121 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Copyright (c) 2008 Arno Haase.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

Contributors:
    Arno Haase - initial API and implementation
*/
package org.eclipse.xtend.backend.aop;

import org.eclipse.xtend.backend.aop.internal.AdviceScopeCounter;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SyntaxConstants;


/**
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class AroundAdvice {
    private final ExpressionBase _body;
    private final Pointcut _pointcut;
    
    private final boolean _isCacheable;
    
    /**
     * 
     * @param body contains the body of this advice
     * @param pointcut contains the pointcut that guards this advice
     * @param isCacheable This flag marks the advice as "cacheable". This means that the result of its execution
     *         will be cached iff all advice wrapped by it, and the originally wrapped function, 
     *         are cacheable or cached, respectively.
     */
    public AroundAdvice (ExpressionBase body, Pointcut pointcut, boolean isCacheable) {
        _body = body;
        _pointcut = pointcut;
        _isCacheable = isCacheable;
    }

    /**
     * actually evaluates the advice, regardless of caching - that is context sensitive and must
     *  be taken care of by callers
     */
    public Object evaluate (ExecutionContext ctx, AdviceScopeCounter scopeCounter, ThisJoinPoint thisJoinPoint, ThisJoinPointStaticPart thisJoinPointStaticPart) {
        scopeCounter.enterAdvice();
        ctx.getLocalVarContext().getLocalVars().put (SyntaxConstants.THIS_JOINPOINT, thisJoinPoint);
        ctx.getLocalVarContext().getLocalVars().put (SyntaxConstants.THIS_JOINPOINT_STATICPART, thisJoinPointStaticPart);
        
        try {
            return _body.evaluate (ctx);
        }
        finally {
            ctx.getLocalVarContext ().getLocalVars ().remove (SyntaxConstants.THIS_JOINPOINT);
            ctx.getLocalVarContext ().getLocalVars ().remove (SyntaxConstants.THIS_JOINPOINT_STATICPART);
            scopeCounter.leaveAdvice();
        }
    }

    public Pointcut getPointcut () {
        return _pointcut;
    }

    /**
     * This flag determines whether the advice is cacheable. It is intentionally
     *  kept separate from the "cached" flag of the implementing function because
     *  of the different semantics.
     */
    public boolean isCacheable () {
        return _isCacheable;
    }
}

Back to the top