diff options
Diffstat (limited to 'python/rest')
5 files changed, 67 insertions, 12 deletions
diff --git a/python/rest/resources/META-INF/plugin.xml b/python/rest/resources/META-INF/plugin.xml index 06cd1f494960..76e572763830 100644 --- a/python/rest/resources/META-INF/plugin.xml +++ b/python/rest/resources/META-INF/plugin.xml @@ -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> diff --git a/python/rest/src/com/jetbrains/rest/RestBundle.properties b/python/rest/src/com/jetbrains/rest/RestBundle.properties index 24b98c7431f4..192f44308c13 100644 --- a/python/rest/src/com/jetbrains/rest/RestBundle.properties +++ b/python/rest/src/com/jetbrains/rest/RestBundle.properties @@ -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 diff --git a/python/rest/src/com/jetbrains/rest/RestLanguage.java b/python/rest/src/com/jetbrains/rest/RestLanguage.java index c451e379f437..df056590efcc 100644 --- a/python/rest/src/com/jetbrains/rest/RestLanguage.java +++ b/python/rest/src/com/jetbrains/rest/RestLanguage.java @@ -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() { diff --git a/python/rest/src/com/jetbrains/rest/psi/RestTitle.java b/python/rest/src/com/jetbrains/rest/psi/RestTitle.java index eb93cbee77ac..05c2e66c2c52 100644 --- a/python/rest/src/com/jetbrains/rest/psi/RestTitle.java +++ b/python/rest/src/com/jetbrains/rest/psi/RestTitle.java @@ -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 index 000000000000..c906e311af83 --- /dev/null +++ b/python/rest/src/com/jetbrains/rest/validation/RestTitleAnnotator.java @@ -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")); + } + } +} |