How to get parameter type at call time?

Open
#1,415 0 comments 2 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
backend

Research direction

Start by reading the JavaMethodCall API and the related issue #721, then trace how ArchUnit represents method-call arguments and their types. The issue asks whether call-site type information, such as String passed to a generic parameter, is available; done means determining whether the existing model exposes it or what representation would be needed. No source files or tests are named, so locating the relevant code requires familiarity with the project.

Written by the indexing model from the issue text.

Description

Consider:

class A {
    public <T> void foo(T value) {}
}

class B {
    public void bar() {
        new A().foo("string");
    }
}

With a DescribedPredicate<JavaMethodCall> I can get a reference to the call to A.foo, but it appears that the JavaMethodCall object only contains type information defined in the method signature. Is there a way to get access to the type information at the call site? I.e. that we're passing a String to the method?

This is somewhat related to https://github.com/TNG/ArchUnit/issues/721, but subtly different: I'm not looking to get the call value (which isn't generally statically available), but I'm looking for the call type (which is statically available).

Dominant language
Java
Stars
3.9k
Forks
350
Avg merge
3d 2m
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TNG/ArchUnit

All issues in TNG/ArchUnit

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.