summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-03-01 09:49:39 (EST)
committer ahaase2008-03-01 09:49:39 (EST)
commit3e92b1189cfc934a575bb11b1e6209bd75d4c8a7 (patch)
tree4ee0af00306d5512ce4d80a322f72c47f1665f6c
parenta88b99b80b30252293638f62bdcf295ad3136235 (diff)
downloadorg.eclipse.xpand-3e92b1189cfc934a575bb11b1e6209bd75d4c8a7.zip
org.eclipse.xpand-3e92b1189cfc934a575bb11b1e6209bd75d4c8a7.tar.gz
org.eclipse.xpand-3e92b1189cfc934a575bb11b1e6209bd75d4c8a7.tar.bz2
added Xpand Advice
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/ast/Advice.java4
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java26
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java16
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java30
5 files changed, 74 insertions, 34 deletions
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/ast/Advice.java b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/ast/Advice.java
index 96d16a3..d48f094 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/ast/Advice.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/internal/xpand2/ast/Advice.java
@@ -50,6 +50,10 @@ public class Advice extends AbstractDefinition implements XpandAdvice {
private Pattern p = null;
+ public boolean isWildcardParams () {
+ return wildParams;
+ }
+
public boolean matches(final XpandDefinition def, XpandExecutionContext ctx) {
if (p == null) {
p = Pattern.compile(getName().replaceAll("\\*", ".*"));
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java
index 8333013..f7f95f7 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java
@@ -20,6 +20,7 @@ import org.eclipse.internal.xtend.expression.ast.Case;
import org.eclipse.internal.xtend.expression.ast.ChainExpression;
import org.eclipse.internal.xtend.expression.ast.CollectionExpression;
import org.eclipse.internal.xtend.expression.ast.ConstructorCallExpression;
+import org.eclipse.internal.xtend.expression.ast.DeclaredParameter;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.expression.ast.FeatureCall;
import org.eclipse.internal.xtend.expression.ast.GlobalVarExpression;
@@ -39,9 +40,15 @@ import org.eclipse.internal.xtend.type.baseimpl.types.CollectionTypeImpl;
import org.eclipse.internal.xtend.type.baseimpl.types.ListTypeImpl;
import org.eclipse.internal.xtend.type.baseimpl.types.ObjectTypeImpl;
import org.eclipse.internal.xtend.type.baseimpl.types.SetTypeImpl;
+import org.eclipse.xtend.backend.aop.AdviceParamType;
+import org.eclipse.xtend.backend.aop.AroundAdvice;
+import org.eclipse.xtend.backend.aop.ExecutionPointcut;
+import org.eclipse.xtend.backend.aop.Pointcut;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExpressionBase;
+import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.SourcePos;
+import org.eclipse.xtend.backend.common.SyntaxConstants;
import org.eclipse.xtend.backend.expr.AndExpression;
import org.eclipse.xtend.backend.expr.CreateUncachedExpression;
import org.eclipse.xtend.backend.expr.HidingLocalVarDefExpression;
@@ -64,6 +71,7 @@ import org.eclipse.xtend.backend.types.builtin.ObjectType;
import org.eclipse.xtend.backend.util.CollectionHelper;
import org.eclipse.xtend.backend.util.Pair;
import org.eclipse.xtend.expression.ExecutionContext;
+import org.eclipse.xtend.expression.TypeSystem;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendLibNames;
import org.eclipse.xtend.typesystem.StaticProperty;
@@ -71,7 +79,7 @@ import org.eclipse.xtend.typesystem.Type;
/**
- * converts a single expression
+ * converts a single expression or advice
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
@@ -86,6 +94,28 @@ public final class OldExpressionConverter {
_extensionName = extensionName;
}
+ private static final List<String> _adviceLocalVarNames = Arrays.asList (SyntaxConstants.THIS_JOINPOINT, SyntaxConstants.THIS_JOINPOINT_STATICPART);
+
+ public List<String> getAdviceLocalVarNames () {
+ return _adviceLocalVarNames;
+ }
+
+ public List<Type> getAdviceLocalVarTypes (TypeSystem ts) {
+ return Arrays.asList (ts.getStringType(), ts.getStringType()); // any type other than Object will do - as a hint for the right optimizations
+ }
+
+ private static final AdviceParamType _wildCardParamType = new AdviceParamType (ObjectType.INSTANCE, true);
+
+ public AroundAdvice convertAdvice (ExpressionBase body, String namePattern, List<DeclaredParameter> params, boolean hasVarArgs, FunctionDefContext fdc) {
+ final List <Pair <String, AdviceParamType>> paramTypes = new ArrayList <Pair <String, AdviceParamType>> ();
+ for (DeclaredParameter dp: params)
+ paramTypes.add (new Pair <String, AdviceParamType> (dp.getName().getValue(), new AdviceParamType (_typeConverter.convertToBackendType (dp.getType()), true)));
+
+ final Pointcut pointcut = new ExecutionPointcut (namePattern, paramTypes, hasVarArgs, _wildCardParamType);
+
+ return new AroundAdvice (body, pointcut, false, fdc);
+ }
+
public ExpressionBase convert (Expression expr) {
if (expr instanceof BooleanLiteral)
return new LiteralExpression ("true".equals (((Literal) expr).getLiteralValue().getValue()), getSourcePos (expr));
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java
index 767e78d..8783305 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java
@@ -17,6 +17,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.internal.xpand2.ast.Advice;
import org.eclipse.internal.xpand2.ast.Definition;
import org.eclipse.internal.xpand2.ast.ErrorStatement;
import org.eclipse.internal.xpand2.ast.ExpandStatement;
@@ -35,6 +36,7 @@ import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.expression.ast.SyntaxElement;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xpand2.output.Outlet;
+import org.eclipse.xtend.backend.aop.AroundAdvice;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.Function;
@@ -89,6 +91,27 @@ public final class OldDefinitionConverter {
}
+ public AroundAdvice create (Advice a, Set<XpandDefinitionName> referencedDefinitions, FunctionDefContext fdc) {
+ final XpandExecutionContext oldCtx = _ctx;
+
+ try {
+ final OldExpressionConverter exprConv = new OldExpressionConverter (_ctx, _typeConverter, "<around>");
+
+ _ctx = (XpandExecutionContext) _ctx.cloneWithoutVariables();
+
+ final List<String> localVarNames = exprConv.getAdviceLocalVarNames();
+ final List<Type> localVarTypes = exprConv.getAdviceLocalVarTypes (oldCtx);
+ for (int i=0; i<localVarNames.size(); i++)
+ _ctx = (XpandExecutionContext) _ctx.cloneWithVariable (new Variable (localVarNames.get(i), localVarTypes.get(i)));
+
+ final ExpressionBase body = convertStatementSequence (a.getBody(), a, referencedDefinitions);
+ return exprConv.convertAdvice (body, a.getName(), Arrays.asList (a.getParams()), a.isWildcardParams(), fdc);
+ }
+ finally {
+ _ctx = oldCtx;
+ }
+ }
+
/**
* converts an extension to a function, taking care of mutual registration with its fdc
*/
@@ -107,7 +130,6 @@ public final class OldDefinitionConverter {
throw new IllegalArgumentException ("unsupported definition type " + def.getClass().getName());
}
- //TODO imported namespaces (probably one level up)
private Function createNormalDefinition (Definition def, FunctionDefContext fdc, Set<XpandDefinitionName> referencedDefinitions) {
final XpandExecutionContext oldCtx = _ctx;
@@ -341,8 +363,6 @@ public final class OldDefinitionConverter {
final ExpressionBase outletName = new LiteralExpression ((stmt.getOutletName() != null) ? stmt.getOutletName() : FileIoOperations.DEFAULT_OUTLET_NAME, getSourcePos(stmt));
final ExpressionBase append = new LiteralExpression (outlet.isAppend(), getSourcePos(stmt));
- //TODO register the outlets
-
final List<ExpressionBase> emptyParamList = Collections.emptyList();
final ExpressionBase initIsDeleteLineExpression = new InvocationOnObjectExpression (XtendLibNames.DELETE_LINE_INIT, emptyParamList, false, getSourcePos (stmt));
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
index 1eeb7f6..038bee1 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
@@ -19,7 +19,9 @@ import java.util.Set;
import org.eclipose.xtend.middleend.MiddleEnd;
import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipse.internal.xpand2.ast.Advice;
import org.eclipse.internal.xpand2.ast.Template;
+import org.eclipse.internal.xpand2.model.XpandAdvice;
import org.eclipse.internal.xpand2.model.XpandDefinition;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xpand2.XpandUtil;
@@ -56,7 +58,8 @@ public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
* all functions actually defined in a given compilation unit
*/
private final Map<String, List<NamedFunction>> _functionsByResource = new HashMap <String, List<NamedFunction>>();
-
+
+ private final Map<String, List<AroundAdvice>> _adviceByResource = new HashMap <String, List<AroundAdvice>> ();
private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldHelper.normalizeXtendResourceName (xtendName));
@@ -108,6 +111,11 @@ public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
defined.add (definitionFactory.create (ext, fdc, referenced));
_functionsByResource.put (xpandFile, defined);
+
+ final List<AroundAdvice> newAdvice = new ArrayList<AroundAdvice>();
+ for (XpandAdvice a: file.getAdvices())
+ newAdvice.add (definitionFactory.create ((Advice) a, referenced, fdc));
+ _adviceByResource.put(xpandResourceName, newAdvice);
// make sure all imported resources are registered as well
for (String imported: file.getImportedExtensions())
@@ -124,6 +132,7 @@ public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
for (String xpandFileName: xpandFileNames)
for (NamedFunction f: _middleEnd.getFunctions (xpandFileName).getPublicFunctions())
fdc.register (f, false);
+
}
@@ -151,11 +160,10 @@ public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
public List<AroundAdvice> getContributedAdvice (String resourceName) {
- //TODO Xpand advice
- return new ArrayList<AroundAdvice>();
+ registerXpandFile (resourceName);
+ return _adviceByResource.get (OldHelper.normalizeXpandResourceName (resourceName));
}
-
public String getName () {
return "Xpand";
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java
index bb6190d..163b0fd 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java
@@ -12,21 +12,16 @@ package org.eclipse.xtend.middleend.old.internal.xtend;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
-import org.eclipse.internal.xtend.expression.ast.DeclaredParameter;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.xtend.ast.Around;
import org.eclipse.internal.xtend.xtend.ast.CreateExtensionStatement;
import org.eclipse.internal.xtend.xtend.ast.ExpressionExtensionStatement;
import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement;
-import org.eclipse.xtend.backend.aop.AdviceParamType;
import org.eclipse.xtend.backend.aop.AroundAdvice;
-import org.eclipse.xtend.backend.aop.ExecutionPointcut;
-import org.eclipse.xtend.backend.aop.Pointcut;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.Function;
@@ -38,8 +33,6 @@ import org.eclipse.xtend.backend.expr.LocalVarEvalExpression;
import org.eclipse.xtend.backend.expr.NewLocalVarDefExpression;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
-import org.eclipse.xtend.backend.types.builtin.ObjectType;
-import org.eclipse.xtend.backend.util.Pair;
import org.eclipse.xtend.expression.AnalysationIssue;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.Variable;
@@ -63,26 +56,11 @@ public final class OldExtensionConverter {
_typeConverter = typeConverter;
}
- private static final AdviceParamType _wildCardParamType = new AdviceParamType (ObjectType.INSTANCE, true);
-
public AroundAdvice create (Around around, FunctionDefContext fdc) {
- final List<String> localVarNames = Arrays.asList (SyntaxConstants.THIS_JOINPOINT, SyntaxConstants.THIS_JOINPOINT_STATICPART);
- final List<Type> localVarTypes = Arrays.asList (_ctx.getStringType(), _ctx.getStringType()); // any type other than Object will do - as a hint for the right optimizations
- final ExpressionBase body = convertExpression (around.getExpression(), localVarNames, localVarTypes, "<around>");
-
- final String namePattern = around.getPointCut().getValue();
-
- final List <Pair <String, AdviceParamType>> paramTypes = new ArrayList <Pair <String, AdviceParamType>> ();
- for (DeclaredParameter dp: around.getParams())
- paramTypes.add (new Pair <String, AdviceParamType> (dp.getName().getValue(), new AdviceParamType (_typeConverter.convertToBackendType (dp.getType()), true)));
-
- final boolean hasVarArgs = around.isWildparams();
-
- final Pointcut pointcut = new ExecutionPointcut (namePattern, paramTypes, hasVarArgs, _wildCardParamType);
-
- return new AroundAdvice (body, pointcut, false, fdc);
- }
-
+ final OldExpressionConverter exprConv = new OldExpressionConverter (_ctx, _typeConverter, "<around>");
+ final ExpressionBase body = convertExpression (around.getExpression(), exprConv.getAdviceLocalVarNames(), exprConv.getAdviceLocalVarTypes(_ctx), "<around>");
+ return exprConv.convertAdvice (body, around.getPointCut().getValue(), around.getParams(), around.isWildparams(), fdc);
+ }
/**
* converts an extension to a function, taking care of mutual registration with its fdc