MCPcopy Index your code
hub / github.com/Guardsquare/kotlin-metadata-printer

github.com/Guardsquare/kotlin-metadata-printer @v1.1.13

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.13 ↗ · + Follow
179 symbols 445 edges 20 files 14 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Kotlin Metadata Printer

The Kotlin metadata printer is a free tool to print the Kotlin metadata in a human-readable format. The printer is built on the ProGuardCORE library and can process class files, zip files, jars or apks.

The Kotlin metadata printer is integrated in ProGuard Playground or you can run it locally.

demo of printer GUI

Building

You can build the Kotlin metadata printer jar by executing the following Gradle command:

./gradlew build

Once built a jar will be created in lib/kotlin-metadata-printer.jar

Executing

You can execute the printer directly through gradle as follows:

./gradlew :kmp-cli:run --args "input.{apk,jar,zip,class}"

Or you can execute the built printer jar as follows:

java -jar lib/kotlin-metadata-printer.jar input.{apk,jar,zip,class}

Options

--filter '<classNameFilter>' class name filter e.g. --filter '!android.**,com.mypackage.**'
--output '<outputFile>'      write output to this file instead of stdout e.g. --output 'myfile.txt'
--json                       output the metadata in a JSON structure
--divider                    a string that is printed between each Kotlin metadata

Example

The following example is a basic Android activity class written in Kotlin:

/**
 * Sample activity that displays "Hello world!".
 */
class HelloWorldActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

and this is its associated metadata as printed by the Kotlin metadata printer:

/**
* Kotlin class.
* From Java class: com.example.HelloWorldActivity
*/
class HelloWorldActivity : android.support.v7.app.AppCompatActivity {

    // Functions

    protected open fun onCreate(savedInstanceState: android.os.Bundle?) { }
}

Using as a library

The project is split into CLI (kmp-cli) and library (kmp-lib) modules. To use the printer programmatically from your project add a dependency on the library and then use the KotlinMetadataPrinter class along with a ProGuardCORE ClassPool. The printed metadata is placed into the processing info field of the Clazz.

import com.guardsquare.proguard.kotlin.printer.KotlinMetadataPrinter;
import proguard.classfile.kotlin.visitor.ReferencedKotlinMetadataVisitor;
import proguard.classfile.visitor.MultiClassVisitor;
import proguard.classfile.util.kotlin.KotlinMetadataInitializer;
import proguard.classfile.ClassPool;

import static proguard.io.util.IOUtil.read;

public class Main
{
    public static void main(String[] args)
    {
        ClassPool programClassPool = read(args[0], false);
        programClassPool.classesAccept(
            new MultiClassVisitor(    
            new KotlinMetadataInitializer((clazz, errorMessage) -> System.err.println(errorMessage)),        
            new ReferencedKotlinMetadataVisitor(
            new KotlinMetadataPrinter(programClassPool)))
        );

        programClassPool.classesAccept(clazz -> System.out.println(clazz.getProcessingInfo()));
    }
}

Contributing

The Kotlin metadata printer is built on the ProGuardCORE library.

Contributions, issues and feature requests are welcome in both projects. Feel free to check the issues page and the contributing guide if you would like to contribute.

License

The Kotlin metadata printer is distributed under the terms of the Apache License Version 2.0.

Enjoy!

Copyright (c) 2002-2023 Guardsquare NV

Core symbols most depended-on inside this repo

Shape

Method 157
Class 21
Enum 1

Languages

Java96%
Kotlin4%

Modules by API surface

kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/KotlinMetadataPrinter.java58 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/KotlinTypeVisitorWrapper.java26 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/KotlinAnnotationPrinter.java17 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/ContextParameterValueParameterVisitor.java11 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/ConstantToStringVisitor.java11 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/AnnotationPrinter.java11 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/KotlinTypeParameterVisitorWrapper.java9 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/Context.java9 symbols
kmp-cli/src/main/java/com/guardsquare/proguard/kotlin/printer/KotlinMetadataPrinterCli.java9 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/KotlinMetadataVisitorWrapper.java5 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/visitor/KotlinClassTypeParameterVisitor.java4 symbols
kmp-library/src/main/java/com/guardsquare/proguard/kotlin/printer/internal/ContextFrame.java2 symbols

For agents

$ claude mcp add kotlin-metadata-printer \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page