2

I've added this class:

public class StringExtensions {
  public static String makeMusical( String in ) {
    return "1";
  }
}

@ExtensionMethod({StringExtensions.class})
public class App {
   public static void main(String[] args) {
   String a = "A".makeMusical();  //compiles but ide shows:"cannot resolve method makeMusical"
  }
}

but when trying to use it on a string I get:

"cannot resolve method makeMusical"

(The solution is built and running on IntelliJ but I do not have intellisense / ide doesn't recognized the method)

I've set:

  • Enable annotation processing.
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
roman
  • 607
  • 2
  • 10
  • 18
  • You might want to share the code where you call this method. Also - how is it related to Lombok? It seems that `makeMusical` is your code, not Lombok's. – SHG Apr 02 '17 at 08:40
  • I've updateded the question – roman Apr 02 '17 at 08:48
  • Lombok itself works in Eclipse and Netbeans, while in IntelliJ you need the plugin. According to https://github.com/mplushnikov/lombok-intellij-plugin/issues/21, it's still an open issue. – maaartinus Apr 02 '17 at 17:39

1 Answers1

1

Still experimental feature - Probably the reason for that is here.

The created method makeMusical is static, so I guess when you're trying to intellisense after "A". the IDE tries to auto-complete only using non-static methods.

Hopefully, when the issue in the link will be resolved the IDE plugin will behave accordingly.

BTW - Eclipse intellisense behavior is similar, but it doesn't show any errors though.

SHG
  • 2,516
  • 1
  • 14
  • 20
  • Your second paragraph is confusing as all extension methods must be `static`, just the call site looks like a non-static call. – maaartinus Apr 02 '17 at 17:42
  • Sorry, I didn't understand your comment. What confused you about my second paragraph? – SHG Apr 02 '17 at 18:49
  • The IDE should show the method as the call looks like `"A".makeMusical()`, i.e., like a non-static method (and unlike e.g. `"A".valueOf('x')`, which is better written as `String.valueOf('x')`). In Eclipse, it works. In IntelliJ, it doesn't and AFAIK the only reason is that the plugin doesn't understand `@ExtensionMethod` at all. – maaartinus Apr 02 '17 at 19:33