Import everything from a package and its subpackages (or classes)

Started by overlisted, November 03, 2019, 21:35:28

Previous topic - Next topic

overlisted

Is there a way to import everything from a package and its subpackages or classes? Like
import static org.lwjgl.opengl.**;


I assume there is code generator that can convert it to legal Java syntax, but I can't find it.

KaiHH

If you want to implement against a particular OpenGL version, such as OpenGL 3.3 with GL33, and also want to have all methods from all earlier versions be visible, then with at least LWJGL 3.2.0 simply do:
import static org.lwjgl.opengl.GL33.*;

See the last paragraph of https://github.com/LWJGL/lwjgl3-wiki/wiki/2.2.-OpenGL#calling-opengl-functions

overlisted

Quote from: KaiHH on November 03, 2019, 21:55:54
If you want to implement against a particular OpenGL version, such as OpenGL 3.3 with GL33, and also want to have all methods from all earlier versions be visible, then with at least LWJGL 3.2.0 simply do:
import static org.lwjgl.opengl.GL33.*;

See the last paragraph of https://github.com/LWJGL/lwjgl3-wiki/wiki/2.2.-OpenGL#calling-opengl-functions

Thanks. But it's hard to find and import methods from special GL versions (because intellij autocomplete doesn't search static methods without their class name).

KaiHH

Quote from: True_han on November 03, 2019, 22:52:39
But it's hard to find and import methods from special GL versions (because intellij autocomplete doesn't search static methods without their class name).
And this is exactly what you don't have to do when you use a single static import of the highest OpenGL version you want to support / program against.
Then all methods from all earlier OpenGL versions will be visible/available to you automatically and autocomplete just fine.
For example, when doing the following:
import static org.lwjgl.opengl.GL33.*;
public class Test {
    public static void main(String[] args) {
        glDrawA
    }
}

When having the cursor behind the "glDrawA" and hitting Ctrl+Space, it will suggest glDrawArrays.

Apart from that, IntelliJ IDEA does support importing static methods without a static import of a class when you write out the complete method name and at least tell it that it is a method by writing open and close parentheses after the method name. When you then have the cursor on the method name you just called and hit Alt+Enter it will suggest "Import static method..." and tell you two classes to import from (GL11 and GL11C).