summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-03-01 10:34:18 (EST)
committerahaase2008-03-01 10:34:18 (EST)
commit72579e2a35cd4524e1177a84f76c9db1d73ee2c6 (patch)
tree7d8081d2be83ed12d773e7a761a31b253a40baf0
parent3e92b1189cfc934a575bb11b1e6209bd75d4c8a7 (diff)
downloadorg.eclipse.xpand-72579e2a35cd4524e1177a84f76c9db1d73ee2c6.zip
org.eclipse.xpand-72579e2a35cd4524e1177a84f76c9db1d73ee2c6.tar.gz
org.eclipse.xpand-72579e2a35cd4524e1177a84f76c9db1d73ee2c6.tar.bz2
reworked aop support in the workflow components
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/xpand2/Generator.java4
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java55
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java16
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java25
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java1
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java27
6 files changed, 76 insertions, 52 deletions
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/Generator.java b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/Generator.java
index 3e779d4..68d3966 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/Generator.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/Generator.java
@@ -90,19 +90,23 @@ public class Generator extends AbstractExpressionsUsingWorkflowComponent {
return "generating '"+expand+"' => directory '"+genPath+"'";
}
+ @Override
public void addAdvices(final String advice) {
if ( !this.advices.contains(advice) ) this.advices.add( advice );
}
+ @Override
public void addAdvice(final String advice) {
if ( !this.advices.contains(advice) ) this.advices.add( advice );
}
+ @Override
public void addExtensionAdvices(String extensionAdvices) {
if ( !this.extensionAdvices.contains(extensionAdvices) )
this.extensionAdvices.add( extensionAdvices );
}
+ @Override
public void addExtensionAdvice(String extensionAdvice) {
if ( !this.extensionAdvices.contains(extensionAdvice) )
this.extensionAdvices.add( extensionAdvice );
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
index 7e415b9..6fccaf7 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
@@ -17,6 +17,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -37,7 +38,6 @@ import org.eclipse.xpand2.output.PostProcessor;
import org.eclipse.xtend.backend.BackendFacade;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
-import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
@@ -61,7 +61,6 @@ import org.eclipse.xtend.typesystem.MetaModel;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public final class XpandBackendFacade {
- private final String _xpandFile;
private final MiddleEnd _middleEnd;
private final String _fileEncoding;
@@ -86,7 +85,6 @@ public final class XpandBackendFacade {
/**
* This method executes Xpand code that is passed in as a string, script language style.<br>
- * This method executes Xpand code that is passed in as a string, script language style.<br>
*
* There are two restrictions. Firstly, no DEFINEs are allowed - the string that is passed in must be a valid body for a DEFINE. Never
* mind the "parameters" - the "variables" parameter defines all variables that will be defined during execution. Use "this" as a
@@ -98,18 +96,34 @@ public final class XpandBackendFacade {
* Both the "variables" and "outlets" parameter may be null.
*/
public static Object executeStatement (String code, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> variables, Collection <Outlet> outlets) {
- return createForFile (null, fileEncoding, mms, outlets).executeStatement (code, variables);
+ return executeStatement(code, fileEncoding, mms, variables, outlets, null);
}
-
- public Object executeStatement (String code, Map<String, Object> variables) {
+
+ /**
+ * This method executes Xpand code that is passed in as a string, script language style.<br>
+ *
+ * There are two restrictions. Firstly, no DEFINEs are allowed - the string that is passed in must be a valid body for a DEFINE. Never
+ * mind the "parameters" - the "variables" parameter defines all variables that will be defined during execution. Use "this" as a
+ * variable name to specify the variable that is implicitly bound as the "special" parameter passed to a definition.<br>
+ *
+ * Secondly, no IMPORT or EXTENSION statements are possible. So types must be referenced by their fully qualified names, and no calls
+ * to extensions are possible. Calls to other templates that are available as files are possible, just as you would expect.<br>
+ *
+ * The "variables", "outlets" and "advice" parameters parameter may be null.
+ */
+ public static Object executeStatement (String code, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> variables, Collection <Outlet> outlets, List<String> advice) {
+ return createForFile (fileEncoding, mms, outlets).executeStatement (code, variables, advice);
+ }
+
+ public Object executeStatement (String code, Map<String, Object> variables, List<String> advice) {
if (variables == null)
variables = new HashMap<String, Object> ();
+ if (advice == null)
+ advice = new ArrayList<String> ();
final Template tpl = XpandParseFacade.file (new StringReader (XpandTokens.LT + "DEFINE dUmMy FOR dUmMy" + XpandTokens.RT + code + XpandTokens.RT + XpandTokens.LT + "ENDDEFINE" + XpandTokens.RT), null);
final Statement[] statements = ((Definition) tpl.getDefinitions()[0]).getBody();
- System.err.println (_fileEncoding);
-
XpandExecutionContext ctx = createXpandExecutionContext (_fileEncoding, _mms, _outlets);
for (String varName: variables.keySet())
ctx = (XpandExecutionContext) ctx.cloneWithVariable (new Variable (varName, ctx.getType (variables.get (varName))));
@@ -131,7 +145,7 @@ public final class XpandBackendFacade {
return converted.evaluate (backendCtx);
}
- public static void registerOutlets (ExecutionContext ctx, Collection<Outlet> outlets) {
+ private static void registerOutlets (ExecutionContext ctx, Collection<Outlet> outlets) {
for (Outlet oldOutlet: outlets) {
final FileOutlet newOutlet = new FileOutlet ();
newOutlet.setAppend (oldOutlet.isAppend());
@@ -225,8 +239,8 @@ public final class XpandBackendFacade {
}
}
- public static XpandBackendFacade createForFile (String xpandFilename, String fileEncoding, Collection<MetaModel> mms, Collection <Outlet> outlets) {
- return new XpandBackendFacade (xpandFilename, fileEncoding, mms, outlets);
+ public static XpandBackendFacade createForFile (String fileEncoding, Collection<MetaModel> mms, Collection <Outlet> outlets) {
+ return new XpandBackendFacade (fileEncoding, mms, outlets);
}
@@ -255,28 +269,21 @@ public final class XpandBackendFacade {
return result;
}
-
- private XpandBackendFacade (String xpandFilename, String fileEncoding, Collection<MetaModel> mms, Collection <Outlet> outlets) {
+ private XpandBackendFacade (String fileEncoding, Collection<MetaModel> mms, Collection <Outlet> outlets) {
if (outlets == null)
outlets = new ArrayList<Outlet> ();
- _xpandFile = OldHelper.normalizeXpandResourceName (xpandFilename);
+ //TODO replace with version without OSGi dependency!
+ //TODO externalize middleend initialization into the workflow!
_middleEnd = MiddleEndFactory.create (OldHelper.guessTypesystem (mms), createSpecificParameters (fileEncoding, mms, outlets));
_fileEncoding = fileEncoding;
_mms = mms;
_outlets = outlets;
}
-
- public Collection<NamedFunction> getContributedFunctions () {
- return _middleEnd.getFunctions(_xpandFile).getPublicFunctions();
- }
-
- public FunctionDefContext getFunctionDefContext () {
- if (_xpandFile == null)
- return new FunctionDefContextFactory (_middleEnd.getTypesystem()).create();
-
- return _middleEnd.getFunctions (_xpandFile);
+
+ public void applyAdvice (String resourceName) {
+ _middleEnd.applyAdvice (resourceName);
}
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java
index 1acc9a8..6d92b16 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java
@@ -41,9 +41,7 @@ import org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
- //TODO genPath, srcPath
//TODO profiler
- //TODO advice / AOP
private String _genPath = null;
private String _srcPath = null;
@@ -53,6 +51,8 @@ public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
private boolean _automaticHyphens = false;
private Output _output = null;
+ private final List<Outlet> _outlets = new ArrayList<Outlet>();
+
private List<PostProcessor> _postprocessors = new ArrayList <PostProcessor>();
private List<Outlet> _initializedOutlets = new ArrayList<Outlet> ();
@@ -136,13 +136,11 @@ public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
for (String name: wfContext.getSlotNames())
variables.put (name, wfContext.get (name));
- XpandBackendFacade.executeStatement (code, _fileEncoding, metaModels, variables, outlets);
+ XpandBackendFacade.executeStatement (code, code, metaModels, variables, _outlets, _advice);
}
- private final List<Outlet> outlets = new ArrayList<Outlet>();
-
public void addOutlet (Outlet outlet) {
- outlets.add(outlet);
+ _outlets.add(outlet);
}
public void setOutput (Output output) {
@@ -160,10 +158,10 @@ public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
return _output;
}
-
+
private List<Outlet> getInitializedOutlets() {
if (_initializedOutlets.isEmpty()) {
- final List<Outlet> result = new ArrayList<Outlet> (outlets);
+ final List<Outlet> result = new ArrayList<Outlet> (_outlets);
if (result.isEmpty()) {
if (_genPath != null) { // backward compatibility
result.add (new Outlet (false, _fileEncoding, null, true, _genPath));
@@ -205,7 +203,7 @@ public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
if (_genPath == null && getInitializedOutlets().isEmpty())
issues.addError(this, "You need to configure at least one outlet!");
- if ((_genPath != null || _srcPath != null) && !outlets.isEmpty())
+ if ((_genPath != null || _srcPath != null) && !_outlets.isEmpty())
issues.addWarning(this, "'genPath' is ignored since you have specified outlets!");
int defaultOutlets = 0;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java
index 872187d..bc5e4bf 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java
@@ -11,9 +11,7 @@ Contributors:
package org.eclipse.xtend.middleend.old;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.eclipse.emf.mwe.core.WorkflowContext;
@@ -31,22 +29,17 @@ import org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent;
*/
public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
-// private final Log _log = LogFactory.getLog(getClass());
-
-
- private List<String> _extensionAdvices = new ArrayList<String>();
-
- public void addExtensionAdvice (String resourceName) {
- if ( !_extensionAdvices.contains (resourceName) )
- _extensionAdvices.add (resourceName );
- }
-
/** Stores the value of the 'invoke' property. Needed for error analysis. */
private String _invokeExpression;
String _extensionFile = null;
private String _expression = null;
private String _outputSlot = WorkflowContext.DEFAULT_SLOT;
+
+ private String _fileEncoding = null;
+ public void setFileEncoding (String fileEncoding) {
+ _fileEncoding = fileEncoding;
+ }
@Override
public String getLogMessage() {
@@ -75,11 +68,6 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
return;
}
- final List<String> adviceResources = new ArrayList<String>();
- for (String rawAdvice : _extensionAdvices)
- for (String a: rawAdvice.split (","))
- adviceResources.add (a.trim());
-
final Map<String, Object> localVars = new HashMap<String, Object> ();
for (String slotName: ctx.getSlotNames())
localVars.put (slotName, ctx.get (slotName));
@@ -88,8 +76,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
for (GlobalVarDef gvd: globalVarDefs)
globalVars.put (gvd.getName(), gvd.getValue());
- //TODO allow file encoding configuration
- final Object result = XtendBackendFacade.evaluateExpression (_expression, _extensionFile, null, metaModels, localVars, globalVars, adviceResources);
+ final Object result = XtendBackendFacade.evaluateExpression (_expression, _extensionFile, _fileEncoding, metaModels, localVars, globalVars, _advice);
ctx.set (_outputSlot, result);
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
index a79dafc..70d7e05 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
@@ -39,6 +39,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
private List<String> extensionAdvices = new ArrayList<String>();
+ @Override
public void addExtensionAdvice(String extensionAdvices) {
if ( !this.extensionAdvices.contains(extensionAdvices) )
this.extensionAdvices.add( extensionAdvices );
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
index 275b493..dafbd09 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
@@ -35,6 +35,33 @@ public abstract class AbstractExpressionsUsingWorkflowComponent extends
protected final List<GlobalVarDef> globalVarDefs = new ArrayList<GlobalVarDef>();
+ protected final List<String> _advice = new ArrayList<String>();
+
+ public void addAdvice (String advice) {
+ for (String singleAdvice: advice.split (",")) {
+ singleAdvice = singleAdvice.trim();
+ if (singleAdvice.length() == 0)
+ continue;
+
+ if (!_advice.contains (singleAdvice))
+ _advice.add (singleAdvice);
+ }
+ }
+
+ public void addAdvices (String advice) {
+ addAdvices (advice);
+ }
+
+ public void addExtensionAdvice (String advice) {
+ addAdvice (advice);
+ }
+
+ public void addExtensionAdvices (String advice) {
+ addExtensionAdvice (advice);
+ }
+
+
+
public void addMetaModel(final MetaModel metaModel) {
assert metaModel != null;
metaModels.add(metaModel);