summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-25 08:47:35 (EST)
committer ahaase2008-02-25 08:47:35 (EST)
commitebc177783d2614bd09efc4527ef95de6f52ffb27 (patch)
treecf77dd2d1200d27fc85b88818dba09dc95cd6378
parent9e2ea3fa0281ef04eb0265fee86d43a443e8bf8e (diff)
downloadorg.eclipse.xpand-ebc177783d2614bd09efc4527ef95de6f52ffb27.zip
org.eclipse.xpand-ebc177783d2614bd09efc4527ef95de6f52ffb27.tar.gz
org.eclipse.xpand-ebc177783d2614bd09efc4527ef95de6f52ffb27.tar.bz2
added an expression to register dynamically scoped advice
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/AdviceContext.java6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/RegisterAdviceExpression.java50
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java7
4 files changed, 62 insertions, 7 deletions
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/AdviceContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/AdviceContext.java
index 2a3c284..7ffd0c2 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/AdviceContext.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/AdviceContext.java
@@ -10,8 +10,13 @@ Contributors:
*/
package org.eclipse.xtend.backend.common;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.xtend.backend.aop.AdvisedFunction;
import org.eclipse.xtend.backend.aop.AroundAdvice;
+import org.eclipse.xtend.backend.util.ObjectWrapper;
+import org.eclipse.xtend.backend.util.Triplet;
/**
@@ -21,4 +26,5 @@ import org.eclipse.xtend.backend.aop.AroundAdvice;
public interface AdviceContext {
AdviceContext copyWithAdvice (AroundAdvice advice);
AdvisedFunction getAdvice (String functionName, Function f);
+ public Map<Triplet<Function, AroundAdvice, List<?>>, ObjectWrapper> getResultCache ();
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
index 22fe114..4d697a9 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
@@ -12,8 +12,6 @@ package org.eclipse.xtend.backend.common;
import java.util.List;
-import org.eclipse.xtend.backend.aop.internal.AdviceContextImpl;
-
/**
*
@@ -30,8 +28,8 @@ public interface ExecutionContext {
FunctionInvoker getFunctionInvoker ();
CreationCache getCreationCache ();
- AdviceContextImpl getAdviceContext ();
- void setAdviceContext (AdviceContextImpl ctx);
+ AdviceContext getAdviceContext ();
+ void setAdviceContext (AdviceContext ctx);
void logNullDeRef (SourcePos pos);
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/RegisterAdviceExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/RegisterAdviceExpression.java
new file mode 100644
index 0000000..d2eece1
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/RegisterAdviceExpression.java
@@ -0,0 +1,50 @@
+/*
+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.expr;
+
+import org.eclipse.xtend.backend.aop.AroundAdvice;
+import org.eclipse.xtend.backend.common.AdviceContext;
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.ExpressionBase;
+import org.eclipse.xtend.backend.common.SourcePos;
+
+
+//TODO test this
+
+/**
+ * This class dynamically registers advice for the scope of the execution of a contained expression.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class RegisterAdviceExpression extends ExpressionBase {
+ private final AroundAdvice _advice;
+ private final ExpressionBase _inner;
+
+ public RegisterAdviceExpression (ExpressionBase inner, AroundAdvice advice, SourcePos sourcePos) {
+ super(sourcePos);
+
+ _advice = advice;
+ _inner = inner;
+ }
+
+ @Override
+ protected Object evaluateInternal (ExecutionContext ctx) {
+ final AdviceContext oldContext = ctx.getAdviceContext();
+
+ ctx.setAdviceContext (ctx.getAdviceContext ().copyWithAdvice (_advice));
+ try {
+ return _inner.evaluate (ctx);
+ }
+ finally {
+ ctx.setAdviceContext (oldContext);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
index ba3ddf4..791a0cc 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
@@ -15,6 +15,7 @@ import java.util.List;
import org.apache.commons.logging.LogFactory;
import org.eclipse.xtend.backend.aop.internal.AdviceContextImpl;
+import org.eclipse.xtend.backend.common.AdviceContext;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.Constants;
import org.eclipse.xtend.backend.common.ContributionStateContext;
@@ -40,7 +41,7 @@ public final class ExecutionContextImpl implements ExecutionContext {
private final boolean _logStacktrace;
private final List<StacktraceEntry> _stacktrace = new ArrayList<StacktraceEntry> ();
- private AdviceContextImpl _adviceContext = new AdviceContextImpl ();
+ private AdviceContext _adviceContext = new AdviceContextImpl ();
private final ContributionStateContext _contributionStateContext = new ContributionStateContext ();
@@ -98,11 +99,11 @@ public final class ExecutionContextImpl implements ExecutionContext {
return _logStacktrace;
}
- public AdviceContextImpl getAdviceContext () {
+ public AdviceContext getAdviceContext () {
return _adviceContext;
}
- public void setAdviceContext (AdviceContextImpl ctx) {
+ public void setAdviceContext (AdviceContext ctx) {
_adviceContext = ctx;
}
}