Skip to content
프로젝트

소개

A Kotlin compiler plugin for embedding information about the file being compiled

프로그래밍 언어 및 런타임

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Cite for Kotlin

A Kotlin compiler plugin for embedding information about the file being compiled.

For example, given:

object Greeter {
  fun sayHi() {
    println("Hello: $__FILE__, $__TYPE__, $__MEMBER__, $__LINE__")
  }
}

When invoked, this will output:

Hello: main.kt, Greeter, sayHi, 16

The Java bytecode shows values were resolved at compile time:

 9: getstatic     #19      // Field java/lang/System.out:Ljava/io/PrintStream;
11: ldc           #27      // String Hello: main.kt, Greeter, sayHi, 16
14: invokevirtual #25      // Method java/io/PrintStream.println:(Ljava/lang/Object;)V

The values are constants, so they can be folded with other constants.

Every Kotlin target is supported. Here's JS:

Greeter.prototype.h = function () {
  println('Hello: main.kt, Greeter, sayHi, 16');
};

Native (as LLVM IR):

@760 = … { …, [68 x i8] c"H\00e\00l\00l\00o\00:\00 \00m\00a\00i\00n\00.\00k\00t\00,\00 \00G\00r\00e\00e\00t\00e\00r\00,\00 \00s\00a\00y\00H\00i\00,\00 \001\007\00" }
 ⋮
call void @"kfun:kotlin.io#println(kotlin.Any?){}"(ptr @760)

API

Six properties are provided:

Property Type Description Example
__MODULE__ String Name of the Kotlin module. "example"
__FILE__ String Filename of the source file. "main.kt"
__TYPE__ String Name of the nearest enclosing class, object, interface, or enum. "Greeter"
__FQ_TYPE__ String Fully-qualified name of the nearest enclosing type or file facade. "com.example.Greeter"
__MEMBER__ String Name of the nearest enclosing function or property body. "sayHi"
__LINE__ Int One-based line number of this property access. 16

Using type properties in locations without an associated enclosing type is an error. For example, using __TYPE__ in a top-level function will fail to compile.

Usage

Add the buildscript dependency and apply the plugin to each module in which you want to access the properties.

buildscript {
  repository {
    mavenCental()
  }
  dependencies {
    classpath 'com.jakewharton.cite:cite-gradle-plugin:0.9.0'
  }
}

apply plugin: 'org.jetbrains.kotlin.multiplatform' // Or .jvm, or .android
apply plugin: 'com.jakewharton.cite'

The runtime dependency will be added as an implementation dependency automatically. Never add the runtime dependency yourself, as use without the plugin will not work.

Snapshots of the development version are available in the Central Portal Snapshots repository.

buildscript {
  repositories {
    mavenCentral()
    maven {
      url 'https://central.sonatype.com/repository/maven-snapshots/'
    }
  }
  dependencies {
    classpath 'com.jakewharton.cite:cite-gradle-plugin:0.10.0-SNAPSHOT'
  }
}

apply plugin: 'org.jetbrains.kotlin.multiplatform' // Or .jvm, or .android
apply plugin: 'com.jakewharton.cite'

Compatibility

Since Kotlin compiler plugins are an unstable API, certain versions of Cite only work with certain versions of Kotlin.

Kotlin Cite
2.4.0 0.9.0
2.3.0 0.8.0
2.0.21 - 2.2.0 0.4.0 - 0.7.0
1.8.0 - 1.9.25 0.1.0 - 0.3.0

Kotlin versions newer than those listed may be supported but have not been tested.

License

Copyright 2023 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

관련 프로젝트 살펴보기

불러오는 중…