Hello Guest

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

  • 3 Replies
  • 137 Views
*

Offline True_han

  • *
  • 8
  • русские вперед
Is there a way to import everything from a package and its subpackages or classes? Like
Code: [Select]
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.
noob in opengl ;)

*

Offline KaiHH

  • ****
  • 207
Re: Import everything from a package and its subpackages (or classes)
« Reply #1 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:
Code: [Select]
import static org.lwjgl.opengl.GL33.*;
See the last paragraph of https://github.com/LWJGL/lwjgl3-wiki/wiki/2.2.-OpenGL#calling-opengl-functions

*

Offline True_han

  • *
  • 8
  • русские вперед
Re: Import everything from a package and its subpackages (or classes)
« Reply #2 on: November 03, 2019, 22:52:39 »
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:
Code: [Select]
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).
noob in opengl ;)

*

Offline KaiHH

  • ****
  • 207
Re: Import everything from a package and its subpackages (or classes)
« Reply #3 on: November 03, 2019, 23:24:34 »
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:
Code: [Select]
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).
« Last Edit: November 03, 2019, 23:35:17 by KaiHH »