Vscode-java: Code action: add static import

Created on 13 Feb 2019  路  7Comments  路  Source: redhat-developer/vscode-java

Hi. I wonder that there is no way to quickly add static import (+ refactor all occurances).
It is really actual while writing tests or using spring 5 functional routing for example.

  • Visual Studio Code version: 1.32
  • Java extension version: 0.38
code action enhancement

Most helpful comment

Click on static method, Ctrl+. (Cmd+. on mac) or click on lightbulb or right-click -> Code Action

All 7 comments

static import itself throwing error, in my case

@jnesspro By default, the Java extension will only recommend static import for the members below.

    "java.completion.favoriteStaticMembers": [
        "org.junit.Assert.*",
        "org.junit.Assume.*",
        "org.junit.jupiter.api.Assertions.*",
        "org.junit.jupiter.api.Assumptions.*",
        "org.junit.jupiter.api.DynamicContainer.*",
        "org.junit.jupiter.api.DynamicTest.*",
        "org.mockito.Mockito.*",
        "org.mockito.ArgumentMatchers.*",
        "org.mockito.Answers.*"
      ]

If you want to enable static import for spring 5 members, you need modify the user settings and append your favorite package into java.completion.favoriteStaticMembers.
For example:

    "java.completion.favoriteStaticMembers": [
        ...
        "org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*",
        "org.springframework.test.web.servlet.result.MockMvcResultMatchers.*"
      ]

@cedric05 Can you execute VS Code command Java: Open Java Language Server log file, and share us the log?

@testforstephen sorry for filing wrong. its working.

You asked for it, @testforstephen delivered:

Mar-26-2019 15-56-04

@fbricon How are you bringing up the menu?

Click on static method, Ctrl+. (Cmd+. on mac) or click on lightbulb or right-click -> Code Action

Was this page helpful?
0 / 5 - 0 ratings