summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-27 10:29:02 (EST)
committer ahaase2008-02-27 10:29:02 (EST)
commitddc8d33c2d107259a7ff4faa2500abe4a26aabdd (patch)
tree306049ca516f3725a421399d12c67df2f56e286f
parentad6b4d7fde27a63e4741ec96a1423ce9def94e11 (diff)
downloadorg.eclipse.xpand-ddc8d33c2d107259a7ff4faa2500abe4a26aabdd.zip
org.eclipse.xpand-ddc8d33c2d107259a7ff4faa2500abe4a26aabdd.tar.gz
org.eclipse.xpand-ddc8d33c2d107259a7ff4faa2500abe4a26aabdd.tar.bz2
made the OSGi dependency of MiddleEnd creation optional
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java3
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java3
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java12
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEndFactory.java53
4 files changed, 62 insertions, 9 deletions
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
index fc033d8..7e415b9 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Set;
import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.MiddleEndFactory;
import org.eclipse.internal.xpand2.ast.Definition;
import org.eclipse.internal.xpand2.ast.Statement;
import org.eclipse.internal.xpand2.ast.Template;
@@ -260,7 +261,7 @@ public final class XpandBackendFacade {
outlets = new ArrayList<Outlet> ();
_xpandFile = OldHelper.normalizeXpandResourceName (xpandFilename);
- _middleEnd = new MiddleEnd (OldHelper.guessTypesystem (mms), createSpecificParameters (fileEncoding, mms, outlets));
+ _middleEnd = MiddleEndFactory.create (OldHelper.guessTypesystem (mms), createSpecificParameters (fileEncoding, mms, outlets));
_fileEncoding = fileEncoding;
_mms = mms;
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
index 71333d4..e2edeef 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Map;
import org.eclipose.xtend.middleend.MiddleEnd;
+import org.eclipose.xtend.middleend.MiddleEndFactory;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.xtend.parser.ParseFacade;
import org.eclipse.xtend.backend.BackendFacade;
@@ -161,7 +162,7 @@ public final class XtendBackendFacade {
_xtendFile = OldHelper.normalizeXtendResourceName (xtendFileName);
_mms = mms;
- _middleEnd = new MiddleEnd (OldHelper.guessTypesystem (mms), getSpecificParameters (fileEncoding, mms));
+ _middleEnd = MiddleEndFactory.create (OldHelper.guessTypesystem (mms), getSpecificParameters (fileEncoding, mms));
}
public FunctionDefContext getFunctionDefContext () {
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
index 66cf6b1..b96111e 100644
--- 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
@@ -11,11 +11,9 @@ Contributors:
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;
@@ -36,10 +34,10 @@ import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public class MiddleEnd {
+public final class MiddleEnd {
private static final Log _log = LogFactory.getLog (MiddleEnd.class);
- private final List<LanguageSpecificMiddleEnd> _middleEnds;
+ private final List<LanguageSpecificMiddleEnd> _languageHandlers;
private final ExecutionContext _ctx;
private final BackendTypesystem _ts;
@@ -48,14 +46,14 @@ public class MiddleEnd {
* The key must be the class implementing the LanguageSpecificMiddleEnd interface
* and contributed via the extension point.
*/
- public MiddleEnd (BackendTypesystem ts, Map<Class<?>, Object> specificParams) {
+ public MiddleEnd (BackendTypesystem ts, List<LanguageSpecificMiddleEnd> languageHandlers) {
_ctx = BackendFacade.createExecutionContext (new FunctionDefContextFactory (ts).create(), ts, false);
_ts = ts;
- _middleEnds = Activator.getInstance().getFreshMiddleEnds (this, specificParams);
+ _languageHandlers = languageHandlers;
}
private LanguageSpecificMiddleEnd findHandler (String resourceName) {
- for (LanguageSpecificMiddleEnd candidate: _middleEnds) {
+ for (LanguageSpecificMiddleEnd candidate: _languageHandlers) {
if (candidate.canHandle (resourceName)) {
_log.debug ("middle end " + candidate.getName() + " handles resource " + resourceName);
return candidate;
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEndFactory.java b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEndFactory.java
new file mode 100644
index 0000000..cde6c4a
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEndFactory.java
@@ -0,0 +1,53 @@
+/*
+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.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipose.xtend.middleend.internal.Activator;
+import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
+import org.eclipse.xtend.backend.common.BackendTypesystem;
+
+
+/**
+ * This class encapsulates the OSGi / Eclipse extension registry specific behavior and
+ * initialization code. It serves as an optional wrapper / convenience initialization
+ * code for the actual MiddleEnd class.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class MiddleEndFactory {
+ /**
+ * This method creates a MiddleEnd instance based on an explicitly provided list of handlers. It works without
+ * OSGi.
+ */
+ public static MiddleEnd create (BackendTypesystem ts, List<LanguageSpecificMiddleEnd> languageHandlers) {
+ return new MiddleEnd (ts, languageHandlers);
+ }
+
+ /**
+ * This method creates a middle end based on the handlers registered with the extension point. It relies
+ * on OSGi and makes use of the Eclipse extension registry.<br>
+ *
+ * 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 static MiddleEnd create (BackendTypesystem ts, Map<Class<?>, Object> specificParams) {
+ final List<LanguageSpecificMiddleEnd> languageHandlers = new ArrayList<LanguageSpecificMiddleEnd> ();
+ final MiddleEnd result = new MiddleEnd (ts, languageHandlers);
+
+ languageHandlers.addAll (Activator.getInstance().getFreshMiddleEnds (result, specificParams));
+ return result;
+ }
+}