Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.11 KB

cheatSheet.md

File metadata and controls

37 lines (26 loc) · 1.11 KB

Useful References

Find Module for PsiElement

Module moduleForDomElement = ModuleUtil.findModuleForPsiElement(domElement.getXmlElement());
Module moduleForPsiFile = ModuleUtil.findModuleForPsiElement(psiFile);

Find virtual files by type

Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(
        FileTypeIndex.NAME, StdFileTypes.JAVA, GlobalSearchScope.moduleScope(moduleForPsiElement));

Get JavaPsiFile with Module scope from VirtualFile

Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(
        FileTypeIndex.NAME, StdFileTypes.JAVA, GlobalSearchScope.moduleScope(module));

VirtualFile virtualFile = virtualFiles.iterator().next();

PsiFile file = PsiManager.getInstance(project)
             .findFile(virtualFile);

PsiJavaFile javaFile = (PsiJavaFile) file;

Find Java class by name, with specified scope

final PsiClass psiClass = JavaPsiFacade.getInstance(module.getProject())
        .findClass("fully.qualified.name.Foo", module.getModuleWithDependenciesAndLibrariesScope(true));