use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class Configuration method loadState.
@Override
public void loadState(final Element element) {
myInjections.clear();
List<Element> injectionElements = element.getChildren("injection");
if (!injectionElements.isEmpty()) {
final Map<String, LanguageInjectionSupport> supports = new THashMap<>();
for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
supports.put(support.getId(), support);
}
for (Element child : injectionElements) {
final String key = child.getAttributeValue("injector-id");
final LanguageInjectionSupport support = supports.get(key);
final BaseInjection injection = support == null ? new BaseInjection(key) : support.createInjection(child);
injection.loadState(child);
InjectionPlace[] places = dropKnownInvalidPlaces(injection.getInjectionPlaces());
if (places != null) {
// not all places were removed
injection.setInjectionPlaces(places);
myInjections.get(key).add(injection);
}
}
}
importPlaces(getDefaultInjections());
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class Configuration method loadDefaultInjections.
private static List<BaseInjection> loadDefaultInjections() {
final List<Configuration> cfgList = new ArrayList<>();
final Set<Object> visited = new THashSet<>();
for (LanguageInjectionConfigBean configBean : Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) {
PluginDescriptor descriptor = configBean.getPluginDescriptor();
final ClassLoader loader = descriptor.getPluginClassLoader();
try {
final Enumeration<URL> enumeration = loader.getResources(configBean.getConfigUrl());
if (enumeration == null || !enumeration.hasMoreElements()) {
LOG.warn(descriptor.getPluginId() + ": " + configBean.getConfigUrl() + " was not found");
} else {
while (enumeration.hasMoreElements()) {
URL url = enumeration.nextElement();
// for DEBUG mode
if (!visited.add(url.getFile()))
continue;
InputStream stream = null;
try {
stream = url.openStream();
cfgList.add(load(stream));
} catch (Exception e) {
LOG.warn(e);
} finally {
if (stream != null) {
stream.close();
}
}
}
}
} catch (Exception e) {
LOG.warn(e);
}
}
final List<BaseInjection> defaultInjections = new ArrayList<>();
for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
for (Configuration cfg : cfgList) {
final List<BaseInjection> imported = cfg.getInjections(supportId);
defaultInjections.addAll(imported);
}
}
return defaultInjections;
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class Configuration method getState.
protected Element getState(Element element) {
Comparator<BaseInjection> comparator = (o1, o2) -> {
int rc = Comparing.compare(o1.getDisplayName(), o2.getDisplayName());
if (rc != 0)
return rc;
return ContainerUtil.compareLexicographically(Arrays.asList(o1.getInjectionPlaces()), Arrays.asList(o2.getInjectionPlaces()), (o11, o22) -> {
if (o11.isEnabled() && !o22.isEnabled())
return -1;
if (!o11.isEnabled() && o22.isEnabled())
return 1;
return Comparing.compare(o11.getElementPattern().toString(), o22.getElementPattern().toString());
});
};
for (String key : ContainerUtil.newTreeSet(myInjections.keySet())) {
Set<BaseInjection> injections = ContainerUtil.newHashSet(myInjections.get(key));
injections.removeAll(getDefaultInjections());
for (BaseInjection injection : ContainerUtil.sorted(injections, comparator)) {
element.addContent(injection.getState());
}
}
return element;
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class InjectionsSettingsUI method doImportAction.
private void doImportAction(final DataContext dataContext) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, false) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType() == StdFileTypes.XML;
}
};
descriptor.setDescription("Please select the configuration file (usually named IntelliLang.xml) to import.");
descriptor.setTitle("Import Configuration");
descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, LangDataKeys.MODULE.getData(dataContext));
final SplitterProportionsData splitterData = new SplitterProportionsDataImpl();
splitterData.externalizeFromDimensionService("IntelliLang.ImportSettingsKey.SplitterProportions");
final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
if (file == null)
return;
try {
final Configuration cfg = Configuration.load(file.getInputStream());
if (cfg == null) {
Messages.showWarningDialog(myProject, "The selected file does not contain any importable configuration.", "Nothing to Import");
return;
}
final CfgInfo info = getDefaultCfgInfo();
final Map<String, Set<InjInfo>> currentMap = ContainerUtil.classify(info.injectionInfos.iterator(), new Convertor<InjInfo, String>() {
public String convert(final InjInfo o) {
return o.injection.getSupportId();
}
});
final List<BaseInjection> originalInjections = new ArrayList<>();
final List<BaseInjection> newInjections = new ArrayList<>();
for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
ArrayList<InjInfo> list = new ArrayList<>(ObjectUtils.notNull(currentMap.get(supportId), Collections.<InjInfo>emptyList()));
final List<BaseInjection> currentInjections = getInjectionList(list);
final List<BaseInjection> importingInjections = cfg.getInjections(supportId);
if (currentInjections == null) {
newInjections.addAll(importingInjections);
} else {
Configuration.importInjections(currentInjections, importingInjections, originalInjections, newInjections);
}
}
info.replace(originalInjections, newInjections);
myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
final int n = newInjections.size();
if (n > 1) {
Messages.showInfoMessage(myProject, n + " entries have been successfully imported", "Import Successful");
} else if (n == 1) {
Messages.showInfoMessage(myProject, "One entry has been successfully imported", "Import Successful");
} else {
Messages.showInfoMessage(myProject, "No new entries have been imported", "Import");
}
} catch (Exception ex) {
Configuration.LOG.error(ex);
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Import Failed");
}
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class AbstractLanguageInjectionSupport method createDefaultEditAction.
public static AnAction createDefaultEditAction(final Project project, final Factory<BaseInjection> producer) {
return new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final BaseInjection originalInjection = producer.create();
final BaseInjection newInjection = showDefaultInjectionUI(project, originalInjection.copy());
if (newInjection != null) {
originalInjection.copyFrom(newInjection);
}
}
};
}
Aggregations