-
Notifications
You must be signed in to change notification settings - Fork 317
/
TestlanguagesActivator.java
117 lines (101 loc) · 4.71 KB
/
TestlanguagesActivator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
* Copyright (c) 2011, 2024 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.xbase.testlanguages.ui.internal;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.Collections;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.shared.SharedStateModule;
import org.eclipse.xtext.util.Modules2;
import org.eclipse.xtext.xbase.testlanguages.ContentAssistFragmentTestLangRuntimeModule;
import org.eclipse.xtext.xbase.testlanguages.XImportSectionTestLangRuntimeModule;
import org.eclipse.xtext.xbase.testlanguages.bug462047.Bug462047LangRuntimeModule;
import org.eclipse.xtext.xbase.testlanguages.bug462047.ui.Bug462047LangUiModule;
import org.eclipse.xtext.xbase.testlanguages.ui.ContentAssistFragmentTestLangUiModule;
import org.eclipse.xtext.xbase.testlanguages.ui.XImportSectionTestLangUiModule;
import org.osgi.framework.BundleContext;
/**
* This class was generated. Customizations should only happen in a newly
* introduced subclass.
*/
public class TestlanguagesActivator extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.eclipse.xtext.xbase.testlanguages.ui";
public static final String ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_XIMPORTSECTIONTESTLANG = "org.eclipse.xtext.xbase.testlanguages.XImportSectionTestLang";
public static final String ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_CONTENTASSISTFRAGMENTTESTLANG = "org.eclipse.xtext.xbase.testlanguages.ContentAssistFragmentTestLang";
public static final String ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_BUG462047_BUG462047LANG = "org.eclipse.xtext.xbase.testlanguages.bug462047.Bug462047Lang";
private static final Logger logger = Logger.getLogger(TestlanguagesActivator.class);
private static TestlanguagesActivator INSTANCE;
private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
INSTANCE = this;
}
@Override
public void stop(BundleContext context) throws Exception {
injectors.clear();
INSTANCE = null;
super.stop(context);
}
public static TestlanguagesActivator getInstance() {
return INSTANCE;
}
public Injector getInjector(String language) {
synchronized (injectors) {
Injector injector = injectors.get(language);
if (injector == null) {
injectors.put(language, injector = createInjector(language));
}
return injector;
}
}
protected Injector createInjector(String language) {
try {
com.google.inject.Module runtimeModule = getRuntimeModule(language);
com.google.inject.Module sharedStateModule = getSharedStateModule();
com.google.inject.Module uiModule = getUiModule(language);
com.google.inject.Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
return Guice.createInjector(mergedModule);
} catch (Exception e) {
logger.error("Failed to create injector for " + language);
logger.error(e.getMessage(), e);
throw new RuntimeException("Failed to create injector for " + language, e);
}
}
protected com.google.inject.Module getRuntimeModule(String grammar) {
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_XIMPORTSECTIONTESTLANG.equals(grammar)) {
return new XImportSectionTestLangRuntimeModule();
}
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_CONTENTASSISTFRAGMENTTESTLANG.equals(grammar)) {
return new ContentAssistFragmentTestLangRuntimeModule();
}
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_BUG462047_BUG462047LANG.equals(grammar)) {
return new Bug462047LangRuntimeModule();
}
throw new IllegalArgumentException(grammar);
}
protected com.google.inject.Module getUiModule(String grammar) {
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_XIMPORTSECTIONTESTLANG.equals(grammar)) {
return new XImportSectionTestLangUiModule(this);
}
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_CONTENTASSISTFRAGMENTTESTLANG.equals(grammar)) {
return new ContentAssistFragmentTestLangUiModule(this);
}
if (ORG_ECLIPSE_XTEXT_XBASE_TESTLANGUAGES_BUG462047_BUG462047LANG.equals(grammar)) {
return new Bug462047LangUiModule(this);
}
throw new IllegalArgumentException(grammar);
}
protected com.google.inject.Module getSharedStateModule() {
return new SharedStateModule();
}
}