summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-27 11:43:11 (EST)
committerahaase2008-02-27 11:43:11 (EST)
commit8f55867f061298291d011f2f862c99761dd5f844 (patch)
tree482b1496a0546be8038c8c3a05dd886594ef972e
parentf5df98ea29c9c86319b99925c3e93bc7efdbe57b (diff)
downloadorg.eclipse.xpand-8f55867f061298291d011f2f862c99761dd5f844.zip
org.eclipse.xpand-8f55867f061298291d011f2f862c99761dd5f844.tar.gz
org.eclipse.xpand-8f55867f061298291d011f2f862c99761dd5f844.tar.bz2
bugfix: removed cyclic dependency from the middle end initialization
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java9
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java11
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXpandRegistryFactory.java5
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/plugin/OldXtendRegistryFactory.java5
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEnd.java3
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/MiddleEndFactory.java7
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/internal/Activator.java28
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEnd.java7
-rw-r--r--plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/plugins/LanguageSpecificMiddleEndFactory.java4
9 files changed, 44 insertions, 35 deletions
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
index 59babf1..1eeb7f6 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xpand/OldXpandRegistry.java
@@ -42,8 +42,8 @@ import org.eclipse.xtend.middleend.old.internal.xtendlib.XtendLibContributor;
*/
public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
private final XpandExecutionContext _ctx;
- private final BackendTypesystem _ts;
- private final MiddleEnd _middleEnd;
+ private BackendTypesystem _ts;
+ private MiddleEnd _middleEnd;
private final Cache<String, FunctionDefContextInternal> _functionDefContexts = new Cache<String, FunctionDefContextInternal> () {
@Override
@@ -63,11 +63,14 @@ public final class OldXpandRegistry implements LanguageSpecificMiddleEnd {
}
- public OldXpandRegistry (MiddleEnd middleEnd, Object specificData) {
+ public OldXpandRegistry (Object specificData) {
if (specificData == null)
throw new IllegalArgumentException (getName() + " middle end is not initialized - will not contribute");
_ctx = (XpandExecutionContext) specificData;
+ }
+
+ public void setMiddleEnd (MiddleEnd middleEnd) {
_middleEnd = middleEnd;
_ts = middleEnd.getTypesystem();
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java
index 262f7ae..a783e17 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/internal/xtend/OldXtendRegistry.java
@@ -47,7 +47,7 @@ public final class OldXtendRegistry implements LanguageSpecificMiddleEnd {
private final ExecutionContext _ctx;
@SuppressWarnings("unused")
- private final MiddleEnd _middleEnd;
+ private MiddleEnd _middleEnd;
private BackendTypesystem _ts;
@@ -81,15 +81,18 @@ public final class OldXtendRegistry implements LanguageSpecificMiddleEnd {
/**
* the specificData field contains an ExecutionContext initialized with the MetaModels and the file encoding
*/
- public OldXtendRegistry (MiddleEnd middleEnd, Object specificData) {
+ public OldXtendRegistry (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;
}
+ public void setMiddleEnd (MiddleEnd middleEnd) {
+ _middleEnd = middleEnd;
+ _ts = middleEnd.getTypesystem();
+ }
+
private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldHelper.normalizeXtendResourceName (xtendName));
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
index c5d0b22..c34cf14 100644
--- 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
@@ -10,7 +10,6 @@ Contributors:
*/
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;
@@ -22,8 +21,8 @@ import org.eclipse.xtend.middleend.old.internal.xpand.OldXpandRegistry;
*/
public final class OldXpandRegistryFactory implements LanguageSpecificMiddleEndFactory {
- public LanguageSpecificMiddleEnd create (MiddleEnd middleEnd, Object specificData) {
- return new OldXpandRegistry (middleEnd, specificData);
+ public LanguageSpecificMiddleEnd create (Object specificData) {
+ return new OldXpandRegistry (specificData);
}
public String getName () {
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
index 180c6de..f75d3b9 100644
--- 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
@@ -10,7 +10,6 @@ Contributors:
*/
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;
@@ -22,8 +21,8 @@ import org.eclipse.xtend.middleend.old.internal.xtend.OldXtendRegistry;
*/
public class OldXtendRegistryFactory implements LanguageSpecificMiddleEndFactory {
- public LanguageSpecificMiddleEnd create (MiddleEnd middleEnd, Object specificData) {
- return new OldXtendRegistry (middleEnd, specificData);
+ public LanguageSpecificMiddleEnd create (Object specificData) {
+ return new OldXtendRegistry (specificData);
}
public String getName () {
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 b96111e..c7ba558 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
@@ -50,6 +50,9 @@ public final class MiddleEnd {
_ctx = BackendFacade.createExecutionContext (new FunctionDefContextFactory (ts).create(), ts, false);
_ts = ts;
_languageHandlers = languageHandlers;
+
+ for (LanguageSpecificMiddleEnd handler: languageHandlers)
+ handler.setMiddleEnd (this);
}
private LanguageSpecificMiddleEnd findHandler (String resourceName) {
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
index cde6c4a..b2679ef 100644
--- 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
@@ -10,7 +10,6 @@ Contributors:
*/
package org.eclipose.xtend.middleend;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -44,10 +43,6 @@ public final class MiddleEndFactory {
* 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;
+ return new MiddleEnd (ts, Activator.getInstance().getFreshMiddleEnds (specificParams));
}
}
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
index 143b6ea..bea98d8 100644
--- 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
@@ -18,7 +18,6 @@ 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.IConfigurationElement;
@@ -40,21 +39,18 @@ public class Activator implements BundleActivator {
return _instance;
}
- private final List<LanguageSpecificMiddleEndFactory> _middleEndContributions = new ArrayList<LanguageSpecificMiddleEndFactory>();
-
- private boolean _isInitialized;
+ private final List<LanguageSpecificMiddleEndFactory> _middleEndContributions = new ArrayList<LanguageSpecificMiddleEndFactory> ();
+ private boolean _isInitialized = false;
- public List<LanguageSpecificMiddleEnd> getFreshMiddleEnds (MiddleEnd middleEnd, Map<Class<?>, Object> specificParams) {
- if (!_isInitialized) {
- init();
- _isInitialized = true;
- }
+ public List<LanguageSpecificMiddleEnd> getFreshMiddleEnds (Map<Class<?>, Object> specificParams) {
+ init ();
+
final List<LanguageSpecificMiddleEnd> result = new ArrayList<LanguageSpecificMiddleEnd>();
for (LanguageSpecificMiddleEndFactory factory: _middleEndContributions) {
try {
- result.add (factory.create (middleEnd, specificParams.get (factory.getClass())));
+ result.add (factory.create (specificParams.get (factory.getClass())));
}
catch (IllegalArgumentException exc) {
// this is the official way for an implementation to withdraw from the pool for this call
@@ -66,15 +62,19 @@ public class Activator implements BundleActivator {
}
public void start (BundleContext context) throws Exception {
- _isInitialized = false;
+ //TODO Bernd: implement error handling and logging to be both robust and independent of Eclipse
+
+ _isInitialized = false;
_instance = this;
}
private void init () {
+ if (_isInitialized)
+ return;
+
+ _isInitialized = true;
_middleEndContributions.clear ();
- //TODO Bernd: implement error handling and logging to be both robust and independent of Eclipse
- _log.info ("Initializing Modeling Middle End - the following middle ends are registered:");
try {
final IConfigurationElement[] confEl = RegistryFactory.getRegistry().getConfigurationElementsFor ("org.eclipse.xtend.middleend.MiddleEnd");
@@ -93,11 +93,13 @@ public class Activator implements BundleActivator {
}
});
+ _log.info ("Activating Eclipse Modeling Middle End - the following middle ends are registered:");
for (LanguageSpecificMiddleEndFactory factory: _middleEndContributions)
_log.info (" " + factory.getName());
}
public void stop (BundleContext context) throws Exception {
_instance = null;
+ _middleEndContributions.clear();
}
}
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
index 5496e40..351cd17 100644
--- 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
@@ -12,6 +12,7 @@ package org.eclipose.xtend.middleend.plugins;
import java.util.List;
+import org.eclipose.xtend.middleend.MiddleEnd;
import org.eclipse.xtend.backend.aop.AroundAdvice;
import org.eclipse.xtend.backend.common.FunctionDefContext;
@@ -23,6 +24,12 @@ import org.eclipse.xtend.backend.common.FunctionDefContext;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public interface LanguageSpecificMiddleEnd {
+ /**
+ * This method is used to break the circular dependency between MiddleEnd and the
+ * language specific handlers. It is called by the MiddleEnd on creation.
+ */
+ void setMiddleEnd (MiddleEnd middleEnd);
+
String getName ();
/**
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
index d9d7cc9..feb6915 100644
--- 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
@@ -10,8 +10,6 @@ Contributors:
*/
package org.eclipose.xtend.middleend.plugins;
-import org.eclipose.xtend.middleend.MiddleEnd;
-
/**
* This interface is the common abstraction through which all handlers for different
@@ -46,5 +44,5 @@ public interface LanguageSpecificMiddleEndFactory {
* 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);
+ LanguageSpecificMiddleEnd create (Object specificData);
}