rename; generate correct empty html tag even if there is no corresponding live template
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 23 Mar 2010 18:14:54 +0000 (21:14 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 23 Mar 2010 18:14:54 +0000 (21:14 +0300)
xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingInterpreter.java
xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java

index 7392a13680b582e2eb072b0f9fcfd9a14dbe7864..5f6358b5af68c1f0355f86c2afb4ca779719cc46 100644 (file)
@@ -37,6 +37,7 @@ import com.intellij.psi.xml.XmlTokenType;
 import com.intellij.util.containers.HashMap;
 import com.intellij.util.containers.HashSet;
 import com.intellij.util.containers.IntArrayList;
+import com.intellij.xml.util.HtmlUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -395,8 +396,10 @@ class XmlZenCodingInterpreter {
         template.addVariableSegment(ATTRS);
       }
       template.addTextSegment(">");
-      template.addVariableSegment(TemplateImpl.END);
-      template.addTextSegment("</" + token.myKey + ">");
+      if (XmlZenCodingTemplate.isTrueXml(callback) || !HtmlUtil.isSingleHtmlTag(token.myKey)) {
+        template.addVariableSegment(TemplateImpl.END);
+        template.addTextSegment("</" + token.myKey + ">");
+      }
       template.setToReformat(true);
       Map<String, String> predefinedValues = buildPredefinedValues(attr2value, numberInIteration);
       return callback.startTemplate(template, predefinedValues, listener);
@@ -409,7 +412,7 @@ class XmlZenCodingInterpreter {
                                                     int numberInIteration,
                                                     List<Pair<String, String>> attr2value) {
     if (token.myTemplate != null) {
-      if (attr2value.size() > 0 || XmlZenCodingTemplate.autoclosingAvailable(callback)) {
+      if (attr2value.size() > 0 || XmlZenCodingTemplate.isTrueXml(callback)) {
         TemplateImpl modifiedTemplate = token.myTemplate.copy();
         XmlTag tag = XmlZenCodingTemplate.parseXmlTagInTemplate(token.myTemplate.getString(), callback, true);
         if (tag != null) {
@@ -420,7 +423,7 @@ class XmlZenCodingInterpreter {
               iterator.remove();
             }
           }
-          if (XmlZenCodingTemplate.autoclosingAvailable(callback)) {
+          if (XmlZenCodingTemplate.isTrueXml(callback)) {
             closeUnclosingTags(tag);
           }
           String text = null;
index dc7c8667264355d4bff6d3c5226eb59e3dcac2be..aa690594f3abe99717b714a807c0832bb8a8187f 100644 (file)
@@ -176,7 +176,7 @@ public class XmlZenCodingTemplate {
     return template;
   }
 
-  public static boolean autoclosingAvailable(CustomTemplateCallback callback) {
+  public static boolean isTrueXml(CustomTemplateCallback callback) {
     FileType type = callback.getFileType();
     return type == StdFileTypes.XHTML || type == StdFileTypes.JSPX;
   }
@@ -208,7 +208,7 @@ public class XmlZenCodingTemplate {
           if (token == null) {
             return null;
           }
-          if (applicable && (token.myAttribute2Value.size() > 0 || autoclosingAvailable(callback))) {
+          if (applicable && (token.myAttribute2Value.size() > 0 || isTrueXml(callback))) {
             assert prefix.equals(token.myKey);
             TemplateImpl template = cacheTemplate(token, callback);
             if (token.myAttribute2Value.size() > 0) {