From 8192b229f7ee0b7c31ff1597caba83baae579817 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 20 Aug 2009 19:46:00 +0400 Subject: [PATCH] import/merge injections & new default config --- .../src/LanguageInjectionConfiguration.xml | 1058 ++++++-------------- .../plugins/intelliLang/Configuration.java | 72 +- .../plugins/intelliLang/InjectionsSettingsUI.java | 82 +- 3 files changed, 446 insertions(+), 766 deletions(-) rewrite plugins/IntelliLang/src/LanguageInjectionConfiguration.xml (90%) diff --git a/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml b/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml dissimilarity index 90% index 2f1de1e6d9..2a291d4394 100644 --- a/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml +++ b/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml @@ -1,735 +1,323 @@ - - - - Connection (java.sql) - - - - - - - - - - - - - Statement (java.sql) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Connection (java.sql) + + + + + + + + + + + + + Statement (java.sql) + + + + + + + + + + + + + BatchSqlUpdate (org.springframework.jdbc.object) + + + + + + Connection (java.sql) + + + + + + + + + + + + + EntityManager.createNativeQuery (javax.persistence) + + + + EntityManager.createQuery (javax.persistence) + + + + HibernateOperations (org.springframework.orm.hibernate) + + + + + + + + HibernateOperations (org.springframework.orm.hibernate3) + + + + + + + + + + + + + + + JdbcOperations (org.springframework.jdbc.core) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JpaOperations (org.springframework.orm.jpa) + + + + + + MappingSqlQuery.MappingSqlQuery (org.springframework.jdbc.object) + + + + MappingSqlQueryWithParameters.MappingSqlQueryWithParameters (org.springframework.jdbc.object) + + + + NamedNativeQuery.query (javax.persistence) + + + + NamedQuery.query (javax.persistence) + + + + Node.createXPath (org.dom4j) + + + + Node.selectNodes (org.dom4j) + + + + Node.selectSingleNode (org.dom4j) + + + + Path.value (javax.ws.rs) + [^:]*:[\s]*([^\}]*) + + + + Pattern (java.util.regex) + + + + + + Pattern.regexp (javax.validation.constraints) + + + + RdbmsOperation.setSql (org.springframework.jdbc.object) + + + + Session.createQuery (org.hibernate) + + + + Session.createSQLQuery (org.hibernate) + + + + SimpleJdbcOperations (org.springframework.jdbc.core.simple) + ", "java.lang.Object...").definedInClass("org.springframework.jdbc.core.simple.SimpleJdbcOperations"))]]> + + + + + ", "java.lang.Object...").definedInClass("org.springframework.jdbc.core.simple.SimpleJdbcOperations"))]]> + ", "java.lang.Object...").definedInClass("org.springframework.jdbc.core.simple.SimpleJdbcOperations"))]]> + + + + SqlCall.SqlCall (org.springframework.jdbc.object) + + + + SqlFunction (org.springframework.jdbc.object) + + + + + + SqlOperation.newPreparedStatementCreator (org.springframework.jdbc.object) + + + + SqlQuery (org.springframework.jdbc.object) + + + + + + SqlUpdate (org.springframework.jdbc.object) + + + + + + Statement (java.sql) + + + + + + + + + + + + + String (java.lang) + + + + + + + UpdatableSqlQuery.UpdatableSqlQuery (org.springframework.jdbc.object) + + + + XPath (javax.xml.xpath) + + + + + + + + XPath (org.jdom.xpath) + + + + + + */@href + ^javascript:(.+) + + + + */@on.* + + + + */@style + dummy_selector { + } + + + + ejb-ql + + + + ejbql + + + + entity-query/@ejbql + + + + mapped-statement + + + + out|if|forEach|set|when/@select + + + + query + + + + query + + + + query|update/@sql + + + + script + + + + sql|select|insert|update|delete|statement + + + + + style + + lower-case(@type)='text/css' + + diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java index 6dff6514c3..ef7f10654f 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java @@ -33,6 +33,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.util.FileContentUtil; +import com.intellij.util.Function; import com.intellij.util.NullableFunction; import com.intellij.util.PairProcessor; import com.intellij.util.containers.ConcurrentFactoryMap; @@ -158,14 +159,15 @@ public final class Configuration implements PersistentStateComponent { } private void mergeWithDefaultConfiguration() { + Configuration cfg = null; try { - final Configuration cfg = load(getClass().getResourceAsStream("/" + COMPONENT_NAME + ".xml")); - if (cfg == null) return; // very strange - importFrom(cfg); + cfg = load(getClass().getResourceAsStream("/" + COMPONENT_NAME + ".xml")); } catch (Exception e) { LOG.warn(e); } + if (cfg == null) return; + importFrom(cfg); } public Element getState() { @@ -289,32 +291,60 @@ public final class Configuration implements PersistentStateComponent { /** * Import from another configuration (e.g. imported file). Returns the number of imported items. + * @param cfg configuration to import from + * @return added injections count */ public int importFrom(final Configuration cfg) { - int n = 0; + final ArrayList originalInjections = new ArrayList(); + final ArrayList newInjections = new ArrayList(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { - final List mineInjections = myInjections.get(supportId); - for (BaseInjection other : cfg.getInjections(supportId)) { - final BaseInjection existing = findExistingInjection(other); - if (existing == null) { - n ++; - mineInjections.add(other); + importInjections(getInjections(supportId), cfg.getInjections(supportId), originalInjections, newInjections); + } + if (!newInjections.isEmpty()) configurationModified(); + replaceInjections(newInjections, originalInjections); + return newInjections.size(); + } + + static void importInjections(final Collection existingInjections, final Collection importingInjections, + final Collection originalInjections, final Collection newInjections) { + final MultiValuesMap existingMap = createInjectionMap(existingInjections); + main: for (BaseInjection other : importingInjections) { + final List matchingInjections = ContainerUtil.concat(other.getInjectionPlaces(), new Function>() { + public Collection fun(final InjectionPlace o) { + final Collection collection = existingMap.get(o.getText()); + return collection == null? Collections.emptyList() : collection; } - else { - if (existing.equals(other)) continue; - boolean placesAdded = false; - for (InjectionPlace place : other.getInjectionPlaces()) { - if (existing.findPlaceByText(place.getText()) == null) { - existing.getInjectionPlaces().add(place); - placesAdded = true; - } + }); + if (matchingInjections.isEmpty()) { + newInjections.add(other); + } + else { + BaseInjection existing = null; + for (BaseInjection injection : matchingInjections) { + if (injection.equals(other)) continue main; + if (existing == null && injection.sameLanguageParameters(other)) { + existing = injection; } - if (placesAdded) n++; } + if (existing == null) continue main; // skip!! language changed + final BaseInjection newInjection = existing.copy(); + newInjection.mergeOriginalPlacesFrom(other, true); + if (!newInjection.equals(existing)) { + originalInjections.add(existing); + newInjections.add(newInjection); + } + } + } + } + + private static MultiValuesMap createInjectionMap(final Collection injections) { + final MultiValuesMap existingMap = new MultiValuesMap(); + for (BaseInjection injection : injections) { + for (InjectionPlace place : injection.getInjectionPlaces()) { + existingMap.put(place.getText(), injection); } } - if (n >= 0) configurationModified(); - return n; + return existingMap; } public void configurationModified() { diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/InjectionsSettingsUI.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/InjectionsSettingsUI.java index 5ad57e4a12..965f047cb6 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/InjectionsSettingsUI.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/InjectionsSettingsUI.java @@ -42,7 +42,7 @@ import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.Icons; import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.*; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.ui.ListTableModel; import gnu.trove.THashMap; @@ -50,6 +50,7 @@ import org.intellij.plugins.intelliLang.inject.InjectedLanguage; import org.intellij.plugins.intelliLang.inject.InjectorUtils; import org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport; import org.intellij.plugins.intelliLang.inject.config.BaseInjection; +import org.intellij.plugins.intelliLang.inject.config.InjectionPlace; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; @@ -77,6 +78,7 @@ public class InjectionsSettingsUI implements Configurable { private final Map myEditActions = new THashMap(); private final List myAddActions = new ArrayList(); private ActionToolbar myToolbar; + private JLabel myCountLabel; public InjectionsSettingsUI(final Project project, final Configuration configuration) { myProject = project; @@ -102,9 +104,9 @@ public class InjectionsSettingsUI implements Configurable { myInjectionsTable = new InjectionsTable(myInjections); final JPanel tablePanel = new JPanel(new BorderLayout()); - //tablePanel.setBorder(BorderFactory.createTitledBorder("Available Injections")); + tablePanel.add(BetterJTable.createStripedJScrollPane(myInjectionsTable), BorderLayout.CENTER); - tablePanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); + //tablePanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); final DefaultActionGroup group = createActions(); @@ -112,6 +114,11 @@ public class InjectionsSettingsUI implements Configurable { myToolbar.setTargetComponent(myInjectionsTable); myRoot.add(myToolbar.getComponent(), BorderLayout.NORTH); myRoot.add(tablePanel, BorderLayout.CENTER); + myCountLabel = new JLabel(); + myCountLabel.setHorizontalAlignment(SwingConstants.RIGHT); + myCountLabel.setForeground(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.getFgColor()); + myRoot.add(myCountLabel, BorderLayout.SOUTH); + updateCountLabel(); } private DefaultActionGroup createActions() { @@ -146,6 +153,7 @@ public class InjectionsSettingsUI implements Configurable { @Override public void actionPerformed(final AnActionEvent e) { performAdd(e); + updateCountLabel(); } }; final AnAction removeAction = new AnAction("Remove", "Remove", Icons.DELETE_ICON) { @@ -157,6 +165,7 @@ public class InjectionsSettingsUI implements Configurable { @Override public void actionPerformed(final AnActionEvent e) { performRemove(); + updateCountLabel(); } }; @@ -175,6 +184,7 @@ public class InjectionsSettingsUI implements Configurable { action.actionPerformed(e); ((ListTableModel)myInjectionsTable.getModel()).fireTableDataChanged(); myInjectionsTable.getSelectionModel().setSelectionInterval(row, row); + updateCountLabel(); } }; group.add(addAction); @@ -189,6 +199,7 @@ public class InjectionsSettingsUI implements Configurable { @Override public void actionPerformed(final AnActionEvent e) { doImportAction(e.getDataContext()); + updateCountLabel(); } }); group.addSeparator(); @@ -202,6 +213,7 @@ public class InjectionsSettingsUI implements Configurable { @Override public void actionPerformed(final AnActionEvent e) { performSelectedInjectionsEnabled(false); + updateCountLabel(); } }); @@ -209,11 +221,32 @@ public class InjectionsSettingsUI implements Configurable { @Override public void actionPerformed(final AnActionEvent e) { performToggleAction(); + updateCountLabel(); } }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable); return group; } + private void updateCountLabel() { + int placesCount = 0; + int enablePlacesCount = 0; + for (BaseInjection injection : myInjections) { + for (InjectionPlace place : injection.getInjectionPlaces()) { + placesCount++; + if (place.isEnabled()) enablePlacesCount++; + } + } + if (!myInjections.isEmpty()) { + final StringBuilder sb = new StringBuilder(); + sb.append(myInjections.size()).append(" injection").append(myInjections.size() > 1 ? "s" : "").append(" (").append(enablePlacesCount) + .append(" of ").append(placesCount).append(" place").append(placesCount > 1 ? "s" : "").append(" enabled) "); + myCountLabel.setText(sb.toString()); + } + else { + myCountLabel.setText("no injections configured "); + } + } + private AnAction getEditAction() { final BaseInjection injection = getSelectedInjection(); final String supportId = injection == null? null : injection.getSupportId(); @@ -251,6 +284,7 @@ public class InjectionsSettingsUI implements Configurable { myInjections.add(injection.copy()); } ((ListTableModel)myInjectionsTable.getModel()).setItems(myInjections); + updateCountLabel(); } public void disposeUIResources() { @@ -274,7 +308,7 @@ public class InjectionsSettingsUI implements Configurable { for (BaseInjection injection : getSelectedInjections()) { injection.setPlaceEnabled(null, enabled); } - myInjectionsTable.updateUI(); + myInjectionsTable.updateUI(); } private void performToggleAction() { @@ -297,7 +331,7 @@ public class InjectionsSettingsUI implements Configurable { ((ListTableModel)myInjectionsTable.getModel()).fireTableDataChanged(); final int index = Math.min(myInjections.size() - 1, selectedRow); myInjectionsTable.getSelectionModel().setSelectionInterval(index, index); - TableUtil.scrollSelectionToVisible(myInjectionsTable); + TableUtil.scrollSelectionToVisible(myInjectionsTable); } private List getSelectedInjections() { @@ -549,14 +583,42 @@ public class InjectionsSettingsUI implements Configurable { Messages.showWarningDialog(myProject, "The selected file does not contain any importable configuration.", "Nothing to Import"); return; } - final List newInjections = - ContainerUtil.concat(cfg.getAllInjectorIds(), new Function>() { - public Collection fun(final String s) { - return cfg.getInjections(s); + final Map> currentMap = + ContainerUtil.classify(myInjections.iterator(), new Convertor() { + public String convert(final BaseInjection o) { + return o.getSupportId(); } }); - newInjections.removeAll(myInjections); + final List originalInjections = new ArrayList(); + final List newInjections = new ArrayList(); + //// remove duplicates + //for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { + // final Set currentInjections = currentMap.get(supportId); + // if (currentInjections == null) continue; + // for (BaseInjection injection : currentInjections) { + // Configuration.importInjections(newInjections, Collections.singleton(injection), originalInjections, newInjections); + // } + //} + //myInjections.clear(); + //myInjections.addAll(newInjections); + + for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { + final Set currentInjections = currentMap.get(supportId); + final List importingInjections = cfg.getInjections(supportId); + if (currentInjections == null) { + newInjections.addAll(importingInjections); + continue; + } + else { + Configuration.importInjections(currentInjections, importingInjections, originalInjections, newInjections); + } + } + myInjections.removeAll(originalInjections); myInjections.addAll(newInjections); + for (BaseInjection injection : newInjections) { + injection.initializePlaces(true); + } + ((ListTableModel)myInjectionsTable.getModel()).setItems(myInjections); final int n = newInjections.size(); if (n > 1) { Messages.showInfoMessage(myProject, n + " entries have been successfully imported", "Import Successful"); -- 2.11.4.GIT