Search code examples
javaeclipsebuilderlombokautosuggest

Eclipse Lombok builder add new suggestion


For class with @Builder Eclipse auto complete (Ctrl+Space) builder methods:

ResponseVO.builder().

It also suggests new which can't work

ResponseVO.builder().new;

Error:

Syntax error on token(s), misplaced construct(s)

Also as creating new instance

new ResponseVO.builder();

Error:

ResponseVO.builder cannot be resolved to a type

Why new is added in suggestion to Builder class?

Checked with Eclipse 4.9.0 version and lower

EDIT

It's happening without lombok's builder, if extracting generated code using inner class Eclipse suggest new when calling MyClass.BuilderExampleBuilder.builder().

public class MyClass {
  public static BuilderExampleBuilder builder() {
    return new BuilderExampleBuilder();
  }   
  public static class BuilderExampleBuilder {       
    BuilderExampleBuilder() { }
  }
}

Opened Bug 558621 - [content assist] Eclipse suggests 'new' for qualified allocation even if no inner class exists


Solution

  • Proposing new after . is fundamentally correct, helping the user to create a qualified instance creation a la outerInstance.new InnerClass() (see JLS §15.9)

    It seems wrong, however, that Eclipse proposes this syntax even if no applicable inner class exists.