fixed PY-10998 Wrong highlight in rst (restructured texts) for headlines

This commit is contained in:
Ekaterina Tuzova
2013-12-02 19:11:48 +04:00
parent b875819405
commit acc583e096
6 changed files with 68 additions and 13 deletions
+7 -3
View 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>
+1 -1
View 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$">
@@ -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
@@ -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() {
@@ -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);
}
}
@@ -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"));
}
}
}