I would like to find the library specification for a class opened in the editor. I have a Maven project which is quite big with a lot of modules. When I navigate to a class which is referenced from the source code I can see a module origin in the title bar of Intellij Idea like this "HttpServlet [Maven: org.apache..."
However I am not able to see where exactly this Maven library is included from, I can guess this example above as part of an Web Service and I can think of where it is nested in, but this is a hard process sometimes especially if it is a nested include somewhere...
Following https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests and https://www.michael-bull.com/blog/2016/06/04/separating-integration-and-unit-tests-with-gradle we are attempting to separate our integration tests from plain unit tests.
The problem we have is internal members in Kotlin are not accessible from such tests. As per Kotlin doco there is a visibility exception for test source sets.
The internal visibility modifier means that the member is visible
within the same module. More specifically, a module is a set of Kotlin
files compiled together:
an IntelliJ IDEA module;
a Maven project;
a Gradle source set (with the exception that the test source set can access the internal declarations of main);
a set of files compiled with one invocation of the Ant task.
Is there a way around it other than not trying to access them? That would call for a major refactoring of hundreds of tests and potentialy the whole codebase.
I was able to get a custom test sourceSet to access internal classes by adding the following code to my custom Gradle plugin.
NamedDomainObjectContainer<KotlinWithJavaCompilation<KotlinJvmOptions>> compilations = project
.getExtensions()
.getByType(KotlinJvmProjectExtension.class)
.target.getCompilations();
compilations.getByName(sourceSet.getName())
.associateWith(compilations.getByName(SourceSet.MAIN_SOURCE_SET_NAME));
I looked at the kotlin-gradle-plugin source code and found the following:
https://github.com/JetBrains/kotlin/blob/v1.3.61/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlugin.kt#L488-L490
With change, the tests in my custom source set run just fine, but IntellIJ still shows compilation errors. I'll look further to see if I can make IntelliJ happy as well
I am creating an IntelliJ plugin and I am using JavaParser for one of my features. My plugin will allow users to click a gutter icon next to a method and automatically navigate to the tests associated with that method.
To achieve this, temporerily I have used the line:
typeSolver.add(new JavaParserTypeSolver(new File("/home/webby/IdeaProjects/project00/src/")));
My problem is that I need to pass the source folder of the given module into this type solver. Is there any way I can find the source folder programmatically? Perhaps from an actionEvent?
I have tried things along the lines of the following:
actionEvent.getData(PlatformDataKeys.PROJECT).getBasePath()
This gives me: '/home/webby/IdeaProjects/project00/' but I'm struggling to see how I can get the source folder? I feel there should be a fairly straight forward way of doing this using IntelliJ's SDK but I have not found anything in the documentation or anywhere else online.
Any and all solutions welcome!
Many Thanks,
James
You can use
ModuleRootManager.getInstance(module).getSourceRoots()
to access sources roots of a module. Refer to IntelliJ SDK Docs for details.
BTW IntelliJ IDEA provides special API to syntax trees of Java files, it works more efficiently and better integrates with other IDE features than external JavaParsers.
And it's better to ask questions about IntelliJ IDEA API on a special forum.
I'm using stanford nlp to do sentiment analysis. I just need the sentiment score therefore following are the libraries that I'm adding into my project:
1) ejml-0.23.jar
2) stanford-corenlp-3.5.2.jar
3) stanford-corenlp-3.5.2-models.jar
When I add dependencies in the Project Structure in IntelliJ, first two work fine and are imported correctly and shown in the external libraries tab. But for the models.jar it throws me an error saying that IDEA cannot determine what kind of files the chosen item contains. When I still go ahead and add it - I don't see the models.jar file in the External Libraries section. See pics attached:
Libraries present in my Project Structure:
External Libraries: models.jar not included
stanford-corenlp-3.5.2-models.jar is not a library of Java classes but instead, it contains various nlp models that are used by different algorithms in the core package.
Therefore IntelliJ fails to recognize the content (which is fine). As long as the jar file is available in the classpath at the runtime, you should not run into any issues. It seems the case by looking at the project structure so I would not worry about this particular error.
Background
I have an sbt-managed Scala project that uses the usual sbt project layout for Scala projects with macros, i.e., a subproject that contains the macros a main project that is the actual application and that depends on the macro subproject. The macros are macro annotations which, in essence, generate companion objects for regular classes. The generated companion objects declare, amongst other members, apply/unapply methods.
I used the sbt-idea plugin to generate a corresponding IntelliJ IDEA project, and I use the sbt console from IDEA's sbt-plugin to compile and run my Scala application.
Everything works more or less fine, except that the generated companion objects, and more importantly, their members such as apply/unapply, are not recognised by IDEA. Thus, I get a squiggly line everywhere I, e.g., an apply method.
My setup is IntelliJ IDEA CE 133.471 with the plugins SBT 1.5.1 and Scala 0.28.363 on Windows 7 x64.
Questions
How do I get IntelliJ IDEA to recognise code (classes, objects, methods, ...) that has been generated by Scala macros (macro annotations, to be precise)?
Are other IDEs, e.g., Eclipse, known to work better in such a setting?
Related
This question (which is less detailed) essentially asks the same, but has not gotten a reply yet (2014-02-26).
According to a JetBrains developer the feature I requested is on their long-term to-do list, but won't be implemented any time soon (2014-03-05).
With the latest Scala plugin build, there is an API which can be used to write your own plugin to support your macros: http://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/
Now, everyone can use this API to make their macros more friendly to their favorite IDE. To do that, you have to implement SyntheticMembersInjector, and register it in the plugin.xml file:
<extensions defaultExtensionNs="org.intellij.scala">
<syntheticMemberInjector implementation="org.jetbrains.example.injector.Injector"/>
</extensions>
Seems like there's limited support if any.
Quote by this link: http://blog.jetbrains.com/scala/2014/01/23/heading-to-the-perfect-scala-code-analysis/
Alexander Podkhalyuzin says:
January 30, 2014 at 10:13 am
We started support for Scala macros, but it’s not a simple task, so I can’t promise it will be done soon.
Best regards,
Alexander Podkhalyuzin.