官方FAQ(非常重要)——idea插件开发
/ / 阅读耗时预计 7 分钟Plugin Development FAQ
This FAQ is a topical index of questions that have been asked (and answered) on our IntelliJ IDEA Open API and Plugin Development forum.
Open-Source Plugins
Open-Source Plugins
- How do I trigger actions programmatically?
- How do I add a main menu item?
- How do I customize the “New…” menu?
- How do I customize the compiler output context menu?
- How do I get the context of an action (selected file, active project etc.)?
- How do I change the icon of an action dynamically?
- How do I add icons to the IDEA toolbar?
- Where do I get the list of built-in action IDs?
Accessing and Modifying the Source Code
- PSI Architectural Overview
- How do I find all subclasses of a class?
- How do I find all anonymous classes created in a class?
- How do I calculate the value of a string literal token?
- How do I rename or move a Java class?
- How do I build the list of all classes used by a given class or package?
- How do I insert whitespace into the PSI?
- How do I add properties to a .properties file?
- How do I find specific method calls inside a PsiMethod?
- What is the lifecycle of a PSI element?
- How do I find a file given its name (but no path)?
- How do I create a new class in the given package?
- How do I make a PsiClass extend another PsiClass?
- How do I find references to a class from non-Java files?
- How do I find the source file given the path to a .class file?
- How do I find classes with the specified non-qualified name?
- How do I find the module in which a class is located?
- PSI Cookbook
Working with XML and XML DOM
- How do I change the value of an XML attribute through the PSI?
- How do I add custom references to Java elements in XML files?
- How do I programmatically register a DTD or schema?
- What is the “strict” parameter in DomElement.getParentOfType()?
Code Completion
- How do I determine what type of code completion was invoked?
- How do I provide additional code completion in specific places of a Java file?
Refactoring
- How can I receive notifications about refactoring events?
- How do I show a refactoring dialog programmatically?
Run/Debug
How do I implement a custom run configuration?
Make/Compile
How do I get access to class files generated by javac?
Version Control Integration
- Can I provide line status markers for files in a custom file system?
- How do I update the state of VCS actions depending on file status?
- How can I find out the module of a deleted file?
- Can I provide additional decorations for changelists in the Changes view?
- How do I report out-of-date files?
Test Framework
How do I create a library dependency in my test module?
Plugin Architecture
- How do I provide a custom exception reporter for my plugin?
- How can I add the help topics of my plugin to the IntelliJ Platform help system?
- How do I get the version of IntelliJ Platform under which my plugin is running?
Editors, Documents and Files
- Why doesn’t the file change on disk after I changed it through the PSI?
- Can I hook into the file save logic?
- Can I mark a part of a file as read-only?
- How do I control what happens when the user tries to edit such a part?
- How do I implement a custom editor?
- How can I show several editors for a single file in tabs?
- Can I open an editor which has no underlying file on disk?
- How do I save the content of my custom editor when the user saves all documents?
- How do I highlight elements in a source code editor?
- How do I allow to navigate between highlighted elements using Find Next?
- How do I force code to be re-analyzed?
- How do I get the active editor instance?
- How do I get the cursor position in the current editor?
- How do I clear the read-only status of a file?
- How do I show a popup hint in an editor?
- How do I create live template-like red box edit regions in an editor?
- How can I show an editor with error highlighting in a tool window?
Inspections
- Can I build an inspection that processes XML files?
- Why are the inspection results shown multiple times?
- How can I provide a quick fix that creates a method?
- Is it possible to inspect only the elements that have been modified after the last full inspection?
- ExternalAnnotator not in sync with current editor
Project Structure
- Can I add a new module dependency storage format?
- What is the Pair to be passed to JavaModuleBuilder.setSourcePaths()?
- How do I access all configured JDKs?
Custom Languages
- How do I provide Parameter Info support for my language?
- How do I provide auto-popup code completion in my language?
- How to make a closing brace unindent?
- How to automatically insert closing quotes?
- How do I provide Ctrl+mouse popups for my language?
- How do I enable debugging for my custom language which is compiled into Java?
- How do I generate virtual Java classes mirroring the classes of my language?
User Interface
- How do I provide animated status bar notifications?
- How do I enable file name completion in a combobox?
- How do I show a popup with left-aligned and right-aligned parts for each item?
- Can I use an embedded Web browser from my plugin?
- How do I provide a custom icon for files/PSI elements?
- Can I show a progress indicator for WriteActions?
- How do I make it possible to search the options of my plugin in the Settings dialog?
- How do I show a custom window or popup based on Structure View?
- Is it possible to extend the Project View tree?
- How do I show the “Project Structure” dialog programmatically?
- How do I print messages in the console view?
- How do I show the package selector dialog programmatically?
- How do I provide syntax and error highlighting in a combo box editor?
- How can I get notified when my tool window is activated?
- How can I provide Close and Rerun buttons in my Usage View window?
- How can I display the SDK list in a JComboBox?