<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zhiying Wang on Medium]]></title>
        <description><![CDATA[Stories by Zhiying Wang on Medium]]></description>
        <link>https://medium.com/@zhiying.wang?source=rss-340cf8d62fb8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*n7lPu_l7m7vEZa46</url>
            <title>Stories by Zhiying Wang on Medium</title>
            <link>https://medium.com/@zhiying.wang?source=rss-340cf8d62fb8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:14:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zhiying.wang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Intellij IDEA Plugin Development Note]]></title>
            <link>https://medium.com/@zhiying.wang/intellij-idea-plugin-development-note-3cec34a930d4?source=rss-340cf8d62fb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cec34a930d4</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[intellij-plugin]]></category>
            <dc:creator><![CDATA[Zhiying Wang]]></dc:creator>
            <pubDate>Wed, 19 Oct 2022 09:05:34 GMT</pubDate>
            <atom:updated>2022-10-19T09:39:30.139Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Official Development Guide</em></p><p><a href="https://plugins.jetbrains.com/docs/intellij/developing-plugins.html">Developing a Plugin | IntelliJ Platform Plugin SDK</a></p><p><em>For Chinese developers，the following site might be better to read</em></p><p><a href="https://kana112233.github.io/intellij-sdk-docs-cn/welcome.html">IntelliJ Platform SDK</a></p><p>Q:How to build a Dialog?</p><p>A:define a class which extends DialogWrapper class，override <em>createCenterPanel </em>to build the dialog’s content，override <em>createActions</em> to build the dialog’s buttons</p><p>caution! the init() method must be called in an appropriate time ;otherwise，your dialog might only show the menu bar without any content.</p><pre><em>init </em>{<br>    <em>//call init method<br>    </em>init()<br>    <em>val </em>projectName = FileUtil.getProjectName(project)<br>    <em>title </em>= &quot;New${projectName}Module&quot;<br>    setSize(640, 80)<br>}</pre><p>Q:How to sync project automatically?</p><p>A:use GradleSyncExecutor</p><pre><em>fun </em>sync(project: <em>Project</em>) {<br>    FileDocumentManager.getInstance().saveAllDocuments()<br>    VirtualFileManager.getInstance().syncRefresh()<br>    VirtualFileManager.getInstance().refreshWithoutFileWatcher(<em>true</em>)<br>    <em>val </em>apiDir = project.<em>basePath </em>?: <em>return<br>    </em>VfsUtil.markDirtyAndRefresh(<em>true</em>, <em>true</em>, <em>true</em>, File(apiDir))<br>    GradleSyncExecutor(project).sync(<br>        GradleSyncInvoker.Request(GradleSyncStats.Trigger.<em>TRIGGER_USER_SYNC_ACTION</em>),<br>        <em>null<br>    </em>)<br>}</pre><p>Q:How to get your current selected project file directory path?</p><p>A:call AnActionEvent’s getData method(it can be found in <em>com.intellij.openapi.roots.ui.configuration.actions.NewModuleAction</em>) ,the parameter key is <em>CommonDataKeys.VIRTUAL_FILE, </em>get virtualFile object，the path field is what you want.</p><pre><em>class XXX</em>CustomModuleAction: AnAction() {<br>    <em>override fun </em>actionPerformed(e: AnActionEvent) {<br>        <em>val </em>project = getEventProject(e) ?: <em>return<br>        val </em>projectPath  = project.<em>basePath</em>?: <em>return<br>        var </em>defaultPath: String? = <em>null<br>        val </em>virtualFile = e.getData(CommonDataKeys.<em>VIRTUAL_FILE</em>)<br>        <em>if </em>(virtualFile != <em>null </em>&amp;&amp; virtualFile.<em>isDirectory</em>) {<br>            defaultPath = virtualFile.<em>path<br>        </em>}<br>        <em>if</em>(defaultPath == <em>null</em>){<br>            defaultPath =  projectPath<br>        }<br>        <em>//relative path just like `/biz/live` or empty,means root dir<br>        val </em>relativePath = defaultPath.<em>removePrefix</em>(projectPath)<br>        XXXDialog(project,relativePath).showAndGet()<br>    }<br>}</pre><p>Q:How to display a long long vertical data list</p><p>A: use JBScrollPane,for example jList contains many custom item views</p><pre><em>override fun </em>createCenterPanel(): JComponent {<br>    <em>val </em>centerPanel = JPanel(VerticalLayout(10, <em>SwingConstants</em>.<em>CENTER</em>))<br>    jList.<em>forEach </em><strong>{<br>        </strong>centerPanel.add(<strong>it</strong>)<br>    <strong>}<br>    </strong><em>return </em>JBScrollPane(<br>        centerPanel,<br>        <em>ScrollPaneConstants</em>.<em>VERTICAL_SCROLLBAR_ALWAYS</em>,<br>        <em>ScrollPaneConstants</em>.<em>HORIZONTAL_SCROLLBAR_NEVER<br>    </em>)<br>}</pre><p>Q:In some situations，you want to read a kotlin file content ,and then, make some useful functions ,how could you do to realize it?</p><p>A:use kotlin-compiler-embeddable(e.g version 1.6.10),which provide APIs that can scan kotlin file content,then analysis the content into PSI Elements(What is PSI?reference:<a href="https://plugins.jetbrains.com/docs/intellij/psi.html?from=jetbrains.org">https://plugins.jetbrains.com/docs/intellij/psi.html?from=jetbrains.org</a>)</p><pre><em>dependencies{</em><strong><br>    </strong><em>implementation</em>(&quot;org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.10&quot;)<br>    <em>implementation</em>(&quot;org.jetbrains.kotlin:kotlin-stdlib:1.6.10&quot;)<br>    <em>implementation</em>(&quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8&quot;)<br><strong>}</strong></pre><p>caution! meanwhile <em>,</em>you must use the newest <em>intellij gradle plugin</em></p><pre>plugins <strong>{<br>    </strong><em>// Java support<br>    </em>id(&quot;java&quot;)<br>    <em>// Kotlin support<br>    </em>id(&quot;org.jetbrains.kotlin.jvm&quot;) <em>version </em>&quot;1.6.10&quot;<br>    <em>// Gradle IntelliJ Plugin<br>    </em>id(&quot;org.jetbrains.intellij&quot;) <em>version </em>&quot;1.9.0&quot; &lt;------- make sure  u are using the newest version<br>    <em>// Gradle Changelog Plugin<br>    </em>id(&quot;org.jetbrains.changelog&quot;) <em>version </em>&quot;1.3.1&quot;<br>    <em>// Gradle Qodana Plugin<br>    </em>id(&quot;org.jetbrains.qodana&quot;) <em>version </em>&quot;0.1.13&quot;<br><strong>}</strong></pre><p><em>Intellij gradle plugin Release Note:</em></p><p><a href="https://github.com/JetBrains/gradle-intellij-plugin/releases">https://github.com/JetBrains/gradle-intellij-plugin/releases</a></p><p>Q:An error occurred when i construct an KotlinCoreEnvironment object</p><p>the code just like:</p><pre><em>private val project by lazy </em><strong>{<br>    </strong>KotlinCoreEnvironment.createForProduction(<br>        Disposer.newDisposable(),<br>        CompilerConfiguration(),<br>        EnvironmentConfigFiles.<em>JVM_CONFIG_FILES<br>    </em>).project<br><strong>}</strong></pre><p>the error just like:</p><p>Exception in thread “main” java.lang.IllegalStateException: LOGGING: Loading modules: [java.se, jdk.accessibility, jdk.attach, jdk.compiler, jdk.dynalink, jdk.httpserver, jdk.jartool, jdk.javadoc, jdk.jdi, jdk.jfr, jdk.jsobject, jdk.management, jdk.management.jfr, jdk.net, jdk.scripting.nashorn, jdk.sctp, jdk.security.auth, jdk.security.jgss, jdk.unsupported, jdk.xml.dom, java.base, java.compiler, java.datatransfer, java.desktop, java.xml, java.instrument, java.logging, java.management, java.management.rmi, java.rmi, java.naming, java.net.http, java.prefs, java.scripting, java.security.jgss, java.security.sasl, java.sql, java.transaction.xa, java.sql.rowset, java.xml.crypto, jdk.internal.jvmstat, jdk.jdwp.agent] (no MessageCollector configured)<br> at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.report(ClasspathRootsResolver.kt:312)<br> at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.report$default(ClasspathRootsResolver.kt:310)<br> at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.addModularRoots(ClasspathRootsResolver.kt:253)<br> at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.computeRoots(ClasspathRootsResolver.kt:123)<br> at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.convertClasspathRoots(ClasspathRootsResolver.kt:79)<br> at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.&lt;init&gt;(KotlinCoreEnvironment.kt:219)<br> at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.&lt;init&gt;(KotlinCoreEnvironment.kt:115)<br> at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:422)</p><p>A:add a MESSAGE_COLLECTOR<em> </em>object <em>to the </em>CompilerConfiguration to fix it .</p><pre><em>val </em>configuration = CompilerConfiguration()<br>configuration.put(<br>    CLIConfigurationKeys.<em>MESSAGE_COLLECTOR_KEY</em>,<br>    PrintingMessageCollector(System.<em>err</em>, <em>MessageRenderer</em>.<em>PLAIN_FULL_PATHS</em>, <em>false</em>)<br>)<br><em>val </em>project = KotlinCoreEnvironment.createForProduction(<br>    Disposer.newDisposable(),<br>    configuration,<br>    EnvironmentConfigFiles.<em>JVM_CONFIG_FILES<br></em>).project</pre><p>Now,you’ve got the file PSI Elements ,just do what you want</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cec34a930d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>