Skip to content

Code action: add static import #796

Closed

Description

@str-ay

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

Activity

  1. cedric05 commented on Feb 21, 2019

    @cedric05

    static import itself throwing error, in my case

  2. testforstephen commented on Mar 15, 2019

    @testforstephen
    Collaborator

    @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.*"
          ]
    
  3. testforstephen commented on Mar 15, 2019

    @testforstephen
    Collaborator

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

  4. cedric05 commented on Mar 15, 2019

    @cedric05

    @testforstephen sorry for filing wrong. its working.

  5. added this to the End March 2019 milestone on Mar 26, 2019
  6. fbricon commented on Mar 26, 2019

    @fbricon
    Collaborator

    You asked for it, @testforstephen delivered:

    Mar-26-2019 15-56-04

  7. notmattlythgoe commented on May 21, 2019

    @notmattlythgoe

    @fbricon How are you bringing up the menu?

  8. fbricon commented on May 21, 2019

    @fbricon
    Collaborator

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

  9. bvedant commented on May 4, 2022

    @bvedant

    @fbricon thanks for the update! any chance we could have this feature in Show Code Actions dropdown like it is in IntelliJ, perhaps a toggle to move the feature function to there for those who want it?

  10. appleseedexm commented on Feb 22, 2023

    @appleseedexm

    So for me this was never enabled by default and I had to Edit in settings.json in the settings UI (java.completion.favoriteStaticMembers) for it to add the default static imports to my settings.json.

    Very weird behaviour, but at least it works now. Seems to me like this is not set on install (neither in default / user settings.json).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions