I have an Android project where Java and Kotlin files are mixed. I am writing a comment in one of the Kotlin files and I want to link some method in Java file.
Is this possible? How?
For Kotlin I do:
/**
* [ResultMatcher.getCount]
*/
But when ResultMatcher is java class it doesn't work. I tried adding different symbols (_,#) and .java or ::class but it didn't help.
Most likely ResultMatcher is not the full qualified name and you don't have an import.
Below works in IntelliJ, you can click on size and it will navigate to the method body:
import java.util.ArrayList
/**
* [ArrayList.size]
*/
fun main() { }
and this also works:
/**
* [java.util.ArrayList.size]
*/
fun main() { }
Related
i wanted to write a bit for Android ebay client.
but im struggeling with the first probleme.
first i start a new Java Android Project with IntelliJ
I want to use this Library ebay-oauth-android-client
like described on Git:
Obtaining Library
This library is distributed via maven central repository. To use this
library, include the below as dependency in your project
dependencies {
compile 'com.ebay.auth:ebay-oauth-android-client:1.0.1'
}
i put this snippet in my Gradle.build and replace compile with implementation since compile is depricated.
so far so good. gradle import this library.
but the next step not working for me:
Application Setup
Before performing OAuth, the library should be initialized with details about your application from eBay developer portal. The library uses
Client ID. For details see Getting your OAuth credentials
Redirect Uri. for details see Getting your Redirect_Uri
Url encoded list of scopes. for details see Specifying OAuth scopes
Use these details in ApiSessionConfiguration.initialize() as shown below:
ApiSessionConfiguration.initialize(
apiEnvironment = ApiEnvironment.PRODUCTION,
apiConfiguration = ApiConfiguration(
<Client ID>,
<Redirect Uri>,
<space separated scopes>
)
)
So i try to call initialze:
my Code with error
But when i try that the Compiler tells me that:
cannot find symbol method initialize(<null>)
When i Jump to the Class Declaration of ApiSessionConfiguration is written that:
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.ebay.api.client.auth.oauth2.model
public final class ApiSessionConfiguration private constructor() {
public companion object {
private final val instance: com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration /* compiled code */
public final fun getInstance(): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
public final fun initialize(apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment, apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration): com.ebay.api.client.auth.oauth2.model.ApiSessionConfiguration { /* compiled code */ }
}
public final var apiConfiguration: com.ebay.api.client.auth.oauth2.model.ApiConfiguration? /* compiled code */
public final var apiEnvironment: com.ebay.api.client.auth.oauth2.model.ApiEnvironment? /* compiled code */
}
i dont really understand what im doing wrong. in the sample file on Git ApiSessionConfiguration.initalize() is called without any errors.
i already tried to Invalidate Cache, Clean Build, and start over again.
when i try to import the library from Project Structure Librarys New from Maven repo it says:
no files were downloaded...
Doesn't it can resolve initialize method with single argument?
Did you tried initialize method with two arguments?
Their sample app takes 2 arguments:
https://github.com/eBay/ebay-oauth-android-client/blob/master/sample/src/main/java/com/ebay/api/client/auth/MainActivity.kt#L37-L44
Updated:
But to access to Kotlin companion object function from java you need to call ApiSessionConfiguration.Companion.initialize method
I need to link to a package in JavaDoc.
Example:
#param example description (see {#link com.example.packagename this})
With the code above, I get this message:
warning - Tag #link: reference not found: com.example.packagename
Linking to a class in the same package works fine, but I need to link directly to the package.
It's not possible with #link.
Create package.html file or a single package-info.java in your com.example.packagename
/**
* This is packagename
*/
package com.example.packagename;
Then you can link to this package by using #see.
/**
* #param example description
* #see com.example.packagename
*/
void doWork(String example) {
}
Now you android studio will show the documentation as follow:
By clicking on com.example.packagename, the javadoc inside package-info.java will be shown.
Note:
Instead of linking packagename directly, You can use <a> tag:
* #see Packagename
I am writing a Gradle plugin that needs to scan Kotlin files and find if there is a certain interface included in the class. For example, with this snippet of code:
class MyClass {
interface MyInterface {
fun doSomething()
}
}
my plugin would print on the console that the interface MyInterface was found, and for this snippet:
class MySecondClass {}
would not print anything.
I have successfully created the plugin structure and a DefaultTask like this, where I get the file that needs to be inspected from the user input (written in Kotlin):
open class MyGradleTas : DefaultTask() {
#InputFile lateinit var inputFile: File
#OutputDirectory lateinit var outputDirectory: File
#TaskAction
fun run() {
// How can I inspect the Java/Kotlin code inside the inputFile object
}
}
How can I inspect the inputFile File object? Is there a way to transform it to UAST or PSI? If so, how?
So I found this project: http://javaparser.org/ that I believe it will put me in the right direction, but any suggestions are welcome, since I do not know if this is the preferred/right approach
I agree with your thought that using a parser is the correct way to approach this. I found a discussion of parsing Kotlin that has pointers to 2 projects on GitHub that use antlr4 grammars to parse Kotlin. The second project appears to be basically a copy of the first, but provides slightly more useful examples of how to use it.
I would like to add a shortcut to a specific unit test from my class level comment. This way a developer can quickly navigate to a test within their IDE.
Using IntelliJ, I added the following to the class comment for "MyClass":
/**
* #see com.my.address.AnotherClass
* #see com.my.address.MyClassTests
* {#link com.my.address.MyClassTests#nameOfMyTest NameOfMyTest}
*/
IntelliJ presents this error for the two shortcuts that reference the tests:
Cannot resolve symbol 'com.my.address.MyClassTests' less... (⌘F1)
This inspection points out unresolved references inside javadoc
Is it possible to present a shortcut to a unit test from comment? If so, how?
--- additional info (Jan.28/2015) ---
This is my module setting in IntelliJ for this project:
Assuming they are in the same package you don't need the package name, but you do need a # between the class name and the method name:
{#link MyClassTests#NameOfMyTest()}
By running System.loadLibrary("myAPI"), I verified that the DLL file "myAPI.dll" can be successfully loaded into my Eclipse Java project. Now I need to call methods specified inside this DLL file from my Java code. To do this, I added JNA to my Java project. Then I wrote the below-given code snippet that should be able to get instances of classes IProject and ProjectFactory (specified in the DLL file).
I still don't understand how to properly implement this with JNA. I checked different threads, e.g. this one, but the ones I checked don't provide an answer. Any help is highly appreciated. Thanks.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MyClass {
public interface myAPI extends Library {
//...
}
void LoadProj() {
myAPI api = (myAPI) Native.loadLibrary("myAPI",myAPI.class);
String fileName = "xxx.sp";
IProject project; // this is wrong but shows what I am trying to do
try {
project = ProjectFactory.LoadProject(fileName);
}
catch (Exception ex) {
MessageBox.Show(this, ex.Message, "Load failure");
}
}
}
Not sure what problem you are facing but as a practice your myAPI interface should declare all the methods verbatim with appropriate parameter mapping. I don't see any methods inside your interface.
Please checkout the this link as well as the link mentioned above by #Perception
If there are no Java classes or Java source hidden inside this DLL (which would be ... strange), then it will never work this way. You can't instantiate C# classes or use C# interfaces. MessageBox.Show( isn't Java either, it is Windows Forms code.