Lombok + Intellij:无法解析 super class 的方法

Lombok + Intellij: cannot resolve method of super class

我有一个超类

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ErrorResponse {
    @JsonProperty
    private String message;
}

我有一个child一个

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
@EqualsAndHashCode(callSuper=true)
public class AskQuestionErrorResponse extends ErrorResponse {
    @JsonProperty
    private String status;

    @Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
    private AskQuestionErrorResponse(String status, String message){
        super(message);
        this.status = status;
    }
}

当我使用生成器创建这样的 object 时

AskQuestionErrorResponse._builder()
   .status(1)
   .message("my message here").build()

Intellij 显示 message 为红色,但存在一个问题 cannot resolve method 'message(java.lang.String)' 无论如何,项目编译并运行,即使出现此错误。

我已经启用了注释处理。

如果我像这样评论来自超类的字段

AskQuestionErrorResponse._builder()
                .status(ex.getStatus().getValue()
                //.message(ex.getMessage()
                ).build()

有效。它似乎看不到超类成员。我也试过 maven 清理和安装,重建项目。

更新 龙目岛插件已安装

注释处理器在 PreferencesDefault preferences

中启用

您需要安装Intellij Lombok插件,才能在编译成字节码前理解注解。 https://projectlombok.org/setup/intellij

我找到了。如果您查看我的 class,您会看到两个 @Builder 注释。我删除了第一个,奇迹发生了。现在我的 class 看起来像这样并且没有警告

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper=true)
public class AskQuestionErrorResponse extends ErrorResponse {
    @JsonProperty
    private String status;

    @Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
    public AskQuestionErrorResponse(String status, String message){
        super(message);
        this.status = status;
    }
}

希望对您有所帮助:)