Add checkstyle plugin

This commit is contained in:
SpaiR committed 2019-12-29 23:59:35 +03:00
1 parent 3e7c50296c
commit 51fcd63b57
4 files changed
+225 -21

No files matched your search

+193
View File
@@ -0,0 +1,193 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
- the Java Language Specification at
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
- the Sun Code Conventions at https://www.oracle.com/technetwork/java/codeconvtoc-136057.html
- the Javadoc guidelines at
https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
- some best practices
Checkstyle is very configurable. Be sure to read the documentation at
https://checkstyle.org (or in your downloaded distribution).
Most Checks are configurable, be sure to consult the documentation.
To completely disable a check, just comment it out or delete it from the file.
Finally, it is worth reading the documentation.
-->
<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
https://checkstyle.org/5.x/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- Checks that a package-info.java file exists for each package. -->
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
<!-- <module name="JavadocPackage"/>-->
<!-- Checks whether files end with a new line. -->
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>
<!-- Checks that property files contain the same keys. -->
<!-- See https://checkstyle.org/config_misc.html#Translation -->
<module name="Translation"/>
<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="FileLength"/>
<module name="LineLength">
<property name="max" value="160"/>
<property name="fileExtensions" value="java"/>
</module>
<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="FileTabCharacter"/>
<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<!-- Checks for Headers -->
<!-- See https://checkstyle.org/config_header.html -->
<!-- <module name="Header"> -->
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
<!-- <property name="fileExtensions" value="java"/> -->
<!-- </module> -->
<!-- Suppress warnings by using -->
<module name="SuppressWarningsFilter"/>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See https://checkstyle.org/config_javadoc.html -->
<!-- <module name="InvalidJavadocPosition"/>-->
<!-- <module name="JavadocMethod"/>-->
<!-- <module name="JavadocType"/>-->
<!-- <module name="JavadocVariable"/>-->
<!-- <module name="JavadocStyle"/>-->
<!-- <module name="MissingJavadocMethod"/>-->
<!-- Checks for Naming Conventions. -->
<!-- See https://checkstyle.org/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_import.html -->
<module name="AvoidStarImport">
<property name="excludes" value="org.lwjgl.opengl.GL30,org.lwjgl.glfw.GLFW"/>
</module>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>
<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<!-- Modifier Checks -->
<!-- See https://checkstyle.org/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See https://checkstyle.org/config_design.html -->
<module name="DesignForExtension"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="FinalLocalVariable"/>
<module name="TodoComment"/>
<module name="UpperEll"/>
<!-- See https://checkstyle.sourceforge.io/config_annotation.html#SuppressWarningsHolder -->
<module name="SuppressWarningsHolder"/>
<module name="SuppressionCommentFilter"/>
</module>
</module>
+1
View File
@@ -2,6 +2,7 @@ import org.gradle.internal.os.OperatingSystem
plugins { plugins {
id 'java' id 'java'
id 'checkstyle'
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@@ -4,13 +4,18 @@ import imgui.DrawData;
import imgui.ImGui; import imgui.ImGui;
import imgui.TexDataRGBA32; import imgui.TexDataRGBA32;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Objects; import java.util.Objects;
import static org.lwjgl.opengl.GL30.*; import static org.lwjgl.opengl.GL30.*;
/** /**
* This class mostly a straightforward port of the https://raw.githubusercontent.com/ocornut/imgui/v1.74/examples/imgui_impl_opengl3.cpp adapted for Java and LWJGL realms. * This class mostly a straightforward port of the https://raw.githubusercontent.com/ocornut/imgui/v1.74/examples/imgui_impl_opengl3.cpp
* adapted for Java and LWJGL realms.
* <p> * <p>
* It do support a backup of the current GL state before rendering and restoring of its initial state after. * It do support a backup of the current GL state before rendering and restoring of its initial state after.
* But some specific state variables may be missed (all which are hidden under '#ifdef' macros in the original 'imgui_impl_opengl3.cpp' file). * But some specific state variables may be missed (all which are hidden under '#ifdef' macros in the original 'imgui_impl_opengl3.cpp' file).
@@ -18,7 +23,8 @@ import static org.lwjgl.opengl.GL30.*;
* By default this implementation uses shaders with 130 version of GLSL (OpenGL 3.0). * By default this implementation uses shaders with 130 version of GLSL (OpenGL 3.0).
* You can provide your own shaders into the {@link ImGuiImplGl3#init(CharSequence, CharSequence)} method. * You can provide your own shaders into the {@link ImGuiImplGl3#init(CharSequence, CharSequence)} method.
*/ */
public class ImGuiImplGl3 { @SuppressWarnings("MagicNumber")
public final class ImGuiImplGl3 {
private int vBufferHandle = 0; private int vBufferHandle = 0;
private int iBufferHandle = 0; private int iBufferHandle = 0;
@@ -240,12 +246,12 @@ public class ImGuiImplGl3 {
glBindBuffer(GL_ARRAY_BUFFER, lastArrayBuffer[0]); glBindBuffer(GL_ARRAY_BUFFER, lastArrayBuffer[0]);
glBlendEquationSeparate(lastBlendEquationRgb[0], lastBlendEquationAlpha[0]); glBlendEquationSeparate(lastBlendEquationRgb[0], lastBlendEquationAlpha[0]);
glBlendFuncSeparate(lastBlendSrcRgb[0], lastBlendDstRgb[0], lastBlendSrcAlpha[0], lastBlendDstAlpha[0]); glBlendFuncSeparate(lastBlendSrcRgb[0], lastBlendDstRgb[0], lastBlendSrcAlpha[0], lastBlendDstAlpha[0]);
// @formatter:off // @formatter:off CHECKSTYLE:OFF
if (lastEnableBlend) glEnable(GL_BLEND); else glDisable(GL_BLEND); if (lastEnableBlend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (lastEnableCullFace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if (lastEnableCullFace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (lastEnableDepthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if (lastEnableDepthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (lastEnableScissorTest) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); if (lastEnableScissorTest) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
// @formatter:on // @formatter:on CHECKSTYLE:ON
glViewport(lastViewport[0], lastViewport[1], lastViewport[2], lastViewport[3]); glViewport(lastViewport[0], lastViewport[1], lastViewport[2], lastViewport[3]);
glScissor(lastScissorBox[0], lastScissorBox[1], lastScissorBox[2], lastScissorBox[3]); glScissor(lastScissorBox[0], lastScissorBox[1], lastScissorBox[2], lastScissorBox[3]);
} }
@@ -260,17 +266,17 @@ public class ImGuiImplGl3 {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
final float L = drawData.displayPosX; final float left = drawData.displayPosX;
final float R = drawData.displayPosX + drawData.displaySizeX; final float right = drawData.displayPosX + drawData.displaySizeX;
final float T = drawData.displayPosY; final float top = drawData.displayPosY;
final float B = drawData.displayPosY + drawData.displaySizeY; final float bottom = drawData.displayPosY + drawData.displaySizeY;
// Orthographic matrix projection // Orthographic matrix projection
projMatrix[0] = 2.0f / (R - L); projMatrix[0] = 2.0f / (right - left);
projMatrix[5] = 2.0f / (T - B); projMatrix[5] = 2.0f / (top - bottom);
projMatrix[10] = -1.0f; projMatrix[10] = -1.0f;
projMatrix[12] = (R + L) / (L - R); projMatrix[12] = (right + left) / (left - right);
projMatrix[13] = (T + B) / (B - T); projMatrix[13] = (top + bottom) / (bottom - top);
projMatrix[15] = 1.0f; projMatrix[15] = 1.0f;
// Bind vertices // Bind vertices
@@ -329,8 +335,8 @@ public class ImGuiImplGl3 {
private CharSequence readFromResources(final String path) { private CharSequence readFromResources(final String path) {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
try (final InputStream in = getClass().getClassLoader().getResourceAsStream(path); try (InputStream in = getClass().getClassLoader().getResourceAsStream(path);
final BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(in)))) { BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(in)))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
builder.append(line).append('\n'); builder.append(line).append('\n');
@@ -1,6 +1,9 @@
import imgui.ImGui; import imgui.ImGui;
import imgui.ImGuiString; import imgui.ImGuiString;
import imgui.enums.*; import imgui.enums.ImGuiCond;
import imgui.enums.ImGuiInputTextFlags;
import imgui.enums.ImGuiKey;
import imgui.enums.ImGuiTreeNodeFlags;
import imgui.gl3.ImGuiImplGl3; import imgui.gl3.ImGuiImplGl3;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode;
@@ -12,11 +15,12 @@ import java.util.Objects;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks; import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.system.MemoryStack.stackPush; import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.system.MemoryUtil.NULL; import static org.lwjgl.system.MemoryUtil.NULL;
public class ImGuiGlfwExample { @SuppressWarnings("MagicNumber")
public final class ImGuiGlfwExample {
private static final int DEFAULT_WIDTH = 1024; private static final int DEFAULT_WIDTH = 1024;
private static final int DEFAULT_HEIGHT = 768; private static final int DEFAULT_HEIGHT = 768;
@@ -34,7 +38,7 @@ public class ImGuiGlfwExample {
private final double[] mousePosX = new double[1]; private final double[] mousePosX = new double[1];
private final double[] mousePosY = new double[1]; private final double[] mousePosY = new double[1];
// TODO: move this into ImGuiIO.KeysDown // TODO move this into ImGuiIO.KeysDown
private boolean ctrlKeyDown; private boolean ctrlKeyDown;
private boolean shiftKeyDown; private boolean shiftKeyDown;
private boolean altKeyDown; private boolean altKeyDown;
@@ -75,7 +79,7 @@ public class ImGuiGlfwExample {
} }
// Get the thread stack and push a new frame // Get the thread stack and push a new frame
try (final MemoryStack stack = stackPush()) { try (MemoryStack stack = stackPush()) {
final IntBuffer pWidth = stack.mallocInt(1); // int* final IntBuffer pWidth = stack.mallocInt(1); // int*
final IntBuffer pHeight = stack.mallocInt(1); // int* final IntBuffer pHeight = stack.mallocInt(1); // int*
@@ -83,7 +87,7 @@ public class ImGuiGlfwExample {
glfwGetWindowSize(window, pWidth, pHeight); glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor // Get the resolution of the primary monitor
GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor())); final GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor()));
// Center the window // Center the window
glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); glfwSetWindowPos(window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);