diff --git a/topics/basics/faq.md b/topics/basics/faq.md index 20ae385c3..c64068056 100644 --- a/topics/basics/faq.md +++ b/topics/basics/faq.md @@ -11,25 +11,6 @@ See [](getting_help.topic#problems-with-code-support-issues) on how to post new > See also [](explore_api.md) for more information and strategies. > -## Accessing and Modifying the Source Code - -> See also [](psi.md) and [](psi_cookbook.md) - -* [How do I find all subclasses of a class?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206791895-finding-all-derived-class-given-parent-class) -* [How do I find all anonymous classes created in a class?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206792205-How-to-find-anonymous-classes-in-PsiClass-) -* [How do I calculate the value of a string literal token?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206139829-How-to-evaluate-the-value-of-PsiJavaToken-of-STRING-LITERAL-type) -* [How do I rename or move a Java class?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206791825-How-to-rename-a-class-) -* [How do I build the list of all classes used by a given class or package?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206139469-Using-DependencyValidationManager-to-Get-Required-Classes) -* [How do I insert whitespace into the PSI?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206143839-Adding-PsiElements-to-a-PsiFile) -* [How do I add properties to a .properties file?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206142279-Dynamically-add-new-properties-to-properties-files) -* [How do I find specific method calls inside a PsiMethod?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206143579-finding-a-statement-within-a-PsiMethod) -* [What is the lifecycle of a PSI element?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206796015-What-is-the-lifecycle-of-a-PsiElement-) -* [How do I create a new class in the given package?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206771665-Creating-a-new-class) -* [How do I make a PsiClass extend another PsiClass?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206794255-How-to-make-a-PsiClass-derive-from-another-one-) -* [How do I find references to a class from non-Java files?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206800695-How-to-obtain-the-references-to-a-class-from-non-java-files-) -* [How do I find the source file given the path to a .class file?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206800595-How-to-find-the-source-for-a-class-file) -* [How do I find classes with the specified non-qualified name?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206146759-How-to-resolve-unqualified-name-to-possible-PsiClasses-) - ## Working with XML and XML DOM * [How do I change the value of an XML attribute through the PSI?](https://intellij-support.jetbrains.com/hc/en-us/community/posts/206139639-Change-xml-attribute-value) diff --git a/topics/basics/psi_cookbook.md b/topics/basics/psi_cookbook.md index d8fffbb2b..2169bbe66 100644 --- a/topics/basics/psi_cookbook.md +++ b/topics/basics/psi_cookbook.md @@ -69,7 +69,19 @@ or [`OverridingMethodsSearch.search()`](%gh-ic%/java/java-indexing-api/src/com/intellij/psi/search/searches/OverridingMethodsSearch.java) +### How do I create a new class/interface/enum/record in a given directory? + +Use methods from [`JavaDirectoryService`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/JavaDirectoryService.java). + +### How can I locate specific Java PSI elements within a class/method? + +Extend [`JavaElementVisitor`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/JavaElementVisitor.java) +or [`JavaRecursiveElementVisitor`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/JavaRecursiveElementVisitor.java) and override relevant method(s). +Pass it to `PsiElement.accept()` of the parent PSI element (for example, [`PsiClass`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/PsiClass.java) +or [`PsiMethod`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/PsiMethod.java)). + ### How do I check the presence of a JVM library? + Use dedicated (and heavily cached) methods from [`JavaLibraryUtil`](%gh-ic%/java/openapi/src/com/intellij/java/library/JavaLibraryUtil.java):