summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-27 02:46:24 (EST)
committerahaase2008-02-27 02:46:24 (EST)
commit9622e096ebabc49d922797ecb0dbe06c87f922ab (patch)
tree41fa551e4cdc75681656ecb40291e966d125c8fc
parent7aed86cf5cf7e927fd9d7251c97e16a28bf7bd03 (diff)
downloadorg.eclipse.xpand-9622e096ebabc49d922797ecb0dbe06c87f922ab.zip
org.eclipse.xpand-9622e096ebabc49d922797ecb0dbe06c87f922ab.tar.gz
org.eclipse.xpand-9622e096ebabc49d922797ecb0dbe06c87f922ab.tar.bz2
switched to extension point based middle end implementation: The language specific middle ends now contribute to an extension point, providing full interoperation between the languages.
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/aop/AroundAdvice.java9
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/FunctionDefContext.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpression.java3
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java5
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java14
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/META-INF/MANIFEST.MF12
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/build.properties3
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/plugin.xml17
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckBackendFacade.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckBackendFacade.java)3
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckComponent.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckComponent.java)2
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandBackendFacade.java)87
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandComponent.java)4
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendBackendFacade.java)112
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendComponent.java)107
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldExpressionConverter.java1
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldHelper.java9
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldDefinitionConverter.java)6
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldXpandRegistry.java)87
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/XpandDefinitionName.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandDefinitionName.java)4
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/CheckConverter.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckConverter.java)2
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/JavaExtensionFunction.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/JavaExtensionFunction.java)2
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldExtensionConverter.java)35
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java (renamed from plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldXtendRegistry.java)95
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXpandRegistryFactory.java36
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXtendRegistryFactory.java36
-rw-r--r--plugins/org.eclipse.xtend.middleend/META-INF/MANIFEST.MF12
-rw-r--r--plugins/org.eclipse.xtend.middleend/build.properties3
-rw-r--r--plugins/org.eclipse.xtend.middleend/plugin.xml6
-rw-r--r--plugins/org.eclipse.xtend.middleend/schema/MiddleEnd.exsd105
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/BackendTypesystemFactory.java53
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java97
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/internal/Activator.java101
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEnd.java51
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEndFactory.java50
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java2
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java2
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExpressionFacade.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTest.java20
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTestFunctions.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java3
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java4
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java15
47 files changed, 900 insertions, 346 deletions
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/aop/AroundAdvice.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/aop/AroundAdvice.java
index 8e5b6db..dff82bb 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/aop/AroundAdvice.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/aop/AroundAdvice.java
@@ -13,6 +13,7 @@ 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.FunctionDefContext;
import org.eclipse.xtend.backend.common.SyntaxConstants;
@@ -22,6 +23,7 @@ import org.eclipse.xtend.backend.common.SyntaxConstants;
public final class AroundAdvice {
private final ExpressionBase _body;
private final Pointcut _pointcut;
+ private final FunctionDefContext _fdc;
private final boolean _isCacheable;
@@ -33,10 +35,11 @@ public final class AroundAdvice {
* 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) {
+ public AroundAdvice (ExpressionBase body, Pointcut pointcut, boolean isCacheable, FunctionDefContext fdc) {
_body = body;
_pointcut = pointcut;
_isCacheable = isCacheable;
+ _fdc = fdc;
}
/**
@@ -48,10 +51,14 @@ public final class AroundAdvice {
ctx.getLocalVarContext().getLocalVars().put (SyntaxConstants.THIS_JOINPOINT, thisJoinPoint);
ctx.getLocalVarContext().getLocalVars().put (SyntaxConstants.THIS_JOINPOINT_STATICPART, thisJoinPointStaticPart);
+ final FunctionDefContext oldFdc = ctx.getFunctionDefContext();
+ ctx.setFunctionDefContext (_fdc);
+
try {
return _body.evaluate (ctx);
}
finally {
+ ctx.setFunctionDefContext (oldFdc);
ctx.getLocalVarContext ().getLocalVars ().remove (SyntaxConstants.THIS_JOINPOINT);
ctx.getLocalVarContext ().getLocalVars ().remove (SyntaxConstants.THIS_JOINPOINT_STATICPART);
scopeCounter.leaveAdvice();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/FunctionDefContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/FunctionDefContext.java
index f125d11..8781dc8 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/FunctionDefContext.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/FunctionDefContext.java
@@ -42,4 +42,6 @@ public interface FunctionDefContext {
* types and those registered separately.
*/
boolean hasMatch (ExecutionContext ctx, String functionName, List<? extends Object> params);
+
+ Collection<NamedFunction> getPublicFunctions ();
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpression.java
index d205c1b..7adab79 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpression.java
@@ -43,7 +43,8 @@ public final class NewLocalVarDefExpression extends ExpressionBase {
return _inner.evaluate(ctx);
}
finally {
- ctx.getStacktrace ().remove (ctx.getStacktrace().size() - 1);
+ if (ctx.isLogStacktrace())
+ ctx.getStacktrace ().remove (ctx.getStacktrace().size() - 1);
ctx.getLocalVarContext ().getLocalVars ().remove (_localVarName);
}
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java
index dd83b68..cba47af 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java
@@ -11,6 +11,7 @@ Contributors:
package org.eclipse.xtend.backend.functions;
import org.eclipse.xtend.backend.common.BackendTypesystem;
+import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.internal.FunctionDefContextImpl;
import org.eclipse.xtend.backend.syslib.SyslibContributor;
@@ -28,7 +29,10 @@ public final class FunctionDefContextFactory {
public FunctionDefContextInternal create () {
final FunctionDefContextInternal result = new FunctionDefContextImpl ();
- result.register (_syslib.getContributedFunctions());
+
+ for (NamedFunction f: _syslib.getContributedFunctions())
+ result.register (f, false);
+
return result;
}
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
index 9492584..9e31e46 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
@@ -10,8 +10,6 @@ Contributors:
*/
package org.eclipse.xtend.backend.functions;
-import java.util.Collection;
-
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
@@ -24,6 +22,5 @@ import org.eclipse.xtend.backend.common.NamedFunction;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public interface FunctionDefContextInternal extends FunctionDefContext {
- void register (NamedFunction f);
- void register (Collection <? extends NamedFunction> f);
+ void register (NamedFunction f, boolean isPublic);
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
index f41ce6a..ea01bcb 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
@@ -88,12 +88,12 @@ public final class FunctionDefContextImpl implements FunctionDefContextInternal
}
};
- public void register (Collection<? extends NamedFunction> functions) {
- for (NamedFunction f: functions)
- register (f);
- }
+ private final DuplicateAwareNamedFunctionCollection _publicFunctions = new DuplicateAwareNamedFunctionCollection ();
- public void register (NamedFunction f) {
+ public void register (NamedFunction f, boolean isPublic) {
+ if (isPublic)
+ _publicFunctions.register (f);
+
final NamedFunction old = _functions.get (f.getName(), f.getFunction().getParameterTypes().size()).register (f);
if (old != null && old.getFunction().getParameterTypes().size() > 0)
_byFirstParameterType.get (old.getFunction().getParameterTypes().get (0)).remove (old);
@@ -160,6 +160,10 @@ public final class FunctionDefContextImpl implements FunctionDefContextInternal
public String toString () {
return "FunctionDefContextImpl [" + _functions.getMap().values() + "]";
}
+
+ public Collection<NamedFunction> getPublicFunctions () {
+ return _publicFunctions.getFunctions();
+ }
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.middleend.old/META-INF/MANIFEST.MF
index f52d9ee..2b81a61 100644
--- a/plugins/org.eclipse.xtend.middleend.old/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.middleend.old/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Old Plug-in (Incubation)
-Bundle-SymbolicName: org.eclipse.xtend.middleend.old
+Bundle-SymbolicName: org.eclipse.xtend.middleend.old;singleton:=true
Bundle-Version: 0.7.0
Require-Bundle: org.eclipse.xtend.backend,
org.eclipse.emf.ecore,
@@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.xtend.backend,
org.eclipse.xtend.typesystem.emf,
org.eclipse.emf.mwe.core,
org.apache.commons.logging
-Export-Package: org.eclipse.xtend.middleend.old.common,
- org.eclipse.xtend.middleend.old.internal.xtendlib,
- org.eclipse.xtend.middleend.old.xpand,
- org.eclipse.xtend.middleend.old.xtend
+Export-Package: org.eclipse.xtend.middleend.old,
+ org.eclipse.xtend.middleend.old.common;x-internal:=true,
+ org.eclipse.xtend.middleend.old.internal.xpand;x-internal:=true,
+ org.eclipse.xtend.middleend.old.internal.xtend;x-internal:=true,
+ org.eclipse.xtend.middleend.old.internal.xtendlib;x-internal:=true,
+ org.eclipse.xtend.middleend.old.plugin
diff --git a/plugins/org.eclipse.xtend.middleend.old/build.properties b/plugins/org.eclipse.xtend.middleend.old/build.properties
index 34d2e4d..e9863e2 100644
--- a/plugins/org.eclipse.xtend.middleend.old/build.properties
+++ b/plugins/org.eclipse.xtend.middleend.old/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ plugin.xml
diff --git a/plugins/org.eclipse.xtend.middleend.old/plugin.xml b/plugins/org.eclipse.xtend.middleend.old/plugin.xml
new file mode 100644
index 0000000..f8207ba
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend.old/plugin.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.xtend.middleend.MiddleEnd">
+ <element_1
+ class="org.eclipse.xtend.middleend.old.plugin.OldXtendRegistryFactory">
+ </element_1>
+ </extension>
+ <extension
+ point="org.eclipse.xtend.middleend.MiddleEnd">
+ <element_1
+ class="org.eclipse.xtend.middleend.old.plugin.OldXpandRegistryFactory">
+ </element_1>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckBackendFacade.java
index 335728c..26ad59b 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckBackendFacade.java
@@ -8,11 +8,12 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old;
import java.util.Collection;
import org.eclipse.emf.mwe.core.issues.Issues;
+import org.eclipse.xtend.middleend.old.internal.xtend.CheckConverter;
import org.eclipse.xtend.typesystem.MetaModel;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckComponent.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckComponent.java
index 68d23c1..0468d4d 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckComponent.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/CheckComponent.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old;
import java.util.ArrayList;
import java.util.Collection;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
index ef21ad2..fc033d8 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xpand;
+package org.eclipse.xtend.middleend.old;
import java.io.File;
import java.io.StringReader;
@@ -20,6 +20,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.eclipose.xtend.middleend.MiddleEnd;
import org.eclipse.internal.xpand2.ast.Definition;
import org.eclipse.internal.xpand2.ast.Statement;
import org.eclipse.internal.xpand2.ast.Template;
@@ -33,14 +34,12 @@ import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xpand2.output.PostProcessor;
import org.eclipse.xtend.backend.BackendFacade;
-import org.eclipse.xtend.backend.common.BackendTypesystem;
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;
-import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.backend.syslib.FileIoOperations;
import org.eclipse.xtend.backend.syslib.FileOutlet;
import org.eclipse.xtend.backend.syslib.InMemoryPostprocessor;
@@ -49,7 +48,10 @@ import org.eclipse.xtend.backend.syslib.UriBasedPostprocessor;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.middleend.old.common.OldHelper;
import org.eclipse.xtend.middleend.old.common.TypeToBackendType;
-import org.eclipse.xtend.middleend.old.xtend.OldXtendRegistry;
+import org.eclipse.xtend.middleend.old.internal.xpand.OldDefinitionConverter;
+import org.eclipse.xtend.middleend.old.internal.xpand.XpandDefinitionName;
+import org.eclipse.xtend.middleend.old.plugin.OldXpandRegistryFactory;
+import org.eclipse.xtend.middleend.old.plugin.OldXtendRegistryFactory;
import org.eclipse.xtend.typesystem.MetaModel;
@@ -58,15 +60,15 @@ import org.eclipse.xtend.typesystem.MetaModel;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public final class XpandBackendFacade {
- private final OldXtendRegistry _extensions;
- private final OldXpandRegistry _registry;
private final String _xpandFile;
- private final BackendTypesystem _ts;
-
+ private final MiddleEnd _middleEnd;
+
+ private final String _fileEncoding;
+ private final Collection<MetaModel> _mms;
+ private final Collection<Outlet> _outlets;
/**
* 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
@@ -95,41 +97,35 @@ 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) {
- fileEncoding = OldHelper.normalizedFileEncoding (fileEncoding);
- final BackendTypesystem ts = OldHelper.guessTypesystem (mms);
+ return createForFile (null, fileEncoding, mms, outlets).executeStatement (code, variables);
+ }
+ public Object executeStatement (String code, Map<String, Object> variables) {
if (variables == null)
variables = new HashMap<String, Object> ();
- if (outlets == null)
- outlets = new ArrayList<Outlet> ();
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 = createOldExecutionContext (fileEncoding, mms, outlets);
+ XpandExecutionContext ctx = createXpandExecutionContext (_fileEncoding, _mms, _outlets);
for (String varName: variables.keySet())
ctx = (XpandExecutionContext) ctx.cloneWithVariable (new Variable (varName, ctx.getType (variables.get (varName))));
final Set<XpandDefinitionName> referenced = new HashSet<XpandDefinitionName>();
- final OldDefinitionConverter defConverter = new OldDefinitionConverter (ctx, new TypeToBackendType (ts, ctx));
+ final OldDefinitionConverter defConverter = new OldDefinitionConverter (ctx, new TypeToBackendType (_middleEnd.getTypesystem(), ctx));
final ExpressionBase converted = defConverter.convertStatementSequence (statements, tpl, referenced);
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (_middleEnd.getTypesystem()).create();
- final FunctionDefContextInternal fdc = new FunctionDefContextFactory (ts).create();
-
- //TODO refactor this to extract common code - both from here and from OldXpandRegistry
- final OldXpandRegistry oxr = new OldXpandRegistry (ctx, ts, new OldXtendRegistry (ctx, ts));
- for (XpandDefinitionName xdn: referenced) {
- oxr.registerXpandFile (xdn.getCanonicalTemplateFileName());
-
- for (NamedFunction f: oxr.getContributedFunctions (xdn.getCanonicalTemplateFileName()))
- fdc.register (f);
- }
+ for (XpandDefinitionName xdn: referenced)
+ for (NamedFunction f: _middleEnd.getFunctions (xdn.getCanonicalTemplateFileName ()).getPublicFunctions())
+ fdc.register (f, false);
- final ExecutionContext backendCtx = BackendFacade.createExecutionContext (fdc, ts, true); //TODO configure isLogStacktrace
+ final ExecutionContext backendCtx = BackendFacade.createExecutionContext (fdc, _middleEnd.getTypesystem(), true); //TODO configure isLogStacktrace
backendCtx.getLocalVarContext().getLocalVars().putAll (variables);
- registerOutlets (backendCtx, outlets);
+ registerOutlets (backendCtx, _outlets);
return converted.evaluate (backendCtx);
}
@@ -233,7 +229,7 @@ public final class XpandBackendFacade {
}
- private static XpandExecutionContext createOldExecutionContext (String fileEncoding, Collection<MetaModel> mms, Collection<Outlet> outlets) {
+ private XpandExecutionContext createXpandExecutionContext (String fileEncoding, Collection<MetaModel> mms, Collection<Outlet> outlets) {
fileEncoding = OldHelper.normalizedFileEncoding (fileEncoding);
final Output output = new OutputImpl ();
@@ -245,30 +241,41 @@ public final class XpandBackendFacade {
for (MetaModel mm: mms)
ctx.registerMetaModel (mm);
ctx.setFileEncoding (fileEncoding);
-
+
return ctx;
}
+ private Map<Class<?>, Object> createSpecificParameters (String fileEncoding, Collection<MetaModel> mms, Collection<Outlet> outlets) {
+ final XpandExecutionContext ctx = createXpandExecutionContext (fileEncoding, mms, outlets);
+
+ final Map<Class<?>, Object> result = new HashMap<Class<?>, Object> ();
+ result.put (OldXtendRegistryFactory.class, ctx);
+ result.put (OldXpandRegistryFactory.class, ctx);
+ return result;
+ }
+
+
private XpandBackendFacade (String xpandFilename, String fileEncoding, Collection<MetaModel> mms, Collection <Outlet> outlets) {
+ if (outlets == null)
+ outlets = new ArrayList<Outlet> ();
+
_xpandFile = OldHelper.normalizeXpandResourceName (xpandFilename);
- _ts = OldHelper.guessTypesystem (mms);
-
- final XpandExecutionContext ctx = createOldExecutionContext (fileEncoding, mms, outlets);
+ _middleEnd = new MiddleEnd (OldHelper.guessTypesystem (mms), createSpecificParameters (fileEncoding, mms, outlets));
- _extensions = new OldXtendRegistry (ctx, _ts);
- _registry = new OldXpandRegistry (ctx, _ts, _extensions);
- _registry.registerXpandFile (xpandFilename);
+ _fileEncoding = fileEncoding;
+ _mms = mms;
+ _outlets = outlets;
}
public Collection<NamedFunction> getContributedFunctions () {
- return _registry.getContributedFunctions (_xpandFile);
+ return _middleEnd.getFunctions(_xpandFile).getPublicFunctions();
}
public FunctionDefContext getFunctionDefContext () {
- if (getContributedFunctions().isEmpty())
- return new FunctionDefContextFactory(_ts).create();
+ if (_xpandFile == null)
+ return new FunctionDefContextFactory (_middleEnd.getTypesystem()).create();
- return ((SourceDefinedFunction) getContributedFunctions().iterator().next().getFunction()).getFunctionDefContext();
+ return _middleEnd.getFunctions (_xpandFile);
}
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandComponent.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java
index 30983fc..1acc9a8 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandComponent.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandComponent.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xpand;
+package org.eclipse.xtend.middleend.old;
import java.io.StringReader;
import java.util.ArrayList;
@@ -136,7 +136,7 @@ public class XpandComponent extends AbstractExpressionsUsingWorkflowComponent {
for (String name: wfContext.getSlotNames())
variables.put (name, wfContext.get (name));
- XpandBackendFacade.executeStatement (code, metaModels, variables, outlets);
+ XpandBackendFacade.executeStatement (code, _fileEncoding, metaModels, variables, outlets);
}
private final List<Outlet> outlets = new ArrayList<Outlet>();
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
index 23bda27..71333d4 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
@@ -8,25 +8,25 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.eclipose.xtend.middleend.MiddleEnd;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.xtend.parser.ParseFacade;
import org.eclipse.xtend.backend.BackendFacade;
-import org.eclipse.xtend.backend.common.BackendTypesystem;
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;
-import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.middleend.old.common.OldExpressionConverter;
@@ -34,6 +34,7 @@ import org.eclipse.xtend.middleend.old.common.OldHelper;
import org.eclipse.xtend.middleend.old.common.TypeToBackendType;
import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendGlobalVarOperations;
import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendLibContributor;
+import org.eclipse.xtend.middleend.old.plugin.OldXtendRegistryFactory;
import org.eclipse.xtend.typesystem.MetaModel;
@@ -42,10 +43,9 @@ import org.eclipse.xtend.typesystem.MetaModel;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public final class XtendBackendFacade {
- private final OldXtendRegistry _registry;
private final String _xtendFile;
- private final BackendTypesystem _ts;
-
+ private final MiddleEnd _middleEnd;
+ private final Collection<MetaModel> _mms;
/**
* This method invokes a "stand alone" expression that knows nothing about any functions defined in files. It is useful for
@@ -58,7 +58,7 @@ public final class XtendBackendFacade {
}
public static Object evaluateExpression (String expression, Collection<MetaModel> mms, Map<String, Object> localVars, Map<String, Object> globalVars) {
- return evaluateExpression (expression, null, null, mms, localVars, globalVars);
+ return evaluateExpression (expression, null, null, mms, localVars, globalVars, null);
}
/**
@@ -67,45 +67,57 @@ public final class XtendBackendFacade {
* The fileEncoding may be null, in which case the platform's default encoding is used. Both mms and localVars may be null.
*/
public static Object evaluateExpression (String expression, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> localVars) {
- return evaluateExpression (expression, initialXtendFileName, fileEncoding, mms, localVars, null);
+ return evaluateExpression (expression, initialXtendFileName, fileEncoding, mms, localVars, null, null);
+ }
+
+ public static Object evaluateExpression (String expression, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> localVars, Map<String, Object> globalVars, List<String> adviceResources) {
+ return createForFile (initialXtendFileName, fileEncoding, mms).evaluateExpression (expression, localVars, globalVars, adviceResources);
}
- public static Object evaluateExpression (String expression, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> localVars, Map<String, Object> globalVars) {
+ public Object evaluateExpression (String expression, Map<String, Object> localVars) {
+ return evaluateExpression (expression, localVars, null, null);
+ }
+
+ public Object evaluateExpression (String expression, Map<String, Object> localVars, Map<String, Object> globalVars, List<String> adviceResources) {
if (localVars == null)
localVars = new HashMap<String, Object> ();
if (globalVars == null)
globalVars = new HashMap<String, Object> ();
- if (mms == null)
- mms = new ArrayList<MetaModel> ();
+ if (adviceResources == null)
+ adviceResources = new ArrayList<String> ();
+
+ for (String a: adviceResources)
+ _middleEnd.applyAdvice (a);
final Expression oldAst = ParseFacade.expression (expression);
ExecutionContextImpl ctx = new ExecutionContextImpl ();
- for (MetaModel mm: mms)
+ for (MetaModel mm: _mms)
ctx.registerMetaModel (mm);
for (String varName: localVars.keySet())
ctx = (ExecutionContextImpl) ctx.cloneWithVariable (new Variable (varName, ctx.getType (localVars.get (varName))));
- final BackendTypesystem ts = OldHelper.guessTypesystem (mms);
- final TypeToBackendType typeConverter = new TypeToBackendType (ts, ctx);
-
- final ExpressionBase newAst = new OldExpressionConverter (ctx, typeConverter, "<no file>").convert(oldAst);
+ final TypeToBackendType typeConverter = new TypeToBackendType (_middleEnd.getTypesystem(), ctx);
+ final ExpressionBase newAst = new OldExpressionConverter (ctx, typeConverter, "<no file>").convert (oldAst);
- final FunctionDefContext fdc = createEmptyFdc (ts, initialXtendFileName, fileEncoding, mms);
- final ExecutionContext newCtx = BackendFacade.createExecutionContext (fdc, ts, true); //TODO configure isLogStacktrace
- newCtx.getLocalVarContext().getLocalVars().putAll (localVars);
- newCtx.getContributionStateContext().storeState (XtendGlobalVarOperations.GLOBAL_VAR_VALUES_KEY, globalVars);
+ final FunctionDefContext fdc = createFdc ();
+ _middleEnd.getExecutionContext().setFunctionDefContext (fdc);
+ //TODO configure isLogStacktrace
+ _middleEnd.getExecutionContext().getLocalVarContext().getLocalVars().putAll (localVars);
+ _middleEnd.getExecutionContext().getContributionStateContext().storeState (XtendGlobalVarOperations.GLOBAL_VAR_VALUES_KEY, globalVars);
- return newAst.evaluate (newCtx);
+ return newAst.evaluate (_middleEnd.getExecutionContext());
}
- private static FunctionDefContext createEmptyFdc (BackendTypesystem ts, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms) {
- if (initialXtendFileName != null)
- return createForFile (initialXtendFileName, fileEncoding, mms).getFunctionDefContext();
+ private FunctionDefContext createFdc () {
+ if (_xtendFile != null)
+ return getFunctionDefContext();
- final FunctionDefContextInternal result = new FunctionDefContextFactory (ts).create();
- result.register (new XtendLibContributor (ts).getContributedFunctions());
+ final FunctionDefContextInternal result = new FunctionDefContextFactory (_middleEnd.getTypesystem()).create();
+
+ for (NamedFunction f: new XtendLibContributor (_middleEnd.getTypesystem()).getContributedFunctions())
+ result.register (f, false);
return result;
}
@@ -115,9 +127,12 @@ public final class XtendBackendFacade {
* encoding is used.
*/
public static Object invokeXtendFunction (String xtendFileName, String fileEncoding, Collection<MetaModel> mms, String functionName, Object... parameters) {
- final XtendBackendFacade xbf = createForFile (xtendFileName, fileEncoding, mms);
- final FunctionDefContext fdc = xbf.getFunctionDefContext();
- final ExecutionContext ctx = BackendFacade.createExecutionContext (fdc, OldHelper.guessTypesystem (mms), true); //TODO configure isLogStacktrace
+ return createForFile (xtendFileName, fileEncoding, mms).invokeXtendFunction (functionName, parameters);
+ }
+
+ public Object invokeXtendFunction (String functionName, Object... parameters) {
+ final FunctionDefContext fdc = getFunctionDefContext();
+ final ExecutionContext ctx = BackendFacade.createExecutionContext (fdc, _middleEnd.getTypesystem(), true); //TODO configure isLogStacktrace
return fdc.invoke (ctx, functionName, Arrays.asList (parameters));
}
@@ -125,34 +140,35 @@ public final class XtendBackendFacade {
public static XtendBackendFacade createForFile (String xtendFileName, String fileEncoding, Collection<MetaModel> mms) {
return new XtendBackendFacade (xtendFileName, fileEncoding, mms);
}
-
- private XtendBackendFacade (String xtendFileName, String fileEncoding, Collection<MetaModel> mms) {
- if (mms == null)
- mms = new ArrayList<MetaModel> ();
-
+
+ private Map<Class<?>, Object> getSpecificParameters (String fileEncoding, Collection<MetaModel> mms) {
fileEncoding = OldHelper.normalizedFileEncoding (fileEncoding);
- _xtendFile = OldHelper.normalizeXtendResourceName (xtendFileName);
- _ts = OldHelper.guessTypesystem (mms);
-
+
final ExecutionContextImpl ctx = new ExecutionContextImpl ();
+ ctx.setFileEncoding (fileEncoding);
for (MetaModel mm: mms)
ctx.registerMetaModel (mm);
- ctx.setFileEncoding (fileEncoding);
-
- //TODO redesign to allow reuse of the registry?
- _registry = new OldXtendRegistry ( ctx, _ts);
- _registry.registerExtension (xtendFileName);
+
+ final Map<Class<?>, Object> result = new HashMap<Class<?>, Object> ();
+ result.put (OldXtendRegistryFactory.class, ctx);
+ return result;
}
- public Collection<NamedFunction> getContributedFunctions () {
- return _registry.getContributedFunctions (_xtendFile);
+
+ private XtendBackendFacade (String xtendFileName, String fileEncoding, Collection<MetaModel> mms) {
+ if (mms == null)
+ mms = new ArrayList<MetaModel> ();
+
+ _xtendFile = OldHelper.normalizeXtendResourceName (xtendFileName);
+ _mms = mms;
+ _middleEnd = new MiddleEnd (OldHelper.guessTypesystem (mms), getSpecificParameters (fileEncoding, mms));
}
public FunctionDefContext getFunctionDefContext () {
- if (getContributedFunctions().isEmpty())
- return new FunctionDefContextFactory(_ts).create();
-
- return ((SourceDefinedFunction) getContributedFunctions().iterator().next().getFunction()).getFunctionDefContext();
+ if (_xtendFile == null)
+ return new FunctionDefContextFactory (_middleEnd.getTypesystem()).create();
+
+ return _middleEnd.getFunctions (_xtendFile);
}
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendComponent.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java
index 17a4e39..872187d 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/XtendComponent.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendComponent.java
@@ -8,9 +8,13 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+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;
import org.eclipse.emf.mwe.core.issues.Issues;
@@ -19,9 +23,6 @@ import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory;
import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
import org.eclipse.internal.xtend.xtend.XtendFile;
import org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent;
-import org.eclipse.xtend.expression.ExecutionContext;
-import org.eclipse.xtend.expression.ExpressionFacade;
-import org.eclipse.xtend.expression.Variable;
/**
@@ -33,12 +34,12 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
// private final Log _log = LogFactory.getLog(getClass());
-// private List<String> extensionAdvices = new ArrayList<String>();
-//
-// public void addExtensionAdvice(String extensionAdvices) {
-// if ( !this.extensionAdvices.contains(extensionAdvices) )
-// this.extensionAdvices.add( extensionAdvices );
-// }
+ 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;
@@ -46,17 +47,6 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
private String _expression = null;
private String _outputSlot = WorkflowContext.DEFAULT_SLOT;
-// private String collectProfileSummary = null;
-// private String verboseProfileFilename = null;
-//
-// public void setCollectProfileSummary (String c) {
-// collectProfileSummary = c;
-// }
-//
-// public void setVerboseProfileFilename (String f) {
-// verboseProfileFilename = f;
-// }
-
@Override
public String getLogMessage() {
@@ -85,73 +75,22 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
return;
}
-// OutputStream verboseProfileOutputStream = null;
-//
-// if (verboseProfileFilename != null) {
-// try {
-// verboseProfileOutputStream = new BufferedOutputStream (new FileOutputStream (verboseProfileFilename));
-// ProfileCollector.getInstance().setDetailedLoggingWriter(verboseProfileOutputStream);
-// }
-// catch (IOException exc) {
-// _log.warn("could not open profiling log file", exc);
-// }
-// }
-
+ final List<String> adviceResources = new ArrayList<String>();
+ for (String rawAdvice : _extensionAdvices)
+ for (String a: rawAdvice.split (","))
+ adviceResources.add (a.trim());
- ExecutionContext ec = getExecutionContext(ctx);
+ final Map<String, Object> localVars = new HashMap<String, Object> ();
+ for (String slotName: ctx.getSlotNames())
+ localVars.put (slotName, ctx.get (slotName));
-// for (String advice : extensionAdvices) {
-// final String[] allAdvices = advice.split(",");
-// for (int i = 0; i < allAdvices.length; i++) {
-// final String string = allAdvices[i];
-// ec.registerExtensionAdvices(string.trim());
-// }
-// }
-//
-// ec = ec.cloneWithResource(new Resource() {
-// private String name = "noName";
-//
-// public String getFullyQualifiedName() {
-// return name;
-// }
-//
-// public void setFullyQualifiedName(final String fqn) {
-// name = fqn;
-// }
-//
-// public String[] getImportedNamespaces() {
-// return new String[0];
-// }
-//
-// public String[] getImportedExtensions() {
-// return new String[] { _extensionFile };
-// }
-// });
- final String[] slots = ctx.getSlotNames();
- for (int i = 0; i < slots.length; i++) {
- ec = ec.cloneWithVariable(new Variable(slots[i], ctx.get(slots[i])));
- }
-
-// if (monitor!=null) {
-// ec.setMonitor(monitor);
-// }
+ final Map<String, Object> globalVars = new HashMap<String, Object> ();
+ for (GlobalVarDef gvd: globalVarDefs)
+ globalVars.put (gvd.getName(), gvd.getValue());
- final Object result = new ExpressionFacade (ec).evaluate(_expression);
+ //TODO allow file encoding configuration
+ final Object result = XtendBackendFacade.evaluateExpression (_expression, _extensionFile, null, metaModels, localVars, globalVars, adviceResources);
ctx.set (_outputSlot, result);
-
-// ProfileCollector.getInstance().finish();
-// if ("true".equalsIgnoreCase(this.collectProfileSummary)) {
-// _log.info ("profiling info: \n" + ProfileCollector.getInstance().toString());
-// }
-
-// if (verboseProfileOutputStream != null) {
-// try {
-// verboseProfileOutputStream.close ();
-// }
-// catch (IOException exc) {
-// _log.warn("problem closing profile log file", exc);
-// }
-// }
}
private boolean extensionFileExists() {
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 099bc00..8333013 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
@@ -35,7 +35,6 @@ import org.eclipse.internal.xtend.expression.ast.StringLiteral;
import org.eclipse.internal.xtend.expression.ast.SwitchExpression;
import org.eclipse.internal.xtend.expression.ast.SyntaxElement;
import org.eclipse.internal.xtend.expression.ast.TypeSelectExpression;
-import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
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;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldHelper.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldHelper.java
index 0a102d1..6a5a8ec 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldHelper.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/common/OldHelper.java
@@ -53,6 +53,9 @@ public final class OldHelper {
}
public static String normalizeXtendResourceName (String xtendName) {
+ if (xtendName == null)
+ return null;
+
xtendName = xtendName.replace (SyntaxConstants.NS_DELIM, "/");
if (xtendName.endsWith ("." + XtendFile.FILE_EXTENSION))
xtendName = xtendName.substring (0, xtendName.length() - (XtendFile.FILE_EXTENSION.length() + 1));
@@ -61,6 +64,9 @@ public final class OldHelper {
}
public static String normalizeXpandResourceName (String xpandName) {
+ if (xpandName == null)
+ return null;
+
if (! xpandName.endsWith("." + XpandUtil.TEMPLATE_EXTENSION))
xpandName += "." + XpandUtil.TEMPLATE_EXTENSION;
@@ -70,6 +76,9 @@ public final class OldHelper {
}
public static String xpandFileAsOldResourceName (String xpandName) {
+ if (xpandName == null)
+ return null;
+
if (xpandName.toLowerCase().endsWith (XpandUtil.TEMPLATE_EXTENSION))
xpandName = xpandName.substring (0, xpandName.length() - XpandUtil.TEMPLATE_EXTENSION.length() - 1);
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldDefinitionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java
index f94c1c4..767e78d 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldDefinitionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldDefinitionConverter.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xpand;
+package org.eclipse.xtend.middleend.old.internal.xpand;
import java.util.ArrayList;
import java.util.Arrays;
@@ -74,7 +74,7 @@ import org.eclipse.xtend.typesystem.Type;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class OldDefinitionConverter {
+public final class OldDefinitionConverter {
private XpandExecutionContext _ctx;
private final TypeToBackendType _typeConverter;
@@ -94,7 +94,7 @@ final class OldDefinitionConverter {
*/
public NamedFunction create (XpandDefinition def, FunctionDefContextInternal fdc, Set<XpandDefinitionName> referencedDefinitions) {
final NamedFunction result = createUnregistered (def, fdc, referencedDefinitions);
- fdc.register (result);
+ fdc.register (result, true);
return result;
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldXpandRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
index 7e126bb..59babf1 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/OldXpandRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
@@ -8,21 +8,24 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xpand;
+package org.eclipse.xtend.middleend.old.internal.xpand;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
import org.eclipse.internal.xpand2.ast.Template;
import org.eclipse.internal.xpand2.model.XpandDefinition;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xpand2.XpandUtil;
+import org.eclipse.xtend.backend.aop.AroundAdvice;
import org.eclipse.xtend.backend.common.BackendTypesystem;
+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;
@@ -30,7 +33,6 @@ import org.eclipse.xtend.backend.util.Cache;
import org.eclipse.xtend.middleend.old.common.OldHelper;
import org.eclipse.xtend.middleend.old.common.TypeToBackendType;
import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendLibContributor;
-import org.eclipse.xtend.middleend.old.xtend.OldXtendRegistry;
/**
@@ -38,10 +40,10 @@ import org.eclipse.xtend.middleend.old.xtend.OldXtendRegistry;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class OldXpandRegistry {
+public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
private final XpandExecutionContext _ctx;
private final BackendTypesystem _ts;
- private final OldXtendRegistry _extensions;
+ private final MiddleEnd _middleEnd;
private final Cache<String, FunctionDefContextInternal> _functionDefContexts = new Cache<String, FunctionDefContextInternal> () {
@Override
@@ -56,16 +58,19 @@ final class OldXpandRegistry {
private final Map<String, List<NamedFunction>> _functionsByResource = new HashMap <String, List<NamedFunction>>();
- public OldXpandRegistry (XpandExecutionContext ctx, BackendTypesystem ts, OldXtendRegistry extensions) {
- _ctx = ctx;
- _ts = ts;
- _extensions = extensions;
- }
-
-
private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldHelper.normalizeXtendResourceName (xtendName));
}
+
+
+ public OldXpandRegistry (MiddleEnd middleEnd, Object specificData) {
+ if (specificData == null)
+ throw new IllegalArgumentException (getName() + " middle end is not initialized - will not contribute");
+
+ _ctx = (XpandExecutionContext) specificData;
+ _middleEnd = middleEnd;
+ _ts = middleEnd.getTypesystem();
+ }
/**
@@ -77,7 +82,7 @@ final class OldXpandRegistry {
if (_functionsByResource.containsKey (xpandFile))
return;
- final String xpandResourceName = OldHelper.xpandFileAsOldResourceName(xpandFile);
+ final String xpandResourceName = OldHelper.xpandFileAsOldResourceName (xpandFile);
final Template file = (Template) _ctx.getResourceManager().loadResource (xpandResourceName, XpandUtil.TEMPLATE_EXTENSION);
if (file == null)
throw new IllegalArgumentException ("could not find Xpand file '" + xpandResourceName + "'");
@@ -91,43 +96,65 @@ final class OldXpandRegistry {
final FunctionDefContextInternal fdc = getFunctionDefContext (xpandFile);
// register the XtendLib. Do this first so the extension can override functions
- fdc.register (new XtendLibContributor (_ts).getContributedFunctions());
-
- //TODO imported namespaces
+ for (NamedFunction f: new XtendLibContributor (_ts).getContributedFunctions())
+ fdc.register (f, false);
final Set<XpandDefinitionName> referenced = new HashSet<XpandDefinitionName> ();
for (XpandDefinition ext: file.getDefinitions ())
defined.add (definitionFactory.create (ext, fdc, referenced));
-
_functionsByResource.put (xpandFile, defined);
// make sure all imported resources are registered as well
- for (String imported: file.getImportedExtensions()) {
- _extensions.registerExtension (imported);
- for (NamedFunction f: _extensions.getContributedFunctions(imported))
- fdc.register (f);
- }
+ for (String imported: file.getImportedExtensions())
+ for (NamedFunction f: _middleEnd.getFunctions (imported).getPublicFunctions())
+ fdc.register (f, false);
- // read all referenced template files...
+ // collect all referenced template files...
final Set<String> xpandFileNames = new HashSet<String> ();
for (XpandDefinitionName n: referenced)
xpandFileNames.add (n.getCanonicalTemplateFileName());
- for (String xpandFileName: xpandFileNames)
- registerXpandFile (xpandFileName);
-
// ... and register all template definitions from these files. It is necessary to have them all registered to enable
// polymorphism - static type analysis does not find all potential matches.
for (String xpandFileName: xpandFileNames)
- for (NamedFunction f: _functionsByResource.get (xpandFileName))
- fdc.register(f);
+ for (NamedFunction f: _middleEnd.getFunctions (xpandFileName).getPublicFunctions())
+ fdc.register (f, false);
+ }
+
+
+ public FunctionDefContext getContributedFunctions (String xpandFile) {
+ registerXpandFile (xpandFile);
+ return getFunctionDefContext (xpandFile);
+ }
+
+
+ public boolean canHandle (String xpandFile) {
+ xpandFile = OldHelper.normalizeXpandResourceName (xpandFile);
+
+ if (_functionsByResource.containsKey (xpandFile))
+ return true;
+
+ final String xpandResourceName = OldHelper.xpandFileAsOldResourceName (xpandFile);
+ try {
+ final Template file = (Template) _ctx.getResourceManager().loadResource (xpandResourceName, XpandUtil.TEMPLATE_EXTENSION);
+ return file != null;
+ }
+ catch (Exception exc) {
+ return false;
+ }
+ }
+
+
+ public List<AroundAdvice> getContributedAdvice (String resourceName) {
+ //TODO Xpand advice
+ return new ArrayList<AroundAdvice>();
}
- public Collection<NamedFunction> getContributedFunctions (String xpandFile) {
- return _functionsByResource.get (xpandFile);
+ public String getName () {
+ return "Xpand";
}
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandDefinitionName.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/XpandDefinitionName.java
index c9dcb6f..d10832b 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xpand/XpandDefinitionName.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/XpandDefinitionName.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xpand;
+package org.eclipse.xtend.middleend.old.internal.xpand;
import java.util.List;
@@ -30,7 +30,7 @@ import org.eclipse.xtend.typesystem.Type;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class XpandDefinitionName {
+public final class XpandDefinitionName {
private final String _canonicalDefinitionName;
private final String _canonicalTemplateFileName;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/CheckConverter.java
index 0fd1fd1..cc0ac37 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/CheckConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/CheckConverter.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old.internal.xtend;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/JavaExtensionFunction.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/JavaExtensionFunction.java
index c71b7e1..6052a58 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/JavaExtensionFunction.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/JavaExtensionFunction.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old.internal.xtend;
import java.lang.reflect.Method;
import java.util.List;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldExtensionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java
index d136849..bb6190d 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldExtensionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldExtensionConverter.java
@@ -8,18 +8,25 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+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;
@@ -31,6 +38,8 @@ 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;
@@ -44,7 +53,7 @@ import org.eclipse.xtend.typesystem.Type;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class OldExtensionConverter {
+public final class OldExtensionConverter {
private final ExecutionContext _ctx;
private final TypeToBackendType _typeConverter;
@@ -54,13 +63,33 @@ 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);
+ }
+
/**
* converts an extension to a function, taking care of mutual registration with its fdc
*/
public NamedFunction create (Extension extension, FunctionDefContextInternal fdc) {
final NamedFunction result = new NamedFunction (extension.getName(), createUnregistered (extension, fdc));
- fdc.register (result);
+ fdc.register (result, !extension.isPrivate());
return result;
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldXtendRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java
index 3583022..262f7ae 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/xtend/OldXtendRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.middleend.old.xtend;
+package org.eclipse.xtend.middleend.old.internal.xtend;
import java.util.ArrayList;
import java.util.Collection;
@@ -18,11 +18,16 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
import org.eclipse.internal.xtend.xtend.XtendFile;
+import org.eclipse.internal.xtend.xtend.ast.Around;
import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.internal.xtend.xtend.ast.ExtensionFile;
import org.eclipse.internal.xtend.xtend.ast.ImportStatement;
+import org.eclipse.xtend.backend.aop.AroundAdvice;
import org.eclipse.xtend.backend.common.BackendTypesystem;
+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;
@@ -38,9 +43,13 @@ import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendLibContributor;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public final class OldXtendRegistry {
+public final class OldXtendRegistry implements LanguageSpecificMiddleEnd {
private final ExecutionContext _ctx;
- private final BackendTypesystem _ts;
+
+ @SuppressWarnings("unused")
+ private final MiddleEnd _middleEnd;
+
+ private BackendTypesystem _ts;
private final Cache<String, FunctionDefContextInternal> _functionDefContexts = new Cache<String, FunctionDefContextInternal> () {
@Override
@@ -66,12 +75,21 @@ public final class OldXtendRegistry {
*/
private final Map<String, List<NamedFunction>> _locallyExportedFunctionsByResource = new HashMap <String, List<NamedFunction>>();
+ private final Map<String, List<AroundAdvice>> _advice = new HashMap<String, List<AroundAdvice>> ();
+
- public OldXtendRegistry (ExecutionContext ctx, BackendTypesystem ts) {
- _ctx = ctx;
- _ts = ts;
+ /**
+ * the specificData field contains an ExecutionContext initialized with the MetaModels and the file encoding
+ */
+ public OldXtendRegistry (MiddleEnd middleEnd, Object specificData) {
+ if (specificData == null)
+ throw new IllegalArgumentException (getName() + " middle end is not initialized - will not contribute");
+
+ _middleEnd = middleEnd;
+ _ts = middleEnd.getTypesystem();
+ _ctx = (ExecutionContext) specificData;
}
-
+
private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldHelper.normalizeXtendResourceName (xtendName));
@@ -81,22 +99,22 @@ public final class OldXtendRegistry {
/**
* parses and converts an Xtend file and all other files it depends on.
*/
- public void registerExtension (String xtendFile) {
+ public void registerExtensionFile (String xtendFile) {
xtendFile = OldHelper.normalizeXtendResourceName (xtendFile);
- if (_definedFunctionsByResource.containsKey(xtendFile))
+ if (_definedFunctionsByResource.containsKey (xtendFile))
return;
- final ExtensionFile file = (ExtensionFile) _ctx.getResourceManager().loadResource (xtendFile, XtendFile.FILE_EXTENSION);
- if (file == null)
+ final ExtensionFile extensionFile = (ExtensionFile) _ctx.getResourceManager().loadResource (xtendFile, XtendFile.FILE_EXTENSION);
+ if (extensionFile == null)
throw new IllegalArgumentException ("could not find extension '" + xtendFile + "'");
- final ExecutionContext ctx = _ctx.cloneWithResource (file);
+ final ExecutionContext ctx = _ctx.cloneWithResource (extensionFile);
final TypeToBackendType typeConverter = new TypeToBackendType (_ts, ctx);
final OldExtensionConverter extensionFactory = new OldExtensionConverter (ctx, typeConverter);
- for (Extension ext: file.getExtensions())
+ for (Extension ext: extensionFile.getExtensions())
ext.init (ctx);
final List<NamedFunction> defined = new ArrayList<NamedFunction>();
@@ -105,11 +123,12 @@ public final class OldXtendRegistry {
final FunctionDefContextInternal fdc = getFunctionDefContext (xtendFile);
// register the XtendLib. Do this first so the extension can override functions
- fdc.register (new XtendLibContributor (_ts).getContributedFunctions());
+ for (NamedFunction f: new XtendLibContributor (_ts).getContributedFunctions())
+ fdc.register (f, false);
- fdc.register (new CheckConverter (ctx, typeConverter).createCheckFunction(_ts, fdc, file));
+ fdc.register (new CheckConverter (ctx, typeConverter).createCheckFunction(_ts, fdc, extensionFile), false);
- for (Extension ext: file.getExtensions()) {
+ for (Extension ext: extensionFile.getExtensions()) {
final NamedFunction f = extensionFactory.create (ext, fdc);
defined.add(f);
@@ -123,13 +142,13 @@ public final class OldXtendRegistry {
_locallyExportedFunctionsByResource.put (xtendFile, new ArrayList<NamedFunction> (exported));
// make sure all imported resources are registered as well
- for (String imported: file.getImportedExtensions())
- registerExtension (imported);
+ for (String imported: extensionFile.getImportedExtensions())
+ registerExtensionFile (imported);
// make all imported extensions visible for the scope of this compilation unit
- for (String importedResource: file.getImportedExtensions()) {
+ for (String importedResource: extensionFile.getImportedExtensions()) {
for (NamedFunction f: _locallyExportedFunctionsByResource.get (OldHelper.normalizeXtendResourceName (importedResource)))
- fdc.register (f);
+ fdc.register (f, false);
}
final Set<String> visitedForReexport = new HashSet<String>();
@@ -139,8 +158,13 @@ public final class OldXtendRegistry {
for (NamedFunction f: reexported) {
exported.add (f);
- fdc.register (f);
+ fdc.register (f, true);
}
+
+ final List<AroundAdvice> advice = new ArrayList<AroundAdvice> ();
+ _advice.put (xtendFile, advice);
+ for (Around a: extensionFile.getArounds())
+ advice.add (extensionFactory.create (a, fdc));
}
private void getReexported (String xtendFile, Collection<NamedFunction> result, Set<String> harvestedCompilationUnits, Set<String> processedCompilationUnits) {
@@ -164,8 +188,33 @@ public final class OldXtendRegistry {
}
}
- public Collection<NamedFunction> getContributedFunctions (String xtendFile) {
- return _exportedFunctionsByResource.get (OldHelper.normalizeXtendResourceName(xtendFile));
+ public boolean canHandle (String resourceName) {
+ resourceName = OldHelper.normalizeXtendResourceName (resourceName);
+
+ if (_definedFunctionsByResource.containsKey (resourceName))
+ return true;
+
+ try {
+ final ExtensionFile extensionFile = (ExtensionFile) _ctx.getResourceManager().loadResource (resourceName, XtendFile.FILE_EXTENSION);
+ return extensionFile != null;
+ }
+ catch (Exception exc) {
+ return false;
+ }
+ }
+
+ public FunctionDefContext getContributedFunctions (String xtendFile) {
+ registerExtensionFile (xtendFile);
+ return getFunctionDefContext(xtendFile);
+ }
+
+ public List<AroundAdvice> getContributedAdvice (String resourceName) {
+ registerExtensionFile (resourceName);
+ return _advice.get (OldHelper.normalizeXtendResourceName (resourceName));
+ }
+
+ public String getName () {
+ return "Xtend";
}
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXpandRegistryFactory.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXpandRegistryFactory.java
new file mode 100644
index 0000000..c5d0b22
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXpandRegistryFactory.java
@@ -0,0 +1,36 @@
+/*
+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.middleend.old.plugin;
+
+import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEndFactory;
+import org.eclipse.xtend.middleend.old.internal.xpand.OldXpandRegistry;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class OldXpandRegistryFactory implements LanguageSpecificMiddleEndFactory {
+
+ public LanguageSpecificMiddleEnd create (MiddleEnd middleEnd, Object specificData) {
+ return new OldXpandRegistry (middleEnd, specificData);
+ }
+
+ public String getName () {
+ return "Xpand";
+ }
+
+ public int getPriority () {
+ return 0;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXtendRegistryFactory.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXtendRegistryFactory.java
new file mode 100644
index 0000000..180c6de
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXtendRegistryFactory.java
@@ -0,0 +1,36 @@
+/*
+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.middleend.old.plugin;
+
+import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEndFactory;
+import org.eclipse.xtend.middleend.old.internal.xtend.OldXtendRegistry;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class OldXtendRegistryFactory implements LanguageSpecificMiddleEndFactory {
+
+ public LanguageSpecificMiddleEnd create (MiddleEnd middleEnd, Object specificData) {
+ return new OldXtendRegistry (middleEnd, specificData);
+ }
+
+ public String getName () {
+ return "Xtend";
+ }
+
+ public int getPriority () {
+ return 0;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.middleend/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.middleend/META-INF/MANIFEST.MF
index f11e68b..79a8c03 100644
--- a/plugins/org.eclipse.xtend.middleend/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.middleend/META-INF/MANIFEST.MF
@@ -1,8 +1,14 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Middleend Plug-in (Incubation)
-Bundle-SymbolicName: org.eclipse.xtend.middleend
+Bundle-SymbolicName: org.eclipse.xtend.middleend;singleton:=true
Bundle-Version: 0.7.0
Require-Bundle: org.eclipse.xtend.backend,
- org.eclipse.xtend.backend.emftypes
-Export-Package: org.eclipose.xtend.middleend
+ org.eclipse.xtend.backend.emftypes,
+ org.eclipse.equinox.registry,
+ org.eclipse.osgi,
+ org.apache.commons.logging
+Export-Package: org.eclipose.xtend.middleend,
+ org.eclipose.xtend.middleend.plugins
+Bundle-Activator: org.eclipose.xtend.middleend.internal.Activator
+Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.xtend.middleend/build.properties b/plugins/org.eclipse.xtend.middleend/build.properties
index 34d2e4d..e9863e2 100644
--- a/plugins/org.eclipse.xtend.middleend/build.properties
+++ b/plugins/org.eclipse.xtend.middleend/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ plugin.xml
diff --git a/plugins/org.eclipse.xtend.middleend/plugin.xml b/plugins/org.eclipse.xtend.middleend/plugin.xml
new file mode 100644
index 0000000..4fa5641
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/plugin.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension-point id="MiddleEnd" name="Middle Enf" schema="schema/MiddleEnd.exsd"/>
+
+</plugin>
diff --git a/plugins/org.eclipse.xtend.middleend/schema/MiddleEnd.exsd b/plugins/org.eclipse.xtend.middleend/schema/MiddleEnd.exsd
new file mode 100644
index 0000000..1bea36e
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/schema/MiddleEnd.exsd
@@ -0,0 +1,105 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.xtend.middleend">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.xtend.middleend" id="MiddleEnd" name="Middle Enf"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="element_1" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="element_1">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEndFactory"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/BackendTypesystemFactory.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/BackendTypesystemFactory.java
deleted file mode 100644
index af22182..0000000
--- a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/BackendTypesystemFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-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.eclipose.xtend.middleend;
-
-import java.util.List;
-
-import org.eclipse.xtend.backend.common.BackendTypesystem;
-import org.eclipse.xtend.backend.types.CompositeTypesystem;
-import org.eclipse.xtend.backend.types.emf.EmfTypesystem;
-
-
-/**
- *
- * @author Arno Haase (http://www.haase-consulting.com)
- */
-public final class BackendTypesystemFactory {
-
- /**
- * This generic factory requires the caller to provide a complete list of typesystems that
- * will comprise the actual typesystem. The ordering in this list is semantically
- * relevant because types are searched from beginning to end.
- */
- public static CompositeTypesystem create (List<? extends BackendTypesystem> typesystems) {
- final CompositeTypesystem result = new CompositeTypesystem ();
-
- for (BackendTypesystem ts: typesystems)
- result.register(ts);
-
- return result;
- }
-
- /**
- * This is a convenience factory method to create a typesystem that supports both EMF
- * and Java Beans. UML is left out for performance reasons - the UML metamodel requires
- * the UML metamodel to be parsed initially which takes significant time.
- */
- public static CompositeTypesystem createJustEmf () {
- final CompositeTypesystem result = new CompositeTypesystem ();
-
- result.register (new EmfTypesystem ());
-
- return result;
- }
-}
-
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java
new file mode 100644
index 0000000..66cf6b1
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java
@@ -0,0 +1,97 @@
+/*
+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.eclipose.xtend.middleend;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipose.xtend.middleend.internal.Activator;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipse.xtend.backend.BackendFacade;
+import org.eclipse.xtend.backend.aop.AroundAdvice;
+import org.eclipse.xtend.backend.common.BackendTypesystem;
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.FunctionDefContext;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+
+
+/**
+ * This class is the generic entry point for parsing and executing code. Different
+ * languages can contribute their specific middle ends using extension points.<br>
+ *
+ * MiddleEnd instances are stateful in that they preserve caching of the contributed
+ * middle ends. They also preserve a single ExecutionContext instance throughout their
+ * life span, but they expose it to allows using code to selectively manipulate and / or
+ * re-initialize it between invocations.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class MiddleEnd {
+ private static final Log _log = LogFactory.getLog (MiddleEnd.class);
+
+ private final List<LanguageSpecificMiddleEnd> _middleEnds;
+ private final ExecutionContext _ctx;
+ private final BackendTypesystem _ts;
+
+ /**
+ * The map with "specific params" is used to initialize the contributed middle ends.
+ * The key must be the class implementing the LanguageSpecificMiddleEnd interface
+ * and contributed via the extension point.
+ */
+ public MiddleEnd (BackendTypesystem ts, Map<Class<?>, Object> specificParams) {
+ _ctx = BackendFacade.createExecutionContext (new FunctionDefContextFactory (ts).create(), ts, false);
+ _ts = ts;
+ _middleEnds = Activator.getInstance().getFreshMiddleEnds (this, specificParams);
+ }
+
+ private LanguageSpecificMiddleEnd findHandler (String resourceName) {
+ for (LanguageSpecificMiddleEnd candidate: _middleEnds) {
+ if (candidate.canHandle (resourceName)) {
+ _log.debug ("middle end " + candidate.getName() + " handles resource " + resourceName);
+ return candidate;
+ }
+ }
+
+ _log.warn ("no middle end for resource " + resourceName);
+ throw new IllegalArgumentException ("no middle end for resource " + resourceName);
+ }
+
+ /**
+ * tells this middle end instance to apply the advice in a given resource to all
+ * subsequent invocations.
+ */
+ public void applyAdvice (String resourceName) {
+ for (AroundAdvice advice: findHandler(resourceName).getContributedAdvice(resourceName))
+ _ctx.setAdviceContext (_ctx.getAdviceContext().copyWithAdvice (advice));
+ }
+
+ public FunctionDefContext getFunctions (String resourceName) {
+ return findHandler (resourceName).getContributedFunctions (resourceName);
+ }
+
+
+ /**
+ * This method exposes the execution context to using code with the explicit purpose of allowing others to
+ * inspect and manipulate / re-initialize it partially or in toto. <br>
+ *
+ * But beware: This data structure is used directly by the runtime, and modifications can significantly
+ * influence behavior at runtime!
+ */
+ public ExecutionContext getExecutionContext () {
+ return _ctx;
+ }
+
+ public BackendTypesystem getTypesystem () {
+ return _ts;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/internal/Activator.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/internal/Activator.java
new file mode 100644
index 0000000..82b2613
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/internal/Activator.java
@@ -0,0 +1,101 @@
+/*
+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.eclipose.xtend.middleend.internal;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEndFactory;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class Activator implements BundleActivator {
+ private static final Log _log = LogFactory.getLog (Activator.class);
+
+ private static Activator _instance = null;
+
+ public static Activator getInstance () {
+ return _instance;
+ }
+
+ private final List<LanguageSpecificMiddleEndFactory> _middleEndContributions = new ArrayList<LanguageSpecificMiddleEndFactory> ();
+
+
+ public List<LanguageSpecificMiddleEnd> getFreshMiddleEnds (MiddleEnd middleEnd, Map<Class<?>, Object> specificParams) {
+ final List<LanguageSpecificMiddleEnd> result = new ArrayList<LanguageSpecificMiddleEnd>();
+
+ for (LanguageSpecificMiddleEndFactory factory: _middleEndContributions) {
+ try {
+ result.add (factory.create (middleEnd, specificParams.get (factory.getClass())));
+ }
+ catch (IllegalArgumentException exc) {
+ // this is the official way for an implementation to withdraw from the pool for this call
+ _log.debug ("middle end implementation " + factory.getName() + " says it is not available: " + exc.getMessage());
+ }
+ }
+
+ return result;
+ }
+
+ public void start (BundleContext context) throws Exception {
+ //TODO Bernd: implement error handling and logging to be both robust and independent of Eclipse
+
+ _log.info ("Activating Eclipse Modeling Middle End - the following middle ends are registered:");
+
+ init ();
+
+ for (LanguageSpecificMiddleEndFactory factory: _middleEndContributions)
+ _log.info (" " + factory.getName());
+
+ _instance = this;
+ }
+
+ private void init () throws CoreException {
+ _middleEndContributions.clear ();
+
+ try {
+ final IConfigurationElement[] confEl = RegistryFactory.getRegistry().getConfigurationElementsFor ("org.eclipse.xtend.middleend.MiddleEnd");
+
+ for (IConfigurationElement curEl: confEl) {
+ final Object o = curEl.createExecutableExtension ("class");
+ _middleEndContributions.add ((LanguageSpecificMiddleEndFactory) o);
+ }
+ }
+ catch (Exception exc) {
+ exc.printStackTrace ();
+ }
+
+ Collections.sort (_middleEndContributions, new Comparator <LanguageSpecificMiddleEndFactory> () {
+ public int compare (LanguageSpecificMiddleEndFactory o1, LanguageSpecificMiddleEndFactory o2) {
+ return o1.getPriority() - o2.getPriority();
+ }
+ });
+ }
+
+ public void stop (BundleContext context) throws Exception {
+ _instance = null;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEnd.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEnd.java
new file mode 100644
index 0000000..5496e40
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEnd.java
@@ -0,0 +1,51 @@
+/*
+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.eclipose.xtend.middleend.plugins;
+
+import java.util.List;
+
+import org.eclipse.xtend.backend.aop.AroundAdvice;
+import org.eclipse.xtend.backend.common.FunctionDefContext;
+
+
+/**
+ * This interface is the common abstraction through which all handlers for different
+ * languages can contribute their middle ends.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface LanguageSpecificMiddleEnd {
+ String getName ();
+
+ /**
+ * gives the middle end a way to declare if it can and wants to handle a given
+ * source file / resource. If and only if it returns true, it will be asked for
+ * the functions and advice provided in this resource.
+ */
+ boolean canHandle (String resourceName);
+
+ /**
+ * This method asks the middle end to parse a resource for which it declared
+ * that it is the appropriate handler, and return the functions contained therein.<br>
+ *
+ * Implementations are encouraged to perform aggressive caching. The calling code
+ * takes care of re-initializing the middle end implementations as it deems fit by
+ * creating new instances of the contributed middle end implementation classes.
+ */
+ FunctionDefContext getContributedFunctions (String resourceName);
+
+ /**
+ * This method is the same as getContributedFunctions, except that it returns advice
+ * rather than functions. Since the semantics of advice depends on the order in which
+ * it is applied, this method returns a list rather than an arbitrary collection.
+ */
+ List<AroundAdvice> getContributedAdvice (String resourceName);
+}
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEndFactory.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEndFactory.java
new file mode 100644
index 0000000..d9d7cc9
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEndFactory.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.eclipose.xtend.middleend.plugins;
+
+import org.eclipose.xtend.middleend.MiddleEnd;
+
+
+/**
+ * This interface is the common abstraction through which all handlers for different
+ * languages can contribute their middle ends. Every language should contribute its
+ * MiddleEnd implementation factory through the extension point.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface LanguageSpecificMiddleEndFactory {
+ /**
+ * a clear text name describing the language / middle end
+ */
+ String getName ();
+
+ /**
+ * the priority is a possible way to determine the order in which the middle ends
+ * are asked if they can handle a given resource. Typically, only one middle end
+ * implementation should declare that it can handle a given resource (i.e. source
+ * file), and in this case a priority of 0 should be returned. <br>
+ *
+ * In the rare case where it is needed, highest priority is asked first.
+ */
+ int getPriority ();
+
+ /**
+ * This method creates the actual implementation of the middle end. The specificData parameter is
+ * passed through from the MiddleEnd constructor.<br>
+ *
+ * It is permitted for implementations to throw an IllegalArgumentException,
+ * which is the official way for an implementation to say that it views the
+ * passed data as insufficient to perform, and therefore needs to be removed
+ * from the list of registered middle ends. This is done on a per-call basis
+ * and avoids the necessity to always initialize all middle end implementations.
+ */
+ LanguageSpecificMiddleEnd create (MiddleEnd middleEnd, Object specificData);
+}
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
index e520e78..8afeb58 100644
--- a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
@@ -31,7 +31,7 @@ import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Type1;
import org.eclipse.xtend.expression.Variable;
-import org.eclipse.xtend.middleend.old.xtend.XtendBackendFacade;
+import org.eclipse.xtend.middleend.old.XtendBackendFacade;
import org.eclipse.xtend.typesystem.Property;
/**
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 6bcb9fe..275b493 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
@@ -33,7 +33,7 @@ public abstract class AbstractExpressionsUsingWorkflowComponent extends
protected final List<MetaModel> metaModels = new ArrayList<MetaModel>();
- private List<GlobalVarDef> globalVarDefs = new ArrayList<GlobalVarDef>();
+ protected final List<GlobalVarDef> globalVarDefs = new ArrayList<GlobalVarDef>();
public void addMetaModel(final MetaModel metaModel) {
assert metaModel != null;
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExpressionFacade.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExpressionFacade.java
index c352960..0c0431d 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExpressionFacade.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExpressionFacade.java
@@ -32,7 +32,7 @@ public class ExpressionFacade {
return execContext;
}
- public ExpressionFacade(final ExecutionContext execCtx) {
+ public ExpressionFacade (final ExecutionContext execCtx) {
execContext = execCtx;
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTest.java
index 41d3147..6d693e1 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTest.java
@@ -51,7 +51,7 @@ public class AopTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (CounterFunction.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
@SuppressWarnings("unchecked")
final Pointcut pointCut = new ExecutionPointcut ("*", Collections.EMPTY_LIST, true, new AdviceParamType (ObjectType.INSTANCE, true));
@@ -78,7 +78,7 @@ public class AopTest {
}
private void registerAdvice (ExecutionContext ctx, String prefix, String postfix, boolean proceed, Pointcut pointCut, boolean cached) {
- ctx.setAdviceContext (ctx.getAdviceContext().copyWithAdvice (new AroundAdvice (ConcatAdviceFactory.createConcatExpression (prefix, postfix, proceed), pointCut, cached)));
+ ctx.setAdviceContext (ctx.getAdviceContext().copyWithAdvice (new AroundAdvice (ConcatAdviceFactory.createConcatExpression (prefix, postfix, proceed), pointCut, cached, createEmptyFdc (ctx))));
}
@SuppressWarnings("unchecked")
@@ -90,7 +90,7 @@ public class AopTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (AopTestFunctions.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
final Pointcut pointCutObject = new ExecutionPointcut ("f", Collections.EMPTY_LIST, true, new AdviceParamType (ObjectType.INSTANCE, false));
final Pointcut pointCutObjectPlus = new ExecutionPointcut ("f", Collections.EMPTY_LIST, true, new AdviceParamType (ObjectType.INSTANCE, true));
@@ -117,7 +117,7 @@ public class AopTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (AopTestFunctions.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
final Pointcut pointCutObject = new ExecutionPointcut ("f", Arrays.asList (new Pair<String, AdviceParamType> ("o", new AdviceParamType (ObjectType.INSTANCE, false))), false, null);
final Pointcut pointCutObjectPlus = new ExecutionPointcut ("f", Arrays.asList (new Pair<String, AdviceParamType> ("o", new AdviceParamType (ObjectType.INSTANCE, true))), false, null);
@@ -144,7 +144,7 @@ public class AopTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (AopTestFunctions.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
final Pointcut pointCutFirstPre = new ExecutionPointcut ("first*", Collections.EMPTY_LIST, true, new AdviceParamType (ObjectType.INSTANCE, true));
final Pointcut pointCutFirstPost = new ExecutionPointcut ("*tFunction", Collections.EMPTY_LIST, true, new AdviceParamType (ObjectType.INSTANCE, true));
@@ -185,7 +185,7 @@ public class AopTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (CounterFunction.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
fdc.register (new NamedFunction ("f", new Function () {
@@ -204,7 +204,7 @@ public class AopTest {
public boolean isCached () {
return true;
}
- }));
+ }), true);
final Pointcut pointCut = new ExecutionPointcut ("f", Collections.EMPTY_LIST, false, null);
@@ -226,8 +226,12 @@ public class AopTest {
toBeConcatenated.add (new LiteralExpression (" ", null));
toBeConcatenated.add (ConcatAdviceFactory.createProceedExpression());
- ctx.setAdviceContext (ctx.getAdviceContext().copyWithAdvice (new AroundAdvice (new ConcatExpression (toBeConcatenated, null), pointCut, cacheable)));
+ ctx.setAdviceContext (ctx.getAdviceContext().copyWithAdvice (new AroundAdvice (new ConcatExpression (toBeConcatenated, null), pointCut, cacheable, ctx.getFunctionDefContext())));
}
+
+ private FunctionDefContextInternal createEmptyFdc (ExecutionContext ctx) {
+ return new FunctionDefContextFactory (ctx.getTypesystem()).create();
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTestFunctions.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTestFunctions.java
index b8a4640..153a07c 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTestFunctions.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/aop/AopTestFunctions.java
@@ -27,15 +27,15 @@ public class AopTestFunctions {
return "second";
}
- public String f (Object o) {
+ public String f (@SuppressWarnings("unused") Object o) {
return "f(Object)";
}
- public String f (Collection<?> c) {
+ public String f (@SuppressWarnings("unused") Collection<?> c) {
return "f(Collection)";
}
- public String f(List<?> l) {
+ public String f(@SuppressWarnings("unused") List<?> l) {
return "f(List)";
}
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
index b491978..c644781 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
@@ -56,7 +56,7 @@ public class ConcatExpressionTest {
}.create();
final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
- fdc.register (myToString);
+ fdc.register (myToString, true);
final ExpressionBase expr = new ConcatExpression (Arrays.asList (createLiteral("a"), createLiteral("b")), SOURCE_POS);
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
index 79884f8..8ac3442 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
@@ -96,8 +96,7 @@ public class InitClosureExpressionTest {
public boolean isCached () {
return false;
}
-
- }));
+ }), true);
final ExecutionContext initCtx = BackendFacade.createExecutionContext (fdc, ts, true);
final ExpressionBase body = new InvocationOnObjectExpression ("myFunction", new ArrayList<ExpressionBase> (), false, SOURCE_POS);
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
index 70347d8..b9a0ad2 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
@@ -111,7 +111,7 @@ public class SwitchExpressionTest {
}.create();
final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
- fdc.register (myStringEquals);
+ fdc.register (myStringEquals, true);
final ExecutionContext ctx = createEmptyExecutionContext();
assertEquals ("defaultValue", expr.evaluate (ctx));
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
index 59088e3..a90ae33 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
@@ -36,18 +36,18 @@ public class FunctionTest {
ctx.setFunctionDefContext (fdc);
for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (CounterFunction.class, ctx.getTypesystem()))
- fdc.register (new NamedFunction (f.getName(), f));
+ fdc.register (new NamedFunction (f.getName(), f), true);
fdc.register (new NamedFunctionFactory ("myCached", true) {
public Object invoke (ExecutionContext innerCtx, Object[] params) {
return innerCtx.getFunctionDefContext().invoke (innerCtx, "nextCounterValue", new ArrayList<Object> ());
}
- }.create());
+ }.create(), true);
fdc.register (new NamedFunctionFactory ("myUncached", false) {
public Object invoke (ExecutionContext innerCtx, Object[] params) {
return innerCtx.getFunctionDefContext().invoke (innerCtx, "nextCounterValue", new ArrayList<Object> ());
}
- }.create());
+ }.create(), true);
assertEquals (0L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
assertEquals (1L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
@@ -70,7 +70,7 @@ public class FunctionTest {
final EfficientLazyString result = new EfficientLazyString ();
return EfficientLazyString.createAppendedString (result, "Hi Arno");
}
- }.create());
+ }.create(), true);
assertEquals ("Hi Arno", fdc.invoke (ctx, "myCached", new ArrayList<Object> ()).toString());
EfficientLazyString.createAppendedString ((EfficientLazyString) fdc.invoke (ctx, "myCached", new ArrayList<Object> ()), "... and something else");
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
index 88d69cc..e70288b 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
@@ -54,8 +54,8 @@ public class OverrideTest {
final ExpressionBase expr = new ConcatExpression (Arrays.asList (createLiteral (25L), createLiteral ("Abc")), SOURCE_POS);
final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
- fdc.register (myLongToString);
- fdc.register (myObjectToString);
+ fdc.register (myLongToString, true);
+ fdc.register (myObjectToString, true);
final ExecutionContext ctx = createEmptyExecutionContext();
assertEquals ("25Abc", expr.evaluate (ctx).toString());
diff --git a/tests/org.eclipse.xtend.middleend.old.test/META-INF/MANIFEST.MF b/tests/org.eclipse.xtend.middleend.old.test/META-INF/MANIFEST.MF
index 09d6c75..1cf2aef 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.xtend.middleend.old.test/META-INF/MANIFEST.MF
@@ -9,4 +9,5 @@ Require-Bundle: org.eclipse.xtend.backend,
org.eclipse.xtend,
org.eclipse.xpand,
org.eclipse.emf.mwe.core,
- org.apache.commons.logging
+ org.apache.commons.logging,
+ org.junit4
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java
index 4d68bd6..f06d101 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.eclipose.xtend.middleend.BackendTypesystemFactory;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.IssuesImpl;
import org.eclipse.emf.mwe.internal.core.WorkflowContextDefaultImpl;
@@ -23,18 +22,21 @@ import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xtend.backend.BackendFacade;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
-import org.eclipse.xtend.middleend.old.xpand.XpandBackendFacade;
-import org.eclipse.xtend.middleend.old.xpand.XpandComponent;
-import org.eclipse.xtend.middleend.old.xtend.XtendBackendFacade;
+import org.eclipse.xtend.middleend.old.XpandBackendFacade;
+import org.eclipse.xtend.middleend.old.XpandComponent;
+import org.eclipse.xtend.middleend.old.XtendBackendFacade;
import org.eclipse.xtend.typesystem.MetaModel;
+import org.junit.Test;
public class FirstAttempt {
- public static void main (String[] args) {
+ @Test
+ public void main() throws Exception {
final List<MetaModel> mms = new ArrayList<MetaModel> ();
mms.add (new JavaBeansMetaModel ());
- final CompositeTypesystem ts = BackendTypesystemFactory.createJustEmf();
+ final CompositeTypesystem ts = new CompositeTypesystem ();
+// ts.register (new EmfTypesystem ());
{
final XpandBackendFacade xp = XpandBackendFacade.createForFile ("org::eclipse::xtend::middleend::old::first::aTemplate", "iso-8859-1", mms, new ArrayList<Outlet>());
@@ -47,6 +49,7 @@ public class FirstAttempt {
final XpandComponent xwc = new XpandComponent ();
xwc.setExpand ("org::eclipse::xtend::middleend::old::first::WithFileOutput::WithFileOutput FOR toBeGreeted");
xwc.addOutlet (new Outlet (false, "iso-8859-1", null, true, "src-gen"));
+ xwc.setFileEncoding ("iso-8859-1");
final WorkflowContext wfContext = new WorkflowContextDefaultImpl ();
wfContext.set ("toBeGreeted", "Arno");