Search in sources :

Example 61 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class GroovyPositionManager method findReferenceTypeSourceImage.

@Nullable
private static GroovyPsiElement findReferenceTypeSourceImage(SourcePosition position) {
    PsiFile file = position.getFile();
    if (!(file instanceof GroovyFileBase))
        return null;
    PsiElement element = file.findElementAt(position.getOffset());
    if (element == null)
        return null;
    return PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class);
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class GroovyScriptClassSearcher method findClass.

@Nullable
@Override
public PsiClass findClass(@NotNull PsiElement place) {
    if (place.getLanguage() == GroovyLanguage.INSTANCE) {
        PsiClass containingClass = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
        while (containingClass instanceof PsiTypeParameter) {
            containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
        }
        if (containingClass != null)
            return containingClass;
        PsiFile file = place.getContainingFile();
        if (file instanceof GroovyFile && ((GroovyFile) file).isScript()) {
            return ((GroovyFile) file).getScriptClass();
        }
    }
    return null;
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class GrImportFilteringRule method isVisible.

@Override
public boolean isVisible(@NotNull Usage usage) {
    if (usage instanceof PsiElementUsage) {
        final PsiElement psiElement = ((PsiElementUsage) usage).getElement();
        final PsiFile containingFile = psiElement.getContainingFile();
        if (containingFile instanceof GroovyFile) {
            // check whether the element is in the import list
            return PsiTreeUtil.getParentOfType(psiElement, GrImportStatement.class, true) == null;
        }
    }
    return true;
}
Also used : PsiFile(com.intellij.psi.PsiFile) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) PsiElement(com.intellij.psi.PsiElement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage)

Example 64 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class XsltBreakpointHandler method getActualLineNumber.

public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
    if (position == null) {
        return -1;
    }
    final PsiElement element = findContextElement(project, position);
    if (element == null) {
        return -1;
    }
    if (element instanceof XmlToken) {
        final IElementType tokenType = ((XmlToken) element).getTokenType();
        if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
            final PsiManager psiManager = PsiManager.getInstance(project);
            final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
            final PsiFile psiFile = psiManager.findFile(position.getFile());
            if (psiFile == null) {
                return -1;
            }
            final Document document = documentManager.getDocument(psiFile);
            if (document == null) {
                return -1;
            }
            if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
                final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
                if (tag != null) {
                    final ASTNode node = tag.getNode();
                    assert node != null;
                    // TODO: re-check if/when Xalan is supported
                    final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
                    if (end != null) {
                        return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
                    } else {
                        final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
                        if (end2 != null) {
                            return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
                        }
                    }
                }
            }
        }
    }
    return -1;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 65 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyTemporaryInjector method getInjectedLanguage.

@Nullable
@Override
public Language getInjectedLanguage(@NotNull PsiElement context) {
    final TemporaryPlacesRegistry registry = TemporaryPlacesRegistry.getInstance(context.getProject());
    if (context instanceof PsiLanguageInjectionHost) {
        final PsiFile file = context.getContainingFile();
        final InjectedLanguage injectedLanguage = registry.getLanguageFor((PsiLanguageInjectionHost) context, file);
        if (injectedLanguage != null) {
            return injectedLanguage.getLanguage();
        }
    }
    return null;
}
Also used : TemporaryPlacesRegistry(org.intellij.plugins.intelliLang.inject.TemporaryPlacesRegistry) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiFile (com.intellij.psi.PsiFile)1785 VirtualFile (com.intellij.openapi.vfs.VirtualFile)496 PsiElement (com.intellij.psi.PsiElement)468 Project (com.intellij.openapi.project.Project)267 Nullable (org.jetbrains.annotations.Nullable)267 NotNull (org.jetbrains.annotations.NotNull)248 Document (com.intellij.openapi.editor.Document)181 Editor (com.intellij.openapi.editor.Editor)168 XmlFile (com.intellij.psi.xml.XmlFile)126 PsiDirectory (com.intellij.psi.PsiDirectory)114 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)109 Module (com.intellij.openapi.module.Module)108 TextRange (com.intellij.openapi.util.TextRange)88 ArrayList (java.util.ArrayList)84 XmlTag (com.intellij.psi.xml.XmlTag)68 File (java.io.File)58 PsiManager (com.intellij.psi.PsiManager)56 PsiClass (com.intellij.psi.PsiClass)51 List (java.util.List)46 Language (com.intellij.lang.Language)45