Programmatically get language level setting

Answered

Hi,

I am trying to determine the selected language level for a Java project.

 

Existing topics in searches show up very old resources (e.g. 2004 references to `PsiManager.getEffectiveLanguageLevel()`), or refer to classes/interfaces that do not resolve (e.g. `LanguageLevelProjectExtension`).

 

It does seem to be possible to get the selected SDK, but this does not necessarily match up with the language level (e.g. installation of JDK 16 while developing to the Java 8 language level).

 

Cheers,

Roger

 

Some older resources found:

 

 

 

EDIT: Yann posted this answer on slack, and I include it here for the benefit of anybody coming across this via search results.

language level is specific to Java functionality, so you must declare a dependency on it https://blog.jetbrains.com/platform/2019/06/java-functionality-extracted-as-a-plugin/

 

Two changes were needed:

  • one change within `plugin.xml` to insert `<depends>com.intellij.java</depends>` (2019.2 onwards)
  • one within `gradle.properties` to set `platformPlugins = com.intellij.java (noting that I'm using the plugin template, where `build.gradle.kts` parses and sets this config -- if not using the template, insert it directly into gradle build file)
1 comment
Comment actions Permalink

answered in Slack

0

Post is closed for comments.