fixed PY-10998 Wrong highlight in rst (restructured texts) for headlines
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 2 Dec 2013 15:11:48 +0000 (19:11 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Mon, 2 Dec 2013 15:11:48 +0000 (19:11 +0400)
python/rest/resources/META-INF/plugin.xml
python/rest/rest.iml
python/rest/src/com/jetbrains/rest/RestBundle.properties
python/rest/src/com/jetbrains/rest/RestLanguage.java
python/rest/src/com/jetbrains/rest/psi/RestTitle.java
python/rest/src/com/jetbrains/rest/validation/RestTitleAnnotator.java [new file with mode: 0644]

index 06cd1f49496033df0add5315b4c0b531b6cb0c7f..76e5727638300d63da56274fc47b16bb38678492 100644 (file)
@@ -3,12 +3,16 @@
   <id>org.jetbrains.plugins.rest</id>
   <description>This plugin enables support for reStructuredText files (*.rst)</description>
   <vendor>JetBrains</vendor>
-  <version>132.SNAPSHOT</version>
-  <idea-version since-build="130.1" until-build="133.0"/>
+  <version>134.SNAPSHOT</version>
+  <idea-version since-build="130.1"/>
   <depends>com.intellij.modules.lang</depends>
 
   <xi:include href="/META-INF/rest.xml" xpointer="xpointer(/idea-plugin/*)"/>
-
+  <change-notes><![CDATA[
+    <ul>
+    <li>Added inspection for title & underline length math (PY-10998)</li>
+    </ul>
+]]></change-notes>
   <extensions defaultExtensionNs="com.intellij">
     <errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
   </extensions>
index b9ccb2c7f453446423d5684c0941ff3da37995c6..0310775a2f432073eb6d389e11587d30dd48482b 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
+<module type="PLUGIN_MODULE" version="4">
   <component name="NewModuleRootManager" inherit-compiler-output="true">
     <exclude-output />
     <content url="file://$MODULE_DIR$">
index 24b98c7431f4db8d13d39f6445c1b19ea08d18de..192f44308c13d7e03d5233222e5d0f8b610d681c 100644 (file)
@@ -9,6 +9,7 @@ QFIX.ignore.role=Ignore undefined role ''{0}''
 ### Annotators ###
 ANN.unknown.target=Unknown target name ''{0}''
 ANN.duplicate.target=Duplicate explicit target name ''{0}''
+ANN.title.length=Title length must match the underline
 ANN.unusable.anonymous.target=Anonymous hyperlink target has no reference
 ANN.inline.block=Blank line is required after a literal block
 
index c451e379f437dea28e4248e653afc0595f7b6e8a..df056590efcc31083d86e1754b36eef00fb870bf 100644 (file)
@@ -17,10 +17,7 @@ package com.jetbrains.rest;
 
 import com.intellij.lang.Language;
 import com.intellij.psi.templateLanguages.TemplateLanguage;
-import com.jetbrains.rest.validation.RestAnnotator;
-import com.jetbrains.rest.validation.RestHyperlinksAnnotator;
-import com.jetbrains.rest.validation.RestInlineBlockAnnotator;
-import com.jetbrains.rest.validation.RestReferenceTargetAnnotator;
+import com.jetbrains.rest.validation.*;
 
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -48,6 +45,7 @@ public class RestLanguage extends Language implements TemplateLanguage  {
     _annotators.add(RestHyperlinksAnnotator.class);
     _annotators.add(RestReferenceTargetAnnotator.class);
     _annotators.add(RestInlineBlockAnnotator.class);
+    _annotators.add(RestTitleAnnotator.class);
   }
 
   public Set<Class<? extends RestAnnotator>> getAnnotators() {
index eb93cbee77ac24eda815b09e052eb5fc8ea22fc7..05c2e66c2c5216fb27805db05afaf6b396cf8f8e 100644 (file)
@@ -16,6 +16,7 @@
 package com.jetbrains.rest.psi;
 
 import com.intellij.lang.ASTNode;
+import com.jetbrains.rest.validation.RestElementVisitor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -37,15 +38,13 @@ public class RestTitle extends RestElement {
 
   @Nullable
   public String getName() {
-    final String text = getNode().getText();
-    if (text.length() == 0) return null;
+    final String text = getNode().getText().trim();
+    if (text.length() < 2) return null;
     final char adorn = text.charAt(text.length()-2);
     final CharacterIterator it = new StringCharacterIterator(text);
     int finish = 0;
     for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
-      if (finish == 0)
-        finish++;
-      else if (ch != adorn) {
+      if (ch != adorn) {
         finish = it.getIndex();
         break;
       }
@@ -63,4 +62,25 @@ public class RestTitle extends RestElement {
       return null;
     return text.substring(start, finish).trim();
   }
+
+  @Nullable
+  public String getUnderline() {
+    final String text = getNode().getText().trim();
+    if (text.length() < 2) return null;
+    final char adorn = text.charAt(text.length()-2);
+    final CharacterIterator it = new StringCharacterIterator(text);
+    int start = 0;
+    for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
+      if (ch != adorn) {
+        start = it.getIndex() + 1;
+        break;
+      }
+    }
+    return text.substring(start, text.length());
+  }
+
+  @Override
+  protected void acceptRestVisitor(RestElementVisitor visitor) {
+    visitor.visitTitle(this);
+  }
 }
diff --git a/python/rest/src/com/jetbrains/rest/validation/RestTitleAnnotator.java b/python/rest/src/com/jetbrains/rest/validation/RestTitleAnnotator.java
new file mode 100644 (file)
index 0000000..c906e31
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2000-2013 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.rest.validation;
+
+import com.jetbrains.rest.RestBundle;
+import com.jetbrains.rest.psi.RestTitle;
+
+public class RestTitleAnnotator extends RestAnnotator {
+  @Override
+  public void visitTitle(final RestTitle node) {
+    final String name = node.getName();
+    if (name == null) return;
+    int nameLen = name.length();
+    final String underline = node.getUnderline();
+    if (underline != null && nameLen != underline.length()) {
+      getHolder().createWarningAnnotation(node, RestBundle.message("ANN.title.length"));
+    }
+  }
+}