Skip to content

craftvscruft/untangler

Repository files navigation

Untangler

Tests License: APACHE

Multi-language refactoring tool implemented in Java, an experimental spin-off of MenderBot.

Commands

  • untangler get functions: List function definitions in a file
  • untangler get references: Show symbol and declarations and reference in a file
  • untangler rename: Rename a symbol and all references to it a file
  • untangler add comment: Add a comment at a given line
  • untangler remove comment: Remove a comment at a given line

All commands output text by default but can output machine-readable formats with arguments -o json or -o yaml.

Arguments to each subcommand can be printed with untangler <COMMAND> --help.

Status

Prototype, not ready for production use.

Support by language

Action Python C / C++ Java C# js / ts
get functions Beta Beta Beta Beta -
get references Beta Beta Beta Beta -
rename - Beta Beta - -
add comment - Beta Beta - -
remove comment - Beta Beta - -
extract variable - - - - -
extract parameter - - - - -
extract field - - - - -

Requirements (build)

  • Java 16+ (GraalVM JDK20 to build static exe (Homebrew tap)

GraalVM will allow us to ship untangler static executable that does not require Java to be installed for the end user.

Running

# Set your GraalVM JDK instalation if you're using it
export JAVA_HOME=...

./gradlew installDist

build/install/untangler/bin/untangler

For easy rebuilding and running with the un shortcut, use:

alias un="./gradlew installDist -q && build/install/untangler/bin/untangler"

un get functions -f src/test/resources/hello.c

Testing

Just the unit tests:

./gradlew test

Everything:

./gradlew spotlessApply check

Coverage report in open build/reports/jacoco/test/html/index.html

Vision

  • Support each of the core 6 refactorings identified by Arlo Belshee
  • Support the Menderbot target languages with reliable syntax tree manipulation
  • Operate independent of a language server
  • Be automation-friendly, commands should have an option to output json and indicate success with exit codes, for instance

Core 6 refactorings

  • Rename
  • Inline
  • Extract Method
  • Introduce Local Variable
  • Introduce Parameter
  • Introduce Field

Target languages

  1. Python
  2. C / C++
  3. Java
  4. C#
  5. JavaScript / TypeScript

Building native binary

This build is slower, but the resulting static executable is fast and shippable!

# Your GraalVM JDK 20 instalation
export JAVA_HOME=...

./gradlew nativeCompile

# Run with:

build/native/nativeCompile/untangler

During development, you might alias this nun for native untangler.

alias nun="build/native/nativeCompile/untangler"

If you get a reflection error, META-INF may need to be updated. Check the Gradle native image docs for more info. So far what's been needed is for META-INF/native-image/reflect-config.json to list all the classes that we will serialize to Json. Try running GenerateReflectConfig to get new json (this should eventually be a build step).

Author

👤 Ray Myers

Acknowledgements

  • Antlr - the leading parser generator
  • JavaParser - analyze and transform Java Code
  • picocli - a mighty tiny command line interface

📝 License

Copyright © 2024 Ray Myers.

This project is Apache 2 licensed.

About

Multi-language refactoring command line tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages