IntelliJ and Android Studio icons for Kotlin files

2019-02-17 13:57发布

问题:

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 {}

回答1:

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.