Why in the official Kotlin coding conventions we should omit root package in directory structure? - kotlin

In the official Kotlin coding conventions (https://kotlinlang.org/docs/reference/coding-conventions.html) they recommend to us to omit root package in directory structure. It is not comfortable, when you create a new file in your kotlin source folder and then edit the package name, because it did not generated automatically.

From a Reddit comment:
I guess you're supposed to use the package prefix
in the project structure, but sadly that feature is only available in IDEA and not Android Studio.
I agree it's weird that it's not documented more explicitly, I've only found https://www.jetbrains.com/help/idea/creating-and-managing-modules.html. You may want to consider raising the issue on http://discuss.kotlinlang.org/.

Looks like support for packagePrefix was added to idea-ext gradle plugin in version 0.5 : https://github.com/JetBrains/gradle-idea-ext-plugin/wiki/DSL-spec-v.-0.5#package-prefix-requires-idea-20191

I think this rule is inherited from Java code style where using of default package is a bad practice.
You can check this topic to obtain more information about default package in Java.

Related

How to add Kotlin PSI source files to IDEA Plugin project configuration

I am trying to add support for kotlin for one of the IDEA plugins.
So far, I found this page and understood that I need to work with kotlin PSI files, such as KtClass and others.
When I was setting up my project I added idea source files to sdk(by cloning this repo), to make it easier to debug + see documentation.
However it seems that these idea source files doesn't include kotlin source files, such as mentioned KtClass and others, which I use in my project. Currently I see only decompiled version of these files.
Is there any way to add them like with other IDEA source files?
Those source files belongs to the Kotlin plugin, which is not strictly a part of IntelliJ IDEA distribution. You need to add the Kotlin plugin source to the project as well as the IDEA source.
There're two modules needed:
https://github.com/JetBrains/kotlin/tree/master/idea
https://github.com/JetBrains/kotlin/tree/master/compiler/psi/src/org/jetbrains/kotlin

Feature module won't build unless layout resources exist in base module

I an instant app with around 10 feature modules and one base feature. All of the modules build correctly except for one. If I don't have the layouts for this one feature included in the base feature then the module won't build. It states that the layout resources don't exist even though they are included in the resources directories for the feature module. Has anyone seen this? What can I do to resolve this? Thank you!
Yea it's annoying i had to do something similar. I appended feature's name to the package of feature. Let's say my base package is com.myapp.android, and i have a feature named "awesome", I gave "com.myapp.android.awesome" as package name of that feature. Then while importing the resources I simply did, com.myapp.android.awesome.R.id.login and it worked.
The issue was that I had the R imported from the curbside app base feature and not the feature module.

Where is ChainedFilter class in Lucene .NET 3.0.3?

It was in Lucene.Net.Analyzers.dll in version 2.9.4. But i can't find this class in version 3.0.3.
Mindas: here is my comment since I cannot add a normal comment: how to access this ChainedFilter class? I have downloaded the package but there is no namespace like Lucene.Net.Contrib, or no other namespace which allows me to reach the ChainedFilter class. This seems silly but I am stuck!
UPDATE: There is a bug in the binaries from Nuget as well as zip files uploaded on apache site for Lucene.net. I downloaded the source and noticed that the ChainedFilter.cs class is present in the Apache-Lucene.Net-3.0.3-RC2.src\src\contrib\Analyzers\Filters folder, but this folder is surprisingly not a part of the Contrib.Analyzers project. That is why it was missing from the generated binaries.
Rephrasing this answer, you can either build it yourself or use Nuget to get the binaries.
http://nuget.org/packages/Lucene.Net.Contrib/
ChainedFilter should be under contrib/misc.
It looks like it is in org.apache.lucene.misc.ChainedFilter in Lucene 3.x.

How do I add my fragment to the list of required-plugins on an existing plugin

I currently have an existing plugin, which references a class from a required plugin. I have replaced this code with a reference to a class which is part of my fragment.
I am facing two issues.
If I import my fragment as a jar file, I am not able to see the changes I have made as the plugin running as an eclipse application results in a ClassNotFoundException
To overcome this, I link an additional source (of fragment) to the existing plugin project. However, the link uses an absolute path, and makes it unfit for deployment.
I want to be able to package the plugin with the code modification and be able to "depend" on my fragment code. Is there a way I can add my fragment as a dependency?
For example:
Plugin Project I am changing : org.eclipse.*.editor
it depends on org.eclipse.*.edit
I have a fragment mydomain.*.edit which has org.eclipse.*.edit as host plugin
I want org.eclipse.*.editor to pick up mydomain.*.edit
instead of org.eclipse.*.edit
ps: I have also tried packaging the jar file for the mydomain.*.edit in the plugins directory and try and pick it up from there, it doesnt show up on the list when I click add required plugins on the dependency tab on the plugin.xml file of the org.eclipse.*.editor
Please let me know if I am not clear enough, I will try and rephrase it.
Thanks in advance!
If I understand correctly what you want to do, I don't think that it's possible. You will have to try some other way.
Plugins have dependencies on other plugins. Fragments don't exist as separate runtime entities, but only as extensions of a plugin. So your plugin can only refer to the 'editor' plugin.
Classes provided by a fragment can't (and shouldn't) be accessed directly. They can be returned by the original plugin (A) if they are implementing an executable extension provided by plugin A.
If you refer to the fragment's code from another plugin (B), the classes will be loaded by plugin B's classloader and be different from the ones that are loaded by plugin A.
What is the purpose of your fragment? Do you want to get access to internal code in plugin A? Do you want to extend an eclipse editor?
If you want to extend functionality that the original plugin is not exposing as extensible, I think the only way is to write a plugin, extend the editor class from the original plugin, register it alongside the original one and use it instead.
[Edit] Maybe this link will explain better: Eclipse FAQ
Hope this helps,
Vlad
Thanks Vlad,
Your explanation was very helpful. Unlike the extension based architecture that is truly intended for fragments, I had to modify a certain component in the editor that was not exposed as part of the extension. This modification referred to an external project I created as an fragment but could have been a normal java project packaged a jar file that I could place in the classpath of the editor.
I was able to resolve the dependency issues by placing the jar file in class path, however when I export the plugins and related plugins as jar files and place it in the dropin directory, it does not install correctly. (Nor does placing the jar files in the plugins directory)
The eclipse editor that I am trying to modify uses the EMF project. I have kept the EMF project in the workspace inorder to resolve dependencies of the editor. However when I replace the EMF jar files bundled with eclipse with the one in the workspace, the files that I want to edit are not correctly recognized.
Is there another way of doing this?

IntelliJ creating error when refactoring sample package

I just started learning Javafx with Java11
I created a project in IntelliJ and it gave the standard structure.
In src file when I change the package name for the package "sample" to anything else, IntelliJ gives the following error.
Error:Kotlin: The Kotlin standard library is not found in the module graph. Please ensure you have the 'requires kotlin.stdlib' clause in your module definition
The error disappears when I refactor the package back to "sample".
how do I rename without getting this problem.
this might be helpfull
Javac gives this error, when lint is enabled and you use Java 9 module in Kotlin. You have to declare "requires kotlin.stdlib" in your module-info.java.
Ran into the same issue. For me, I'm using a module-info file in the src folder that looks like this:
module javafx {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
If you rename your package to foo, then you need to change the last line to "opens foo". Otherwise it's still gonna look for and try to open a package named "sample". I have no idea what this has to do with kotlin.
I had the same problem and I solved it disabling "Kotlin migration detection". I have already response here:
https://stackoverflow.com/a/59628873/2350799
I had the same problem. But as long as you are not using Kotlin in the project there is a workaround : disable the Kotlin plugin, under settings.