From bd1a761cd27f8b07b6cb356a63e32145b83e03a6 Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 31 Mar 2010 23:28:08 +0400 Subject: [PATCH] split IntelliLang default config & save only the diff --- .../extensions/impl/ExtensionsAreaImpl.java | 16 +- .../src/LanguageInjectionConfiguration.xml | 444 +----------------- .../META-INF/intellilang-groovy-support.xml | 3 +- .../src/META-INF/intellilang-java-support.xml | 3 +- .../src/META-INF/intellilang-xml-support.xml | 3 +- .../plugins/intelliLang/Configuration.java | 38 +- .../AbstractLanguageInjectionSupport.java | 2 +- .../inject/LanguageInjectionSupport.java | 40 +- .../inject/config/BaseInjection.java | 5 + .../src/resources/groovyInjections.xml | 49 ++ .../src/resources/javaInjections.xml | 279 +++++++++++ .../src/resources/xmlInjections.xml | 99 ++++ 12 files changed, 507 insertions(+), 474 deletions(-) create mode 100644 plugins/IntelliLang/src/resources/groovyInjections.xml create mode 100644 plugins/IntelliLang/src/resources/javaInjections.xml create mode 100644 plugins/IntelliLang/src/resources/xmlInjections.xml diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionsAreaImpl.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionsAreaImpl.java index 8c86da95c0b3..8acb2052ab20 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionsAreaImpl.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionsAreaImpl.java @@ -18,6 +18,7 @@ package com.intellij.openapi.extensions.impl; import com.intellij.openapi.extensions.*; import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.containers.MultiMap; +import org.jdom.Attribute; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.output.Format; @@ -128,7 +129,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea { ExtensionComponentAdapter adapter; if (implClass != null) { - adapter = new ExtensionComponentAdapter(implClass, extensionElement, getPluginContainer(pluginId.getIdString()), pluginDescriptor, false); + adapter = new ExtensionComponentAdapter(implClass, extensionElement, getPluginContainer(pluginId.getIdString()), pluginDescriptor, shouldDeserializeInstance(extensionElement)); } else { final ExtensionPoint extensionPoint = getExtensionPoint(epName); @@ -139,6 +140,19 @@ public class ExtensionsAreaImpl implements ExtensionsArea { getExtensionPoint(epName).registerExtensionAdapter(adapter); } + private static boolean shouldDeserializeInstance(Element extensionElement) { + // has content + if (!extensionElement.getContent().isEmpty()) return true; + // has custom attributes + for (Attribute attribute : (List)extensionElement.getAttributes()) { + final String name = attribute.getName(); + if (!"implementation".equals(name) && !"id".equals(name) && !"order".equals(name)) { + return true; + } + } + return false; + } + private static String extractEPName(final Element extensionElement) { String epName = extensionElement.getAttributeValue("point"); diff --git a/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml b/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml index 8a1bd8c4550e..14439422b3af 100644 --- a/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml +++ b/plugins/IntelliLang/src/LanguageInjectionConfiguration.xml @@ -1,446 +1,4 @@ - - Connection (java.sql) - - - - - - - - - - - - - Statement (java.sql) - - - - - - - - - - - - - groovy.sql.Sql - - - - - - - - - - GroovyShell (groovy.lang) - - - - - - - - - - GroovyShell (groovy.lang) - - - - - - - - - - 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]*([^\}]*) - - - - JAXB attribute node - - - - 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) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SqlCall.SqlCall (org.springframework.jdbc.object) - - - - SqlFunction (org.springframework.jdbc.object) - - - - - - SqlFunction.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 - - - - element - (.+) - - @name='regexp' - - - entity-query/@ejbql - - - - mapped-statement - - - - out|if|forEach|set|when/@select - - - - query - - - - query - - - - query|update/@sql - - - - script - - - - sql|select|insert|update|delete|statement - - - - - iBatis3: sql|select|insert|update|delete - - - - - style - - lower-case(@type)='text/css' - - - Bare Tapestry EL in attribute value - ${ - } - - - - - <<< CSS - - - - <<< SQL - - - - <<< HTML - - - - "<HTML>" - - - - "SELECT ... FROM ..." - - - - <<< JS - - - - - - CSS in jsf - inline.style { - } - - - - CSS in rich faces - inline.style { - } - - + diff --git a/plugins/IntelliLang/src/META-INF/intellilang-groovy-support.xml b/plugins/IntelliLang/src/META-INF/intellilang-groovy-support.xml index edee7c831704..241b30708fd5 100644 --- a/plugins/IntelliLang/src/META-INF/intellilang-groovy-support.xml +++ b/plugins/IntelliLang/src/META-INF/intellilang-groovy-support.xml @@ -3,7 +3,8 @@ - + \ No newline at end of file diff --git a/plugins/IntelliLang/src/META-INF/intellilang-java-support.xml b/plugins/IntelliLang/src/META-INF/intellilang-java-support.xml index d1b1dc329b29..a84e7ae05f1d 100644 --- a/plugins/IntelliLang/src/META-INF/intellilang-java-support.xml +++ b/plugins/IntelliLang/src/META-INF/intellilang-java-support.xml @@ -15,7 +15,8 @@ - + \ No newline at end of file diff --git a/plugins/IntelliLang/src/META-INF/intellilang-xml-support.xml b/plugins/IntelliLang/src/META-INF/intellilang-xml-support.xml index 19d5c32aa17c..c7d3511d488e 100644 --- a/plugins/IntelliLang/src/META-INF/intellilang-xml-support.xml +++ b/plugins/IntelliLang/src/META-INF/intellilang-xml-support.xml @@ -7,7 +7,8 @@ - + \ No newline at end of file diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java index e7a8cdbc053a..4ee6369b793d 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java @@ -85,6 +85,7 @@ public final class Configuration implements PersistentStateComponent { return new CopyOnWriteArrayList(); } }; + private ArrayList myDefaultInjections; // runtime pattern validation instrumentation @NotNull private InstrumentationType myInstrumentationType = InstrumentationType.ASSERT; @@ -169,15 +170,29 @@ public final class Configuration implements PersistentStateComponent { } private void mergeWithDefaultConfiguration() { - Configuration cfg = null; - try { - cfg = load(getClass().getResourceAsStream("/" + COMPONENT_NAME + ".xml")); + final ArrayList cfgList = new ArrayList(); + for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { + final String url = support.getDefaultConfigUrl(); + if (url != null) { + try { + cfgList.add(load(support.getClass().getResourceAsStream(url))); + } + catch (Exception e) { + LOG.warn(e); + } + } } - catch (Exception e) { - LOG.warn(e); + final ArrayList originalInjections = new ArrayList(); + final ArrayList newInjections = new ArrayList(); + myDefaultInjections = new ArrayList(); + for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { + for (Configuration cfg : cfgList) { + final List imported = cfg.getInjections(supportId); + myDefaultInjections.addAll(imported); + importInjections(getInjections(supportId), imported, originalInjections, newInjections); + } } - if (cfg == null) return; - importFrom(cfg); + replaceInjections(newInjections, originalInjections); } public Element getState() { @@ -189,10 +204,13 @@ public final class Configuration implements PersistentStateComponent { JDOMExternalizerUtil.writeField(element, SUBST_ANNOTATION_NAME, mySubstAnnotation); JDOMExternalizerUtil.writeField(element, RESOLVE_REFERENCES, String.valueOf(myResolveReferences)); - final List injectoIds = new ArrayList(myInjections.keySet()); - Collections.sort(injectoIds); - for (String key : injectoIds) { + final List injectorIds = new ArrayList(myInjections.keySet()); + Collections.sort(injectorIds); + for (String key : injectorIds) { final List injections = new ArrayList(myInjections.get(key)); + if (myDefaultInjections != null) { + injections.removeAll(myDefaultInjections); + } Collections.sort(injections, new Comparator() { public int compare(final BaseInjection o1, final BaseInjection o2) { return Comparing.compare(o1.getDisplayName(), o2.getDisplayName()); diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/AbstractLanguageInjectionSupport.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/AbstractLanguageInjectionSupport.java index 743eed1c732f..1ee79a027976 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/AbstractLanguageInjectionSupport.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/AbstractLanguageInjectionSupport.java @@ -33,7 +33,7 @@ import org.jdom.Element; /** * @author Gregory.Shrago */ -public abstract class AbstractLanguageInjectionSupport implements LanguageInjectionSupport { +public abstract class AbstractLanguageInjectionSupport extends LanguageInjectionSupport { public boolean useDefaultInjector(final PsiElement host) { return false; diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/LanguageInjectionSupport.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/LanguageInjectionSupport.java index f9824a202479..f2614f6ed6dc 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/LanguageInjectionSupport.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/LanguageInjectionSupport.java @@ -26,6 +26,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLanguageInjectionHost; import com.intellij.ui.SimpleColoredText; import com.intellij.util.Consumer; +import com.intellij.util.xmlb.annotations.Attribute; import org.intellij.plugins.intelliLang.Configuration; import org.intellij.plugins.intelliLang.inject.config.BaseInjection; import org.jdom.Element; @@ -35,36 +36,43 @@ import org.jetbrains.annotations.NotNull; /** * @author Gregory.Shrago */ -public interface LanguageInjectionSupport { - ExtensionPointName EP_NAME = ExtensionPointName.create("org.intellij.intelliLang.languageSupport"); +public abstract class LanguageInjectionSupport { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("org.intellij.intelliLang.languageSupport"); - Key HAS_UNPARSABLE_FRAGMENTS = Key.create("HAS_UNPARSABLE_FRAGMENTS"); + public static Key HAS_UNPARSABLE_FRAGMENTS = Key.create("HAS_UNPARSABLE_FRAGMENTS"); - @NonNls String XML_SUPPORT_ID = "xml"; - @NonNls String JAVA_SUPPORT_ID = "java"; + @NonNls public static final String XML_SUPPORT_ID = "xml"; + @NonNls public static final String JAVA_SUPPORT_ID = "java"; + + @Attribute("config") + public String myConfigUrl; + + public String getDefaultConfigUrl() { + return myConfigUrl; + } @NonNls @NotNull - String getId(); + public abstract String getId(); @NotNull - Class[] getPatternClasses(); + public abstract Class[] getPatternClasses(); - boolean useDefaultInjector(final PsiElement host); + public abstract boolean useDefaultInjector(final PsiElement host); - boolean addInjectionInPlace(final Language language, final PsiLanguageInjectionHost psiElement); + public abstract boolean addInjectionInPlace(final Language language, final PsiLanguageInjectionHost psiElement); - boolean removeInjectionInPlace(final PsiLanguageInjectionHost psiElement); + public abstract boolean removeInjectionInPlace(final PsiLanguageInjectionHost psiElement); - boolean editInjectionInPlace(final PsiLanguageInjectionHost psiElement); + public abstract boolean editInjectionInPlace(final PsiLanguageInjectionHost psiElement); - BaseInjection createInjection(final Element element); + public abstract BaseInjection createInjection(final Element element); - void setupPresentation(final BaseInjection injection, final SimpleColoredText presentation, final boolean isSelected); + public abstract void setupPresentation(final BaseInjection injection, final SimpleColoredText presentation, final boolean isSelected); - Configurable[] createSettings(final Project project, final Configuration configuration); + public abstract Configurable[] createSettings(final Project project, final Configuration configuration); - AnAction[] createAddActions(final Project project, final Consumer consumer); + public abstract AnAction[] createAddActions(final Project project, final Consumer consumer); - AnAction createEditAction(final Project project, final Factory producer); + public abstract AnAction createEditAction(final Project project, final Factory producer); } diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java index b1d56ba52221..e13935bc6878 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/config/BaseInjection.java @@ -393,4 +393,9 @@ public class BaseInjection implements Injection, PersistentStateComponent" +getDisplayName(); + } } diff --git a/plugins/IntelliLang/src/resources/groovyInjections.xml b/plugins/IntelliLang/src/resources/groovyInjections.xml new file mode 100644 index 000000000000..1953973bdeb1 --- /dev/null +++ b/plugins/IntelliLang/src/resources/groovyInjections.xml @@ -0,0 +1,49 @@ + + + + Connection (java.sql) + + + + + + + + + + + + + Statement (java.sql) + + + + + + + + + + + + + groovy.sql.Sql + + + + + + + + + + GroovyShell (groovy.lang) + + + + + + + + + diff --git a/plugins/IntelliLang/src/resources/javaInjections.xml b/plugins/IntelliLang/src/resources/javaInjections.xml new file mode 100644 index 000000000000..3a207c443c30 --- /dev/null +++ b/plugins/IntelliLang/src/resources/javaInjections.xml @@ -0,0 +1,279 @@ + + + + GroovyShell (groovy.lang) + + + + + + + + + + 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) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SqlCall.SqlCall (org.springframework.jdbc.object) + + + + SqlFunction (org.springframework.jdbc.object) + + + + + + SqlFunction.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) + + + + + diff --git a/plugins/IntelliLang/src/resources/xmlInjections.xml b/plugins/IntelliLang/src/resources/xmlInjections.xml new file mode 100644 index 000000000000..322bbc999d1f --- /dev/null +++ b/plugins/IntelliLang/src/resources/xmlInjections.xml @@ -0,0 +1,99 @@ + + + + JAXB attribute node + + + + */@href + ^javascript:(.+) + + + + */@on.* + + + + */@style + dummy_selector { + } + + + + ejb-ql + + + + ejbql + + + + element + (.+) + + @name='regexp' + + + entity-query/@ejbql + + + + mapped-statement + + + + out|if|forEach|set|when/@select + + + + query + + + + query + + + + query|update/@sql + + + + script + + + + sql|select|insert|update|delete|statement + + + + + iBatis3: sql|select|insert|update|delete + + + + + style + + lower-case(@type)='text/css' + + + Bare Tapestry EL in attribute value + ${ + } + + + + + + CSS in jsf + inline.style { + } + + + + CSS in rich faces + inline.style { + } + + +