A Kotlin compiler plugin that allows Java callers to pass in null for default parameters

Overview

kotlin-null-defaults

Maven Central (Compiler plugin) Maven Central (Gradle Plugin)

Gradle Plugin Portal ( Currently pending approval)

A Kotlin compiler plugin that allows Java callers to pass in null for default parameters by automatically checking for nulls and substituting the default values .

In short, this plugin, through annotating any relevant declarations with @NullDefaults, allows you to treat your default parameters as if they were nullable. The annotation can be applied to a whole class (for constructors), a specific function/constructor, or even individual parameters.

The main use-case being supporting legacy Java code that expects being able to pass in null for certain parameters and having that being handled on its own. Note that this plugin specifically doesn't allow Kotlin callers to do the same thing due to the ease of use and idiomacy of default parameters in Kotlin and the fact that such a feature would go against most established conventions. However, in the future the plugin could support this limited use-case behind a flag.

Use with care!

Note: This plugin was created using Brian Norman's Kotlin IR Plugin Template and from guidance from his wonderful article series Writing Your Second Kotlin Compiler Plugin ( seriously like the articles were immensely helpful when I just knew absolutely nothing about IR) and it was created originally as part of the discussion on Kotlin Discussions: Feature Request: Constructor parameter default value when receiving null input to support the OP's use-case.

You might also like...
A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports
A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports

A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports 1. What are Jetpack Compose compiler metrics? The Comp

The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

The KPy gradle plugin allows you to write Kotlin/Native code and use it from python.

Plugin for Minecraft Dev projects that allows use BON2 as analog of fg.reobf from ForgeGradle

Bon2Gradle Plugin for Minecraft Dev projects that allows use BON2 as analog of fg.reobf from ForgeGradle. Usage Dependencies Gradle 6.8+ (Provider as

Plugin-shared-preferences - Pluto plugin to manage your Shared Preferences

Pluto Shared Preferences Plugin Pluto Shared Preferences is a Pluto plugin to in

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

Extension functions over Android's callback-based APIs which allows writing them in a sequential way within coroutines or observe multiple callbacks through kotlin flow.

callback-ktx A lightweight Android library that wraps Android's callback-based APIs into suspending extension functions which allow writing them in a

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

Kotlin-client-dsl - A kotlin-based dsl project for a (Client) - (Plugin) styled program

kotlin-client-dsl a kotlin-based dsl project for a (Client) - (Plugin) styled p

Custom ViewPager that allows to block left or right swipe gestures.
Custom ViewPager that allows to block left or right swipe gestures.

SwipeDirectionViewPager Introduction Custom ViewPager that allows to block swiping right or left where the ViewPager child fragments set the scroll di

Releases(0.2.0)
Owner
Youssef Shoaib
Youssef Shoaib
Actions are things that run, with parameters. Serves as a common dependency for a variety of Cepi extensions.

Actions Actions that take in customizable paramaters, an optional target, and do things. Installation Download the jar from Releases OR compile it you

Cepi 1 Jan 9, 2022
An annotation and Kotlin compiler plugin for enforcing a when statement is exhaustive

An annotation and Kotlin compiler plugin for enforcing a when statement is exhaustive

Cash App 468 Jan 4, 2023
A composite Github Action to execute the Kotlin Script with compiler plugin and dependency caching!

Kotlin Script Github Action Kotlin can also be used as a scripting language, which is more safer, concise, and fun to write than bash or python. Githu

Suresh 9 Nov 28, 2022
Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

Lorris Creantor 18 Nov 24, 2022
This repository is part of a Uni-Project to write a complete Compiler for a subset of Java.

Compiler This repository is part of a Uni-Project to write a complete Compiler for a subset of Java. Features error recovery using context sensitive a

null 3 Jan 10, 2022
A simple example of kotlim compiler plugin with FIR and IR.

A simple Kotlin compiler plugin example This Kotlin compiler plugin generates a top level class: public final class foo.bar.MyClass { fun foo(): S

Anastasiia Birillo 10 Dec 2, 2022
An experimental tool for building console UI in Kotlin using the Jetpack Compose compiler/runtime

An experimental tool for building console UI in Kotlin using the Jetpack Compose compiler/runtime

Jake Wharton 1.4k Dec 28, 2022
Build a compiler in Kotlin (based on the original tutorial by Jack Crenshaw)

Let's Build a Compiler Based on the original series "Let’s Build a Compiler!" by Jack Crenshaw. This is an adaptation of the original series to Kotlin

null 2 Oct 9, 2022
Playground project for Koin Koin Compiler - Sandbox

Koin Compiler - Sandbox The goal of Koin compiler & Annotations project is to help declare Koin definition in a very fast and intuitive way, and gener

insert-koin.io 17 Nov 22, 2021
A Open GAL compiler based on OpenGAL 0.3.1

A Open GAL compiler based on OpenGAL 0.3.1

Li Plum 3 Dec 21, 2022