Search in sources :

Example 41 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-plugins by JetBrains.

the class CfmlVariableSurroundDescriptor method getElementsToSurround.

@NotNull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
    final FileViewProvider viewProvider = file.getViewProvider();
    PsiElement elementAt = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, CfmlReferenceExpression.class);
    if (elementAt != null) {
        return !(elementAt.getParent() instanceof CfmlReferenceExpression) ? new PsiElement[] { elementAt } : PsiElement.EMPTY_ARRAY;
    }
    for (Language language : viewProvider.getLanguages()) {
        elementAt = viewProvider.findElementAt(startOffset, language);
        if (elementAt != null && (!language.is(CfmlLanguage.INSTANCE) || elementAt.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT) && elementAt.getNode().getText().matches("(\\S)+") && elementAt.getTextRange().getStartOffset() == startOffset && elementAt.getTextRange().getEndOffset() == endOffset) {
            return new PsiElement[] { elementAt };
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) CfmlLanguage(com.intellij.coldFusion.model.CfmlLanguage) CfmlReferenceExpression(com.intellij.coldFusion.model.psi.CfmlReferenceExpression) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileViewProvider (com.intellij.psi.FileViewProvider)41 PsiFile (com.intellij.psi.PsiFile)22 Language (com.intellij.lang.Language)21 PsiElement (com.intellij.psi.PsiElement)15 NotNull (org.jetbrains.annotations.NotNull)12 TextRange (com.intellij.openapi.util.TextRange)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)5 Project (com.intellij.openapi.project.Project)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 Pair (com.intellij.openapi.util.Pair)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)2 FileASTNode (com.intellij.lang.FileASTNode)2 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)2 FileType (com.intellij.openapi.fileTypes.FileType)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)2