MCPcopy Index your code
hub / github.com/Auties00/NamedParameters

github.com/Auties00/NamedParameters @named-1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release named-1.1 ↗ · + Follow
61 symbols 110 edges 9 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Named Parameters

Named and Optional parameters for Java 17

Abstract

While working on another project, I found a way to make the Java compiler attribute a compilation unit without reporting issues if the AST is not correct. So I thought about some cool use cases and decided to create this project. Both classes and methods are supported.

How does it work

So let's say that you have a method or class declaration:

void sayHello(String name, String surname){
    System.out.printf("Hello, %s %s%n", name, surname);
}

Traditionally, you would call the method like this:

sayHello("Alessandro", "Autiero");

Thanks to this plugin, you can use the name of the parameter followed by an assignment operator to specify the parameter:

sayHello(name="Alessandro",surname="Autiero");

According to the JLS, assignments can be legally used as arguments. Here are some examples:

var name = "Mario";
sayHello(name="Alessandro",surname="Autiero"); // name is not a named parameter as variable name exists

void hello(String name){
  sayHello(name="Alessandro", surname="Autiero"); // name is not a named parameter as method parameter name exists
}

class Whatever {
    private String name;

    void hello(){
       sayHello(name="Alessandro", surname="Autiero"); // name is not a named parameter as local variable name exists
    }
}

In these cases, "name" will not be treated as a named parameter to preserve backwards compatibility.

If you want to make a parameter optional, you can do so by applying the @Option annotation:

void sayHello(String name, @Option String surname){
    System.out.printf("Hello, %s %s%n", name, surname);
}

sayHello(name="Alessandro");

By default, these are the default values passed to the method if the argument isn't specified:

  • Object: null
  • Number(byte, short, char, int, long, float, double): 0
  • Booleans: false
  • Arrays: an empty array(for example new int[0])
  • Var args(for example int...): not handled to preserve JLS implementation

A specific value can also be provided, both constants and dynamic values are accepted:

// Constant
void sayHello(String name, @Option(18) int age){
    System.out.printf("Hello, %s(age: %s)%n", name, age);
}

// Dynamic values
void sayHello(String name, @Option(getDefaultAge(name)) int age){
    System.out.printf("Hello, %s(age: %s)%n", name, age);
}

int getDefaultAge(String name){
    // Some incredible logic
    return 0;
}

sayHello(name="Alessandro");

How to install

Installing the plugin is pretty easy, all you need to do is add a dependency to your project.

Maven

<dependencies>
    <dependency>
        <groupId>com.github.auties00</groupId>
        <artifactId>named</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>

Gradle

implementation 'com.github.auties00:named:1.1'

Gradle Kotlin DSL

implementation("com.github.auties00:named:1.1")

Core symbols most depended-on inside this repo

getName
called by 4
src/main/java/it/auties/named/plugin/NamedParameterPlugin.java
getNamedArguments
called by 3
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java
getDefaultValue
called by 3
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java
removeAttributes
called by 3
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java
open
called by 3
src/main/java/it/auties/named/util/Reflection.java
translateArguments
called by 2
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java
hasVarArgs
called by 2
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java
fixArguments
called by 2
src/main/java/it/auties/named/plugin/NamedParameterTransformer.java

Shape

Method 51
Class 10

Languages

Java100%

Modules by API surface

src/main/java/it/auties/named/plugin/NamedParameterTransformer.java18 symbols
src/main/java/it/auties/named/util/Diagnostics.java11 symbols
src/main/java/it/auties/named/util/Reflection.java10 symbols
src/main/java/it/auties/named/plugin/NamedParameterPlugin.java9 symbols
src/main/java/it/auties/named/plugin/PrepareTypesScanner.java6 symbols
src/main/java/it/auties/named/util/Annotations.java4 symbols
src/main/java/it/auties/named/plugin/RemoveTypesScanner.java3 symbols

For agents

$ claude mcp add NamedParameters \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page