Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2018-09-28 08:37:35 +0000
committerJan Belle2018-09-28 11:52:11 +0000
commitcb1b76052fbc2f85f4db45a3caf08cdf96b5b502 (patch)
treed7abafb363608ab8635089190d52c5977e2987de /plugins/org.eclipse.etrice.core.room/src
parentf8f82d046d2b781b44af7c418e1d30c12e329e5b (diff)
downloadorg.eclipse.etrice-cb1b76052fbc2f85f4db45a3caf08cdf96b5b502.tar.gz
org.eclipse.etrice-cb1b76052fbc2f85f4db45a3caf08cdf96b5b502.tar.xz
org.eclipse.etrice-cb1b76052fbc2f85f4db45a3caf08cdf96b5b502.zip
[core] Avoid repeated injector creation
* Create custom validator extensions using dependeny injection. * Add factories for generator model builders. Change-Id: I8d72e336ab981c0c218f17aca9d38688c46ac3fe
Diffstat (limited to 'plugins/org.eclipse.etrice.core.room/src')
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java19
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java24
2 files changed, 19 insertions, 24 deletions
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java
deleted file mode 100644
index 6144705cf..000000000
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.eclipse.etrice.core;
-
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.etrice.core.validation.ValidatorExtensionManager;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-public class RoomActivator extends Plugin implements BundleActivator {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
-
- ValidatorExtensionManager.Registry.getInstance().loadValidatorExtensions();
- }
-}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
index aa2d33069..074ad5034 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.EMFPlugin;
@@ -37,6 +36,10 @@ import org.eclipse.xtext.validation.Check;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.CheckType;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+import org.osgi.framework.Bundle;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
/**
* Custom validator manager for room language, that provides registration via an
@@ -97,7 +100,7 @@ public class ValidatorExtensionManager extends CustomValidatorManager {
&& Platform.getExtensionRegistry().getExtensionPoint(IVALIDATOR_ID) != null;
}
- public void loadValidatorExtensions() {
+ public void loadValidatorExtensions(Injector injector) {
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(IVALIDATOR_ID);
// we use parent-package.class-name as key in our tables
@@ -120,7 +123,11 @@ public class ValidatorExtensionManager extends CustomValidatorManager {
// now we add each extension to our maps
for (IConfigurationElement e : config) {
try {
- final Object ext = e.createExecutableExtension("class");
+ final String extContributor = e.getContributor().getName();
+ final Bundle extBundle = Platform.getBundle(extContributor);
+ final String extClassName = e.getAttribute("class");
+ final Class<?> extClass = extBundle.loadClass(extClassName);
+ final Object ext = injector.getInstance(extClass);
if (ext instanceof ICustomValidator) {
ICustomValidator validator = (ICustomValidator) ext;
infos.add(new ValidatorInfo(validator, e.getName() + ValidatorInfo.SEP
@@ -148,8 +155,8 @@ public class ValidatorExtensionManager extends CustomValidatorManager {
System.out.println("ValidatorExtensionManager: unexpected extension");
}
}
- catch (CoreException ex) {
- System.out.println(ex.getMessage());
+ catch (ClassNotFoundException ex) {
+ System.out.println(ex.toString());
}
}
}
@@ -255,6 +262,13 @@ public class ValidatorExtensionManager extends CustomValidatorManager {
isRegistryAvailable = Registry.isAvailable();
}
+ @Inject
+ public void registerExtensionValidators(Injector injector) {
+ if(isRegistryAvailable) {
+ Registry.getInstance().loadValidatorExtensions(injector);
+ }
+ }
+
@Check
public void checkObject(EObject object) {
if (isRegistryAvailable) {

Back to the top