diff options
Diffstat (limited to 'python/rest/src/com/jetbrains/rest/psi/RestTitle.java')
-rw-r--r-- | python/rest/src/com/jetbrains/rest/psi/RestTitle.java | 30 |
1 files changed, 25 insertions, 5 deletions
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); + } } |