Search in sources :

Example 1 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class GrConcatenationInjector method processInPlace.

public static void processInPlace(MultiHostRegistrar registrar, GrLiteral literal) {
    BaseInjection injection = findLanguageParams(literal);
    if (injection != null) {
        LanguageInjectionSupport support = InjectorUtils.findInjectionSupport(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID);
        InjectorUtils.registerInjectionSimple(literal, injection, support, registrar);
    }
}
Also used : LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) JavaLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 2 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class InjectionsSettingsUI method createActions.

private void createActions(ToolbarDecorator decorator) {
    final Consumer<BaseInjection> consumer = injection -> addInjection(injection);
    final Factory<BaseInjection> producer = (NullableFactory<BaseInjection>) () -> {
        final InjInfo info = getSelectedInjection();
        return info == null ? null : info.injection;
    };
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
        ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
        final AnAction action = support.createEditAction(myProject, producer);
        myEditActions.put(support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action);
        mySupports.put(support.getId(), support);
    }
    Collections.sort(myAddActions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
    decorator.disableUpDownActions();
    decorator.setAddActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return !myAddActions.isEmpty();
        }
    });
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            performAdd(button);
        }
    });
    decorator.setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            boolean enabled = false;
            for (InjInfo info : getSelectedInjections()) {
                if (!info.bundled) {
                    enabled = true;
                    break;
                }
            }
            return enabled;
        }
    });
    decorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            performRemove();
        }
    });
    decorator.setEditActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            AnAction edit = getEditAction();
            if (edit != null)
                edit.update(e);
            return edit != null && edit.getTemplatePresentation().isEnabled();
        }
    });
    decorator.setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            performEditAction();
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {

        @Override
        public boolean isEnabled() {
            return getEditAction() != null;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            final InjInfo injection = getSelectedInjection();
            if (injection != null) {
                addInjection(injection.injection.copy());
            //performEditAction(e);
            }
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            performSelectedInjectionsEnabled(true);
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            performSelectedInjectionsEnabled(false);
        }
    });
    new DumbAwareAction("Toggle") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable);
            e.getPresentation().setEnabled(supply == null || !supply.isPopupActive());
        }

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            performToggleAction();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable);
    if (myInfos.length > 1) {
        AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) {

            {
                addCustomUpdater(new AnActionButtonUpdater() {

                    @Override
                    public boolean isEnabled(AnActionEvent e) {
                        CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
                        e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope");
                        return cfg != null;
                    }
                });
            }

            @Override
            public void actionPerformed(@NotNull final AnActionEvent e) {
                final List<InjInfo> injections = getSelectedInjections();
                final CfgInfo cfg = getTargetCfgInfo(injections);
                if (cfg == null)
                    return;
                for (InjInfo info : injections) {
                    if (info.cfgInfo == cfg)
                        continue;
                    if (info.bundled)
                        continue;
                    info.cfgInfo.injectionInfos.remove(info);
                    cfg.addInjection(info.injection);
                }
                final int[] selectedRows = myInjectionsTable.getSelectedRows();
                myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
                TableUtil.selectRows(myInjectionsTable, selectedRows);
            }

            @Nullable
            private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
                CfgInfo cfg = null;
                for (InjInfo info : injections) {
                    if (info.bundled) {
                        continue;
                    }
                    if (cfg == null)
                        cfg = info.cfgInfo;
                    else if (cfg != info.cfgInfo)
                        return info.cfgInfo;
                }
                if (cfg == null)
                    return null;
                for (CfgInfo info : myInfos) {
                    if (info != cfg)
                        return info;
                }
                throw new AssertionError();
            }
        };
        shareAction.setShortcut(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)));
        decorator.addExtraAction(shareAction);
    }
    decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            doImportAction(e.getDataContext());
            updateCountLabel();
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
            final VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject).save(null, null);
            if (wrapper == null)
                return;
            final Configuration configuration = new Configuration();
            configuration.setInjections(injections);
            try {
                JdomKt.write(configuration.getState(), wrapper.getFile().toPath());
            } catch (IOException ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
            }
        }

        @Override
        public boolean isEnabled() {
            return !getSelectedInjections().isEmpty();
        }
    });
}
Also used : Language(com.intellij.lang.Language) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) ColumnInfo(com.intellij.util.ui.ColumnInfo) THashSet(gnu.trove.THashSet) TableCellRenderer(javax.swing.table.TableCellRenderer) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) Nls(org.jetbrains.annotations.Nls) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) NullableFactory(com.intellij.openapi.util.NullableFactory) TableView(com.intellij.ui.table.TableView) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) Configurable(com.intellij.openapi.options.Configurable) ReferenceInjector(com.intellij.psi.injection.ReferenceInjector) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) InputEvent(java.awt.event.InputEvent) java.util(java.util) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) ContainerUtil(com.intellij.util.containers.ContainerUtil) Comparing(com.intellij.openapi.util.Comparing) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) DataManager(com.intellij.ide.DataManager) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) Convertor(com.intellij.util.containers.Convertor) IOException(java.io.IOException) FileType(com.intellij.openapi.fileTypes.FileType) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) NullableFactory(com.intellij.openapi.util.NullableFactory) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) List(java.util.List) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) IOException(java.io.IOException) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 3 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class AbstractLanguageInjectionSupport method createDefaultAddAction.

