IDEA-101829 Spell Check does not check CDATA blocks
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Thu, 28 Feb 2013 08:24:06 +0000 (12:24 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Thu, 28 Feb 2013 08:24:06 +0000 (12:24 +0400)
spellchecker/spellchecker.iml
spellchecker/src/com/intellij/spellchecker/tokenizer/XmlTextTokenizer.java
spellchecker/testData/inspection/xmlWithMistakes/test.xml

index ad0f6db77fe41c68b46f9f2129ee3b5d3f55e1cc..79b786a06bb7311f191dfc6ab51b284f117c1773 100644 (file)
@@ -15,6 +15,7 @@
     <orderEntry type="module" module-name="xml-openapi" />
     <orderEntry type="module" module-name="testFramework" scope="TEST" />
     <orderEntry type="module" module-name="dom-openapi" />
+    <orderEntry type="module" module-name="xml" />
   </component>
 </module>
 
index 2703391ba897eb8638825e3c3bc32cfe6d63b28c..44d032e9ecc3700432fc2cde1c2aa2df7514e1be 100644 (file)
  */
 package com.intellij.spellchecker.tokenizer;
 
-import com.intellij.lang.injection.InjectedLanguageManager;
-import com.intellij.openapi.util.Pair;
-import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiLanguageInjectionHost;
+import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
+import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.xml.XmlElementType;
 import com.intellij.psi.xml.XmlText;
-import com.intellij.psi.xml.XmlToken;
 import com.intellij.psi.xml.XmlTokenType;
 import com.intellij.spellchecker.inspections.PlainTextSplitter;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.List;
-
 public class XmlTextTokenizer extends Tokenizer<XmlText> {
   @Override
   public void tokenize(@NotNull XmlText element, TokenConsumer consumer) {
-    List<Pair<PsiElement,TextRange>> list = InjectedLanguageManager.getInstance(element.getProject()).getInjectedPsiFiles(element);
-    if (list != null && list.size() > 0) return;
+    if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element)) return;
+    processChildren(element, consumer);
+  }
+
+  private static void processChildren(PsiElement element, TokenConsumer consumer) {
     final PsiElement[] children = element.getChildren();
     for (PsiElement child : children) {
-      if (child instanceof XmlToken && ((XmlToken)child).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
+      IElementType elementType = child.getNode().getElementType();
+      if (elementType == XmlTokenType.XML_DATA_CHARACTERS) {
         consumer.consumeToken(child, PlainTextSplitter.getInstance());
       }
+      else if (elementType == XmlElementType.XML_CDATA) {
+        processChildren(child, consumer);
+      }
     }
   }
 }
index 22db7e2a030828c6e9438987c8fa350689f7c3a8..3273389abcf636e2c3664ef438ad5f296ac9b2a7 100644 (file)
@@ -2,5 +2,8 @@
  plain text <TYPO descr="Typo: In word 'gooes'">gooes</TYPO> here
 
 <b>&amp;</b>
+
+<description><![CDATA[ <TYPO descr="Typo: In word 'foozz'">foozz</TYPO> ]]></description>
+
 </a>