Skip to content

Is there a way to detect unused methods and fields in Spring Application? #1034

Answered by hankem
adavid9 asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, it seems that you already know timtebeek/archunit-unreferenced... 😉

it searches for getters & setters

If you want to allow for unused getters & setters, you could probably exclude them explicitly in your methods().that selection, e.g. for getters:

            // ...
            .and(not(rawParameterTypes(/* none */).and(nameStartingWith("get"))))
            // ...

with a predicate like this:

    static DescribedPredicate<JavaCodeUnit> rawParameterTypes(Class<?>... expectedTypes) {
        return describe("parameters", codeUnit -> {
            List<JavaClass> parameterTypes = codeUnit.getRawParameterTypes();
            if (parameterTypes.size() != expectedTypes.length) {
         …

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@adavid9
Comment options

@codecholeric
Comment options

Answer selected by adavid9
Comment options

You must be logged in to vote
6 replies
@adavid9
Comment options

@adavid9
Comment options

@adavid9
Comment options

@hankem
Comment options

@hankem
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants