use of org.intellij.plugins.intelliLang.inject.config.InjectionPlace 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.InjectionPlace in project intellij-community by JetBrains.
the class InjectionsSettingsUI method updateCountLabel.
private void updateCountLabel() {
int placesCount = 0;
int enablePlacesCount = 0;
final List<InjInfo> items = myInjectionsTable.getListTableModel().getItems();
if (!items.isEmpty()) {
for (InjInfo injection : items) {
for (InjectionPlace place : injection.injection.getInjectionPlaces()) {
placesCount++;
if (place.isEnabled())
enablePlacesCount++;
}
}
myCountLabel.setText(items.size() + " injection" + (items.size() > 1 ? "s" : "") + " (" + enablePlacesCount + " of " + placesCount + " place" + (placesCount > 1 ? "s" : "") + " enabled) ");
} else {
myCountLabel.setText("no injections configured ");
}
}
use of org.intellij.plugins.intelliLang.inject.config.InjectionPlace in project intellij-community by JetBrains.
the class BaseInjectionPanel method apply.
protected void apply(BaseInjection other) {
final String displayName = myNameTextField.getText();
if (StringUtil.isEmpty(displayName)) {
throw new IllegalArgumentException("Display name should not be empty");
}
other.setDisplayName(displayName);
boolean enabled = true;
final StringBuilder sb = new StringBuilder();
final ArrayList<InjectionPlace> places = new ArrayList<>();
for (String s : myTextArea.getText().split("\\s*\n\\s*")) {
final boolean nextEnabled;
if (s.startsWith("+")) {
nextEnabled = true;
s = s.substring(1).trim();
} else if (s.startsWith("-")) {
nextEnabled = false;
s = s.substring(1).trim();
} else {
sb.append(s.trim());
continue;
}
if (sb.length() > 0) {
final String text = sb.toString();
places.add(new InjectionPlace(myHelper.compileElementPattern(text), enabled));
sb.setLength(0);
}
sb.append(s);
enabled = nextEnabled;
}
if (sb.length() > 0) {
final String text = sb.toString();
places.add(new InjectionPlace(myHelper.compileElementPattern(text), enabled));
}
for (InjectionPlace place : places) {
ElementPattern<PsiElement> pattern = place.getElementPattern();
if (pattern instanceof PatternCompilerImpl.LazyPresentablePattern) {
try {
((PatternCompilerImpl.LazyPresentablePattern) pattern).compile();
} catch (Throwable ex) {
throw (RuntimeException) new IllegalArgumentException("Pattern failed to compile:").initCause(ex);
}
}
}
other.setInjectionPlaces(places.toArray(new InjectionPlace[places.size()]));
}
Aggregations