forked from AlanFoster/Camelry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add useful code snippets for developers
- Loading branch information
1 parent
2768bc9
commit bb3f7f5
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Useful References | ||
================== | ||
|
||
Find Module for PsiElement | ||
|
||
```java | ||
Module moduleForDomElement = ModuleUtil.findModuleForPsiElement(domElement.getXmlElement()); | ||
Module moduleForPsiFile = ModuleUtil.findModuleForPsiElement(psiFile); | ||
``` | ||
|
||
Find virtual files by type | ||
|
||
```java | ||
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles( | ||
FileTypeIndex.NAME, StdFileTypes.JAVA, GlobalSearchScope.moduleScope(moduleForPsiElement)); | ||
``` | ||
|
||
Get JavaPsiFile with Module scope from VirtualFile | ||
|
||
```java | ||
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 | ||
|
||
```java | ||
final PsiClass psiClass = JavaPsiFacade.getInstance(module.getProject()) | ||
.findClass("fully.qualified.name.Foo", module.getModuleWithDependenciesAndLibrariesScope(true)); | ||
``` |