Search in sources :

Example 6 with InjectionPlace

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());
}
Also used : LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) THashMap(gnu.trove.THashMap) PsiElement(com.intellij.psi.PsiElement) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) Element(org.jdom.Element) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 7 with InjectionPlace

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 ");
    }
}
Also used : InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace)

Example 8 with InjectionPlace

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()]));
}
Also used : ArrayList(java.util.ArrayList) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) PsiElement(com.intellij.psi.PsiElement)

Aggregations

InjectionPlace (org.intellij.plugins.intelliLang.inject.config.InjectionPlace)8 BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)4 PsiElement (com.intellij.psi.PsiElement)2 THashMap (gnu.trove.THashMap)2 Pattern (java.util.regex.Pattern)2 LanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport)2 MethodParameterInjection (org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection)2 ElementPattern (com.intellij.patterns.ElementPattern)1 PsiCompiledElement (com.intellij.psi.PsiCompiledElement)1 THashSet (gnu.trove.THashSet)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Configuration (org.intellij.plugins.intelliLang.Configuration)1 Element (org.jdom.Element)1