### Setup Custom SDK Paths with SdkModificator (Java) Source: https://docs.namichong.com/intellij-platform-sdk/sdk Provides an example of how to set up paths for a custom SDK. It involves modifying the SDK using `SdkModificator` and committing changes to make them persistent. This is part of creating a custom `SdkType`. ```java @Override public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) { SdkModificator modificator = sdk.getSdkModificator(); modificator.setVersionString(getVersionString(sdk)); modificator.commitChanges(); // save return true; } ``` -------------------------------- ### Java Surround With Live Template Example Source: https://docs.namichong.com/intellij-platform-sdk/live-templates Illustrates a Live Template for surrounding selected Java code with an enhanced for loop. This example shows how to wrap an existing method call with an 'Iterable' or array iteration construct. ```java public void testMethod() { for (Action action : getActions()) { } } ``` -------------------------------- ### IntelliJ Platform SDK plugin.xml Configuration Order Source: https://docs.namichong.com/intellij-platform-sdk/sdk-code-guidelines The standard order of elements within the plugin.xml configuration file for SDK code examples. This promotes consistency and highlights essential configuration. ```xml ``` -------------------------------- ### IntelliJ Platform SDK Copyright Notice Source: https://docs.namichong.com/intellij-platform-sdk/sdk-code-guidelines This is the standard copyright notice to be used in all example plugins written by JetBrains. It ensures consistent licensing and attribution across SDK examples. ```plaintext Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. ``` -------------------------------- ### Markdown Annotation with Title and Style Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Shows how to create a Markdown annotation with both a title and a specific style. This is useful for complex annotations where a clear heading is needed. ```markdown > 这是一个注释。 > 我们有很多文字。 > 通过添加一个好的标题,不要让每个人完全阅读它。 > > {title="一个有用的标题"} ``` -------------------------------- ### Setup Default Repositories with mavenCentral() Source: https://docs.namichong.com/intellij-platform-sdk/tools-intellij-platform-gradle-plugin-repositories-extension Configures Maven Central and default IntelliJ Platform repositories. This is a common setup for building plugins and running standard tasks. ```kotlin repositories { mavenCentral() intellijPlatform { defaultRepositories() } } ``` ```groovy repositories { mavenCentral() intellijPlatform { defaultRepositories() } } ``` -------------------------------- ### Empty State Implementation Example Source: https://docs.namichong.com/intellij-platform-sdk/empty-state Demonstrates the basic structure for implementing an empty state message within a UI component. This example uses Java, common in IntelliJ Platform plugin development, and shows how to provide instructional text. ```java public class ComponentWithEmptyText extends JPanel { // ... constructor and other methods ... public void showEmptyState() { removeAll(); // Clear existing components setLayout(new BorderLayout()); JLabel emptyLabel = new JLabel("No data available. Add new items to get started.", SwingConstants.CENTER); emptyLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.ITALIC)); add(emptyLabel, BorderLayout.CENTER); revalidate(); repaint(); } public void showContent() { removeAll(); // Add actual content components here setLayout(new BorderLayout()); add(new JLabel("Content goes here", SwingConstants.CENTER), BorderLayout.CENTER); revalidate(); repaint(); } } ``` -------------------------------- ### CLion Plugin Gradle Build Script Setup (Kotlin) Source: https://docs.namichong.com/intellij-platform-sdk/clion Configures a Gradle build script for CLion plugin development. It specifies repositories, declares dependencies on the CLion platform using `clion()`, and includes bundled CLion plugins using `bundledPlugin()`. This setup is essential for targeting CLion specifically. ```kotlin repositories { mavenCentral() intellijPlatform { defaultRepositories() } } dependencies { intellijPlatform { clion("") bundledPlugin("com.intellij.clion") } } ``` -------------------------------- ### IntelliJ Platform SDK Gradle Plugin Check Example Source: https://docs.namichong.com/intellij-platform-sdk/using-kotlin This example shows how to use Gradle tasks to verify plugin configuration, specifically checking for the presence of the `kotlin.stdlib.default.dependency` property. The `verifyPlugin` task from the IntelliJ Platform Gradle Plugin (2.x) or Gradle IntelliJ Plugin (1.x) will report a warning if the property is absent, ensuring correct plugin setup. This is crucial for managing Kotlin stdlib dependencies. ```gradle // Example Gradle task for verification (specific implementation may vary) task verifyPluginConfiguration(type: VerifyPlugin) { // ... configuration ... } ``` -------------------------------- ### Java For Loop Live Template Example Source: https://docs.namichong.com/intellij-platform-sdk/live-templates Demonstrates a Live Template for a Java 'for' loop. Typing 'fori' followed by Tab expands to a common loop structure, with placeholders for cursor navigation. ```java for (int i = [|]; i < []; i++) { [] } ``` -------------------------------- ### Get Application and Project Services (Java) Source: https://docs.namichong.com/intellij-platform-sdk/plugin-services Demonstrates how to obtain application-level and project-level service instances using the `ApplicationManager` and `project.getService()` methods in Java. Direct retrieval is recommended over storing instances in fields. ```java MyAppService applicationService = ApplicationManager.getApplication().getService(MyAppService.class); MyProjectService projectService = project.getService(MyProjectService.class); ``` -------------------------------- ### Formatting File Paths Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style File paths should be enclosed in `` tags. This clearly delineates file system locations within the documentation. ```markdown build.gradle.kts ``` -------------------------------- ### Formatting Keyboard Shortcuts Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Keyboard shortcuts should be enclosed in `` tags. This provides a consistent visual representation for key combinations used to perform actions. ```markdown press Alt+Insert ``` -------------------------------- ### Basic Markdown Table Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Illustrates the syntax for creating a simple Markdown table using pipe symbols and hyphens. Special handling is required for pipe characters within cell content. ```markdown | Column 1 | Column 2 | Column 3 | |----------|----------|----------| | Blah | Blah | Blah | ``` -------------------------------- ### Get Application and Project Services (Kotlin) Source: https://docs.namichong.com/intellij-platform-sdk/plugin-services Illustrates how to obtain application-level and project-level service instances using Kotlin extension functions like `service<>()` and `project.service<>()`. This provides a concise way to access services in Kotlin. ```kotlin val applicationService = service() val projectService = project.service() ``` -------------------------------- ### Search for Module-Containing Path using IntelliJ Platform SDK Source: https://docs.namichong.com/intellij-platform-sdk/workspace-model-usages Demonstrates how to find the `ModuleEntity` associated with a given file URL (content root or source root). It uses the `VirtualFileUrlIndex` to search for entities by URL. ```kotlin val workspaceModel = WorkspaceModel.getInstance(project) val virtualFileUrl = workspaceModel.getVirtualFileUrlManager() .getOrCreateFromUrl("file://foo/bar/src") workspaceModel.currentSnapshot.getVirtualFileUrlIndex() .findEntitiesByUrl(virtualFileUrl) .mapNotNull { if (it is SourceRootEntity) { it.contentRoot.module } else if (it is ContentRootEntity) { it.module } else { null } } ``` -------------------------------- ### Page Excerpt with Link Summary Tag Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Each page should include a brief excerpt using the `` tag before the main content. This summary, typically a single sentence, provides a concise description of the page's topic for quick reference in navigation elements. ```markdown Defines a group of related settings. ``` -------------------------------- ### Postfix Template Implementation Example Source: https://docs.namichong.com/intellij-platform-sdk/postfix-templates Demonstrates the basic implementation of a custom postfix template by extending the `PostfixTemplate` class. Key methods `isApplicable()` and `expand()` must be implemented to define when the template can be used and how it modifies the code. ```java public abstract class PostfixTemplate { public abstract boolean isApplicable(@NotNull PsiElement context, @NotNull Document document, int offset); public abstract void expand(@NotNull PsiElement context, @NotNull Editor editor); // ... other methods } ``` -------------------------------- ### Linking to Declarative Source Code Files Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Declarative source code files (e.g., XML, Gradle scripts) are linked using the `%gh-ic%` prefix and formatted with `code` style. Examples include `plugin.xml` and `settings.gradle`. ```markdown [IdeaPlugin.xml](%gh-ic%/community-resources/resources/META-INF/IdeaPlugin.xml) ``` -------------------------------- ### IntelliJ Platform SDK Gradle Build Script Modifications Source: https://docs.namichong.com/intellij-platform-sdk/sdk-code-guidelines Modifications required for the default build.gradle.kts file generated by the New Project Wizard for SDK code examples. These ensure proper versioning and compatibility settings. ```kotlin // Patches value in plugin.xml version.set(project.version) sinceBuild.set("221") untilBuild.set("223.*") ``` -------------------------------- ### Java Postfix Template 'var' Example Source: https://docs.namichong.com/intellij-platform-sdk/postfix-templates Illustrates the 'before' and 'after' states of a Java postfix template for variable declaration using the `` marker for code highlighting and cursor positioning. The `$key` placeholder is also shown for previewing the template key. ```template cart.getProducts().var ``` ```template List products = cart.getProducts(); ``` ```template cart.getProducts()$key ``` ```template cart.getProducts().var ``` -------------------------------- ### Formatting Extension Points (EPs) Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Extension point (EP) names should include 'extension point (EP)' on first mention, followed by 'EP' in subsequent mentions. Use FQN for the initial mention of an EP, then shorthand. ```markdown Introduced `com.intellij.stubIndex` (extension point (EP)). Subsequent mention: `stubIndex` (EP). ``` -------------------------------- ### Linking to SDK Documentation Pages and Sections Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Links to pages within the SDK documentation use the `.md` extension. Links to specific sections on a page use anchors, with spaces replaced by hyphens. Empty link labels automatically use the page or section title. ```markdown [Page Title](page.md) [](page.md) [Link to a section on the current page](#another-section) [Link to a section on another page](other_page.md#another-section) ``` -------------------------------- ### Define Helper Methods for PSI Elements (Java) Source: https://docs.namichong.com/intellij-platform-sdk/reference-contributor This Java code snippet demonstrates helper methods within `SimplePsiImplUtil` for managing named elements in the Simple Language. It includes methods for getting and setting the name of a property, and getting the name identifier. It relies on `SimpleElementFactory` which is defined in a subsequent step. ```java public class SimplePsiImplUtil { // ... public static String getName(SimpleProperty element) { return getKey(element); } public static PsiElement setName(SimpleProperty element, String newName) { ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); if (keyNode != null) { SimpleProperty property = SimpleElementFactory.createProperty(element.getProject(), newName); ASTNode newKeyNode = property.getFirstChild().getNode(); element.getNode().replaceChild(keyNode, newKeyNode); } return element; } public static PsiElement getNameIdentifier(SimpleProperty element) { ASTNode keyNode = element.getNode().findChildByType(SimpleTypes.KEY); return keyNode != null ? keyNode.getPsi() : null; } // ... } ``` -------------------------------- ### 在 plugin.xml 中声明可选插件依赖 Source: https://docs.namichong.com/intellij-platform-sdk/plugin-dependencies 使用 `optional="true"` 和 `config-file` 属性在 `plugin.xml` 中声明可选插件依赖。`config-file` 属性指向可选插件描述文件的路径。 ```xml dependency.plugin.id ``` -------------------------------- ### Get Application and Project Services with getInstance (Java) Source: https://docs.namichong.com/intellij-platform-sdk/plugin-services Shows how service implementations can provide convenient static `getInstance()` or `getInstance(Project)` methods to simplify the retrieval process in Java. This is an alternative to direct calls to `ApplicationManager` or `project.getService()`. ```java MyAppService applicationService = MyAppService.getInstance(); MyProjectService projectService = MyProjectService.getInstance(project); ``` -------------------------------- ### Setup Project Structure for New Module - Java Source: https://docs.namichong.com/intellij-platform-sdk/project-wizard This Java code snippet demonstrates how to implement `setupProjectStructure()` to create a new module if no other modules exist in the project. It iterates through detected project roots and creates `ModuleDescriptor` objects. This functionality is crucial for integrating custom module types into the IntelliJ Platform. ```java @Override public void setupProjectStructure(@NotNull Collection roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) { List modules = projectDescriptor.getModules(); if (modules.isEmpty()) { modules = new ArrayList<>(); for (DetectedProjectRoot root : roots) { modules.add(new ModuleDescriptor(root.getDirectory(), MyModuleType.getInstance(), ContainerUtil.emptyList())); } projectDescriptor.setModules(modules); } } ``` -------------------------------- ### Escaping Placeholders in Paths Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style When a placeholder like `$PLACEHOLDER$` appears in a non-code context within a file path, it must be escaped using backslashes. ```markdown \$PLACEHOLDER\$/somePath ``` -------------------------------- ### Get and Set Project SDK Name with ProjectRootManager (Java) Source: https://docs.namichong.com/intellij-platform-sdk/sdk Demonstrates how to retrieve and set the name of the project-level SDK. This is useful for identifying or configuring the SDK used by the project. ```java String projectSdkName = ProjectRootManager.getInstance(project).getProjectSdkName(); ProjectRootManager.getInstance(project).setProjectSdkName(name, sdk.getSdkType().getName()); ``` -------------------------------- ### Markdown Annotation with Style Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Demonstrates how to create a Markdown annotation with a specific style (e.g., 'note'). Blockquotes are used, followed by a style attribute in curly braces. Supported styles include 'tip', 'note', and 'warning'. ```markdown > 这是一个简单的注释。 > > {style="note"} ``` -------------------------------- ### Get All Module Libraries (Java) Source: https://docs.namichong.com/intellij-platform-sdk/library Obtains a list of all libraries defined specifically for a given module using the OrderEntryUtil. This is a direct way to query module-specific library definitions. ```java OrderEntryUtil.getModuleLibraries(ModuleRootManager.getInstance(module)); ``` -------------------------------- ### Implement Implicit References with ImplicitReferenceProvider (Java) Source: https://docs.namichong.com/intellij-platform-sdk/declarations-and-references This example outlines how to implement and register `ImplicitReferenceProvider` to define implicit references. These are references where the target is easily obtainable (e.g., via Ctrl-Click), but the reference itself is not typically searched or renamed from the target's perspective, such as the `var` keyword. ```java public interface ImplicitReferenceProvider { @NotNull PsiSymbolReference[] getImplicitReferences(@NotNull PsiElement element); } ``` -------------------------------- ### Get Libraries a Module Depends On (Java) Source: https://docs.namichong.com/intellij-platform-sdk/library Retrieves and displays the names of all libraries that a specific module depends on using the OrderEnumerator API. This is useful for understanding module dependencies. ```java List libraryNames = new ArrayList<>(); ModuleRootManager.getInstance(module).orderEntries().forEachLibrary(library -> { libraryNames.add(library.getName()); return true; }); Messages.showInfoMessage(StringUtil.join(libraryNames, "\n"), "Libraries in Module"); ``` -------------------------------- ### Formatting Non-Code Keywords and Filenames Source: https://docs.namichong.com/intellij-platform-sdk/sdk-style Non-code keywords, general terms, and filenames that are not code should be formatted in italics. This distinguishes them from code elements and programming language keywords. ```markdown Theme (*Theme*), README.md (*README.md*) ``` -------------------------------- ### Get Project SDK Information with ProjectRootManager (Java) Source: https://docs.namichong.com/intellij-platform-sdk/sdk Retrieves the project's SDK using the `ProjectRootManager` class. This method is used to access the SDK object associated with the current project. ```java Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk(); ``` -------------------------------- ### Java Line Marker Provider Implementation Example Source: https://docs.namichong.com/intellij-platform-sdk/line-marker-provider Demonstrates the correct and incorrect ways to implement a LineMarkerProvider in Java. The incorrect version returns information for a PsiMethod, leading to blinking icons. The correct version returns information for PsiIdentifier, ensuring proper marker display. ```java final class MyWrongLineMarkerProvider implements LineMarkerProvider { public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (element instanceof PsiMethod) { return new LineMarkerInfo(element, ...); } return null; } } ``` ```java final class MyCorrectLineMarkerProvider implements LineMarkerProvider { public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (element instanceof PsiIdentifier && element.getParent() instanceof PsiMethod) { return new LineMarkerInfo(element, ...); } return null; } } ```