Search in sources :

Example 1 with PerlHeredocTerminatorElement

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());
}
Also used : PerlHeredocTerminatorElement(com.perl5.lang.perl.psi.PerlHeredocTerminatorElement) TextRange(com.intellij.openapi.util.TextRange) PerlHeredocElementImpl(com.perl5.lang.perl.psi.impl.PerlHeredocElementImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlHeredocTerminatorElement

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);
}
Also used : PerlHeredocTerminatorElement(com.perl5.lang.perl.psi.PerlHeredocTerminatorElement) Project(com.intellij.openapi.project.Project) PerlHeredocOpener(com.perl5.lang.perl.psi.PerlHeredocOpener) PerlHeredocElementImpl(com.perl5.lang.perl.psi.impl.PerlHeredocElementImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PerlHeredocTerminatorElement

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);
}
Also used : PerlHeredocTerminatorElement(com.perl5.lang.perl.psi.PerlHeredocTerminatorElement) Language(com.intellij.lang.Language) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PerlHeredocTerminatorElement (com.perl5.lang.perl.psi.PerlHeredocTerminatorElement)3 PerlHeredocElementImpl (com.perl5.lang.perl.psi.impl.PerlHeredocElementImpl)2 Nullable (org.jetbrains.annotations.Nullable)2 Language (com.intellij.lang.Language)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PerlHeredocOpener (com.perl5.lang.perl.psi.PerlHeredocOpener)1 NotNull (org.jetbrains.annotations.NotNull)1