Search in sources :

Example 1 with PsiPerlIfCompoundImpl

use of com.perl5.lang.perl.psi.impl.PsiPerlIfCompoundImpl in project Perl5-IDEA by Camelcade.

the class PerlBraceMatcher method getCodeConstructStart.

@Override
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
    PsiElement element = file.findElementAt(openingBraceOffset);
    if (element == null || element instanceof PsiFile) {
        return openingBraceOffset;
    }
    PsiElement codeBlock = element.getParent();
    if (codeBlock != null && codeBlock instanceof PsiPerlBlock) {
        PsiElement blockContainer = codeBlock.getParent();
        if (blockContainer != null) {
            if (blockContainer instanceof PerlSubDefinitionElement || blockContainer instanceof PsiPerlForCompound) {
                return blockContainer.getTextOffset();
            } else if (blockContainer instanceof PsiPerlConditionalBlock || blockContainer instanceof PsiPerlIfCompoundImpl) {
                PsiElement keyword = blockContainer.getPrevSibling();
                while (keyword != null && (keyword instanceof PsiWhiteSpace || keyword instanceof PsiComment)) {
                    keyword = keyword.getPrevSibling();
                }
                if (keyword != null) {
                    return keyword.getTextOffset();
                }
            }
        }
    }
    return openingBraceOffset;
}
Also used : PsiPerlConditionalBlock(com.perl5.lang.perl.psi.PsiPerlConditionalBlock) PsiComment(com.intellij.psi.PsiComment) PsiPerlIfCompoundImpl(com.perl5.lang.perl.psi.impl.PsiPerlIfCompoundImpl) PsiPerlBlock(com.perl5.lang.perl.psi.PsiPerlBlock) PsiFile(com.intellij.psi.PsiFile) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) PsiElement(com.intellij.psi.PsiElement) PsiPerlForCompound(com.perl5.lang.perl.psi.PsiPerlForCompound) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

PsiComment (com.intellij.psi.PsiComment)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)1 PsiPerlBlock (com.perl5.lang.perl.psi.PsiPerlBlock)1 PsiPerlConditionalBlock (com.perl5.lang.perl.psi.PsiPerlConditionalBlock)1 PsiPerlForCompound (com.perl5.lang.perl.psi.PsiPerlForCompound)1 PsiPerlIfCompoundImpl (com.perl5.lang.perl.psi.impl.PsiPerlIfCompoundImpl)1