public static AnAction createDefaultAddAction(final Project project, final Consumer<BaseInjection> consumer, final AbstractLanguageInjectionSupport support) {
    final String supportTitle = StringUtil.capitalize(support.getId());
    Icon icon = FileTypeManager.getInstance().getFileTypeByExtension(support.getId()).getIcon();
    return new AnAction("Generic " + supportTitle, null, icon) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final BaseInjection injection = new BaseInjection(support.getId());
            injection.setDisplayName("New " + supportTitle + " Injection");
            final BaseInjection newInjection = showDefaultInjectionUI(project, injection);
            if (newInjection != null) {
                consumer.consume(injection);
            }
        }
    };
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 4 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class ConcatenationInjector method getLanguagesToInject.

public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull PsiElement... operands) {
    if (operands.length == 0)
        return;
    boolean hasLiteral = false;
    InjectedLanguage tempInjectedLanguage = null;
    PsiFile containingFile = null;
    for (PsiElement operand : operands) {
        if (PsiUtilEx.isStringOrCharacterLiteral(operand)) {
            hasLiteral = true;
            if (containingFile == null) {
                containingFile = operands[0].getContainingFile();
            }
            tempInjectedLanguage = myTemporaryPlacesRegistry.getLanguageFor((PsiLanguageInjectionHost) operand, containingFile);
            if (tempInjectedLanguage != null)
                break;
        }
    }
    if (!hasLiteral)
        return;
    final Language tempLanguage = tempInjectedLanguage == null ? null : tempInjectedLanguage.getLanguage();
    final PsiFile finalContainingFile = containingFile;
    InjectionProcessor injectionProcessor = new InjectionProcessor(myConfiguration, mySupport, operands) {

        @Override
        protected void processInjection(Language language, List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list, boolean settingsAvailable, boolean unparsable) {
            InjectorUtils.registerInjection(language, list, finalContainingFile, registrar);
            InjectorUtils.registerSupport(mySupport, settingsAvailable, registrar);
            InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable ? Boolean.TRUE : null);
        }

        @Override
        protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) {
            if (methodName == null)
                return false;
            if (getAnnotatedElementsValue().contains(methodName)) {
                return true;
            }
            if (!annoOnly && getXmlAnnotatedElementsValue().contains(methodName)) {
                return true;
            }
            return false;
        }
    };
    if (tempLanguage != null) {
        BaseInjection baseInjection = new BaseInjection(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID);
        baseInjection.setInjectedLanguageId(tempInjectedLanguage.getID());
        injectionProcessor.processInjectionInner(baseInjection, false);
        InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage);
    } else {
        injectionProcessor.processInjections();
    }
}
Also used : InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) Language(com.intellij.lang.Language) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) TextRange(com.intellij.openapi.util.TextRange) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 5 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class JavaLanguageInjectionSupport method showInjectionUI.

private static BaseInjection showInjectionUI(final Project project, final MethodParameterInjection methodParameterInjection) {
    final AbstractInjectionPanel panel = new MethodParameterPanel(methodParameterInjection, project);
    panel.reset();
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setHelpId("reference.settings.injection.language.injection.settings.java.parameter");
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(panel.getComponent());
    builder.setTitle(EditInjectionSettingsAction.EDIT_INJECTION_TITLE);
    builder.setOkOperation(() -> {
        panel.apply();
        builder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
    });
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        return new BaseInjection(methodParameterInjection.getSupportId()).copyFrom(methodParameterInjection);
    }
    return null;
}
Also used : MethodParameterPanel(org.intellij.plugins.intelliLang.inject.config.ui.MethodParameterPanel) AbstractInjectionPanel(org.intellij.plugins.intelliLang.inject.config.ui.AbstractInjectionPanel) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Aggregations

BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)23 InjectionPlace (org.intellij.plugins.intelliLang.inject.config.InjectionPlace)7 Nullable (org.jetbrains.annotations.Nullable)7 Language (com.intellij.lang.Language)6 Project (com.intellij.openapi.project.Project)6 LanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport)6 InjectorUtils (org.intellij.plugins.intelliLang.inject.InjectorUtils)5 NotNull (org.jetbrains.annotations.NotNull)5 AnAction (com.intellij.openapi.actionSystem.AnAction)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 THashSet (gnu.trove.THashSet)4 Pair (com.intellij.openapi.util.Pair)3 PsiElement (com.intellij.psi.PsiElement)3 IOException (java.io.IOException)3 Configuration (org.intellij.plugins.intelliLang.Configuration)3 MethodParameterInjection (org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection)3 Element (org.jdom.Element)3 NonNls (org.jetbrains.annotations.NonNls)3 SplitterProportionsDataImpl (com.intellij.ide.ui.SplitterProportionsDataImpl)2