Search code examples
javaintellij-idealombokintellij-lombok-plugin

Is it possible to use IntelliJ's 'Analyze Data Flow to Here' feature with Java Lombok?


I have recently done an experiment to see how we can use Lombok to reduce boilerplate in our code.

The issue: When creating a simple data class with a builder through Lombok annotations, in IntelliJ IDEA, I cannot right click a field, then select Analyze Data Flow to Here.

This is using the latest IntelliJ Lombok Plugin. IntelliJ Ultimate 2019.2.3.

Is there any fix for this or is it simply not supported?

Example 1 - no lombok:

public class Person {

    private String name;
    private int age;

    private Person() {

    }

    public Person(Builder builder) {
        name = builder.name;
        age = builder.age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public static class Builder {
        private String name;
        private int age;

        public Builder name(String val) {
            this.name = val;
            return this;
        }

        public Builder age(int val) {
            this.age = val;
            return this;
        }

        public Person build() {
            return new Person(this);
        }
    }
}
public class Main {

    public static void main(String[] args) {
        Person person = new Person.Builder().name("tom").age(3).build();
    }
}

With the above code, when I right click the "name" variable and select analyse dataflow to here, I am able to see the dataflow. As shown in screenshot: enter image description here

Example 2 - with Lombok:

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Builder
@Getter
public class Person {
    private String name;
    private int age;
}
public class Main {
    public static void main(String[] args) {
        Person person = Person.builder().name("tom").age(3).build();
    }
}

With the above code example, selecting 'analyse data flow to here' on the name field will show the variable name, but with no tree to expand as shown in the screenshot.enter image description here


Solution

  • "Analyze data flow to here" will not work with generated code provided by Lombok annotations.