Kotlin 文件的 IntelliJ 和 Android Studio 图标 [英] IntelliJ and Android Studio icons for Kotlin files

查看:29
本文介绍了Kotlin 文件的 IntelliJ 和 Android Studio 图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力了解 IntelliJ(和 Android Studio)对我的 Kotlin 文件图标做了什么.在图片中,您可以看到 Kotlin 文件带有两个不同的图标 - 一个带有小K"的矩形或一个带有小K"的圆圈 C(图中红色圆圈).矩形版本还包括一个有用的.kt"后缀.

在对这个问题的黑匣子进行一些修补之后 - 看起来如果 kotlin 文件只是声明了一个与文件名匹配的类,那么它会得到一个带圆圈的 C"图标.但是,如果它做了任何与 Java 不相似的事情——比如在类之外声明一个变量(例如 val foo = 42)——那么图标就会移动到带有K"的矩形上.图标文档

解决方案

你的分析是正确的.如果文件只定义了一个类,则项目视图节点会显示该类,而不是整个文件.如果文件中有多个声明,则项目视图节点会显示一个文件图标.

类图标的外观与混合语言项目中的 Java 类图标保持一致.

I have been tinkering trying to understand what IntelliJ (and Android Studio) are doing to my Kotlin file icons. In the picture you can see that Kotlin files come with two different icons - either a rectangle with a small "K" or a circled C with a small "K" (circled in red in the picture). The rectangle version also includes a useful ".kt" suffix.

After some tinkering with this black box of a problem - it appears that if the kotlin file just declares a class matching the file name then it gets a "circled C" icon. But if it does anything that is un-Java-like - such as declaring a variable outside the class (e.g. val foo = 42) - then the icon is shifted to the rectangle with the "K". The icon documentation here suggests that IntelliJ thinks the rectangle with the "K" is a "Kotlin file" whereas the circled C is a "Kotlin class".

Does anybody know if there is a deeper meaning to this? I think I will include a val declaration outside the class just to get my Kotlin file icon symbols all to match. Then they will also have the handy ".kt" extension to clearly indicate that they are Kotlin files.

For example - here is code that will change your icon to a rectangle with a "K" in file Foo.kt:

val bar = 42;
class Foo {}

解决方案

Your analysis is correct. If a file defines only a single class, then the Project view node shows that class, instead of the file as a whole. If there are multiple declarations in the file, then the Project view node shows a file icon.

The class icon looks the way it does for consistency with Java class icons in mixed-language projects.

这篇关于Kotlin 文件的 IntelliJ 和 Android Studio 图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