IC doesn't fully understand "Builder" pattern code

Issue #602 resolved
Derek Wiers created an issue

I have a class that in its use, there is generally a lot of method chaining, like so:

Element e = new Element(something)
  .addElement(somethingElse)
  .addElement(new Element(somethingElseEntirely)
    .addElement(thing))
  .addElement(thing2));

Problem is, the calls to ".addElement" don't get recognized properly - it compiles fine, but clicking in addElement() and hitting Cmd + B (to go to definition) - leads to a "Cannot find declaration to go to" message. See Screenshots.

Again, this code saves & compiles just fine.

Comments (16)

  1. Derek Wiers reporter

    I should also mention, it's not a new class that this is calling - it's been in our org since well before I started using IC and I know that IC has it in its symbol table as single one-off calls to methods in the class work just fine.

  2. Scott Wells repo owner

    Hmmmm...I'll definitely take a look. When I was developing/testing this stuff...in particular the formatter and real-time expression type evaluator...I used the Builder pattern as a major litmus test. I'll definitely put something together like what you've shown and see what's going on. I use Builder and fluent APIs VERY frequently so I want this working properly as much as anyone!

  3. Eric Alexander

    i get the cannot fin declaration in this pattern as well. Even when it is on one line and not split between lines

  4. Scott Wells repo owner

    I'll see if I can include this in the next release which will be focused on bugfixes.

  5. Scott Wells repo owner

    Aha...so this works fine:

    SoqlBuilder builder = new SoqlBuilder();
    String query = builder
        .selectAll()
        .fromx(Account.SObjectType.getDescribe().getName())
        .toSoql();
    

    but the following does not:

    String query = new SoqlBuilder()
        .selectAll()
        .fromx(Account.SObjectType.getDescribe().getName())
        .toSoql();
    

    In fact, while a completion is offered for selectAll() in the second version, the proper references aren't injected into that symbol after completion, and therefore all subsequent expression types fail to evaluate properly. My guess is that it's an issue with the evaluated expression type of the new expression in a set of chained expressions. Should hopefully be easy to fix.

  6. Derek Wiers reporter

    ^^^ for reference, in my theme, recognized methods should be italicized and yellow. Additionally, Cmd + B (go to definition) does not work either.

  7. Scott Wells repo owner

    Well that sucks. Not sure what I would've done to regress that, but I'll definitely take a look. Sorry 'bout that!

  8. Scott Wells repo owner

    Okay, it's not that this has regressed. It's that it wasn't fixed for fluent/builder patterns as inner classes. Should hopefully be quick to fix. I'll see if I can include it in this week's build.

  9. Scott Wells repo owner

    It's fixed. It actually may be been a regression after all, though not as directly as I was looking for. Anyway, the fix will be in this week's build.

  10. Log in to comment