use of com.perl5.lang.perl.psi.PerlHeredocTerminatorElement in project Perl5-IDEA by Camelcade.
the class PerlHeredocFormattingBlock method getTextRange.
@NotNull
@Override
public TextRange getTextRange() {
TextRange originalRange = super.getTextRange();
if (originalRange.isEmpty()) {
return originalRange;
}
TextRange trimmedRange = TextRange.create(originalRange.getStartOffset(), originalRange.getEndOffset() - 1);
PerlHeredocElementImpl heredocElement = getPsi();
if (!heredocElement.isIndentable()) {
return trimmedRange;
}
PerlHeredocTerminatorElement terminatorElement = heredocElement.getTerminatorElement();
if (terminatorElement == null) {
return trimmedRange;
}
// perlop: Tabs and spaces can be mixed, but are matched exactly. One tab will not be equal to 8 spaces!
int spacesBeforeTerminator = terminatorElement.getTextRange().getStartOffset() - trimmedRange.getEndOffset() - 1;
if (spacesBeforeTerminator == 0) {
return trimmedRange;
}
CharSequence nodeChars = trimmedRange.shiftRight(-myNode.getStartOffset()).subSequence(myNode.getChars());
int effectiveCharsLength = nodeChars.length();
int realSpaces;
int offset = 0;
OUTER: while (offset < effectiveCharsLength) {
for (realSpaces = 0; realSpaces <= spacesBeforeTerminator && offset < effectiveCharsLength; realSpaces++) {
if (realSpaces == spacesBeforeTerminator) {
break OUTER;
}
char currentChar = nodeChars.charAt(offset);
if (currentChar == '\n') {
offset++;
break;
} else if (!Character.isWhitespace(currentChar)) {
break OUTER;
} else {
offset++;
}
}
}
return TextRange.create(trimmedRange.getStartOffset() + offset, trimmedRange.getEndOffset());
}
use of com.perl5.lang.perl.psi.PerlHeredocTerminatorElement in project Perl5-IDEA by Camelcade.
the class PerlDocUtil method getPerlOpDoc.
@Nullable
public static PsiElement getPerlOpDoc(@NotNull PsiElement element) {
final Project project = element.getProject();
String text = element.getText();
String redirect = myOperatorsRedirections.get(text);
if (redirect != null) {
return resolveDocLink(redirect, element);
}
// fixme use map?
PodDocumentPattern pattern = PodDocumentPattern.indexPattern(text);
if (element instanceof PerlHeredocOpener || element instanceof PerlHeredocTerminatorElement || element instanceof PerlHeredocElementImpl) {
// searches with X<>
pattern.setIndexKey("heredoc");
} else if (text.matches("-[rwxoRWXOeszfdlpSbctugkTBMAC]")) {
pattern.setIndexKey("-X");
} else if ("?".equals(text) || ":".equals(text)) {
pattern.setIndexKey("?:");
}
return searchPodElementInFile(project, PodSearchHelper.PERL_OP_FILE_NAME, pattern);
}
use of com.perl5.lang.perl.psi.PerlHeredocTerminatorElement in project Perl5-IDEA by Camelcade.
the class PerlHeredocLanguageInjector method getInjectedLanguage.
@Nullable
private Language getInjectedLanguage(@NotNull PerlHeredocElementImpl heredocElement) {
PerlHeredocTerminatorElement terminator = heredocElement.getTerminatorElement();
if (terminator == null) {
return null;
}
String terminatorText = terminator.getText();
Language mappedLanguage = LANGUAGE_MAP.get(terminatorText);
if (mappedLanguage != null) {
return mappedLanguage;
}
PerlTemporaryInjectedLanguageDetector temporaryInjectedLanguageDetector = PerlTemporaryInjectedLanguageDetector.getInstance();
return temporaryInjectedLanguageDetector == null ? null : temporaryInjectedLanguageDetector.getTemporaryInjectedLanguage(heredocElement);
}
Aggregations