Skip to content

Commit

Permalink
Add Checkstyle (#13)
Browse files Browse the repository at this point in the history
Adding Checkstyle with altered sun style config. Fixed trivial violations.
  • Loading branch information
Nianna authored Jun 4, 2023
1 parent 480ff33 commit 719ecc7
Show file tree
Hide file tree
Showing 69 changed files with 722 additions and 136 deletions.
163 changes: 163 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<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/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>

<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>

<!-- 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="140"/>
<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> -->

<module name="TreeWalker">

<!-- Checks for Javadoc comments. -->
<!-- See https://checkstyle.org/config_javadoc.html -->
<module name="InvalidJavadocPosition"/>
<module name="JavadocStyle"/>

<!-- 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_imports.html -->
<module name="AvoidStarImport"/>
<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_modifier.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">
<property name="option" value="text"/>
</module>
<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="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="TodoComment"/>
<module name="UpperEll"/>

<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
<property name="optional" value="true"/>
</module>

</module>

</module>
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down Expand Up @@ -97,4 +118,5 @@
</dependency>

</dependencies>

</project>
9 changes: 6 additions & 3 deletions src/main/java/com/github/nianna/karedi/I18N.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
import java.util.ResourceBundle;

public class I18N {
private static Locale POLISH = new Locale("pl", "PL");
private static Locale BRITISH_ENGLISH = new Locale("en", "GB");
private static final Locale POLISH = new Locale("pl", "PL");
private static final Locale BRITISH_ENGLISH = new Locale("en", "GB");

private static ResourceBundle bundle;

private I18N() {
}

public static String get(final String key, final Object... args) {
if (bundle != null) {
try {
return MessageFormat.format(bundle.getString(key), args);
} catch (IllegalArgumentException| MissingResourceException e) {
} catch (IllegalArgumentException | MissingResourceException e) {
e.printStackTrace();
return key;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/nianna/karedi/KarediApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.github.nianna.karedi.dialog.SaveChangesAlert;

public class KarediApp extends Application {
private final static String APP_NAME = "Karedi";
private final static String BASIC_CSS_STYLESHEET = "/Karedi.css";
private final static String NIGHT_MODE_CSS_STYLESHEET = "/NightMode.css";
private static final String APP_NAME = "Karedi";
private static final String BASIC_CSS_STYLESHEET = "/Karedi.css";
private static final String NIGHT_MODE_CSS_STYLESHEET = "/NightMode.css";

private static KarediApp instance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public boolean wasFired(KeyEvent event) {
return getAccelerator() != null && getAccelerator().match(event);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ public enum KarediActions {
// DEBUG
RESET_SEQUENCER,

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public class AudioFileLoader {

private AudioFileLoader() {
}

/**
* Loads the specified mp3 file on a background thread and passes the
* optional result to the given consumer.
Expand All @@ -34,7 +37,7 @@ public static void loadMp3File(File file, Consumer<Optional<Mp3File>> fileConsum
private static class LoadMp3FileTask extends Task<Mp3File> {
private File file;

public LoadMp3FileTask(File file) {
LoadMp3FileTask(File file) {
this.file = file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,49 @@ public interface CachedAudioFile {
*
* @return the array of bytes with audio data
*/
public byte[] getCache();
byte[] getCache();

/**
* Obtains the frames per second value of this file. It can be later used
* for calculating frame number from positions expressed in milliseconds.
*
* @return the frames per second value of this audio file
*/
public Double getFPS();
Double getFPS();

/**
* Obtains the media length in milliseconds.
*
* @return the length in milliseconds
*/
public long getDuration();
long getDuration();

/**
* Gets the associated file.
*
* @return file
*/
public File getFile();
File getFile();

/**
* Loads the content of the file and caches it. Updates all properties.
*
* @throws IOException
* if an input error has occurred
*/
public void reload() throws IOException;
void reload() throws IOException;

/**
* The volume of the file. It is expressed as a number between 0 and 1, 0.6
* is assumed to be the original volume.
*/
public DoubleProperty volumeProperty();
DoubleProperty volumeProperty();

default public Double getVolume() {
default Double getVolume() {
return volumeProperty().get();
}

default public void setVolume(double value) {
default void setVolume(double value) {
volumeProperty().set(value);
}

Expand All @@ -72,7 +72,7 @@ default public void setVolume(double value) {
* @return the name of the file (just the last name in the pathname's
* sequence)
*/
default public String getName() {
default String getName() {
return getFile().getName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private class PlayTask extends Task<Long> {
private int endFrame;
private AdvancedPlayer player;

public PlayTask(long startMillis, long endMillis) {
PlayTask(long startMillis, long endMillis) {
super();
if (startMillis < endMillis) {
startFrame = getFrameForMillis(file.getFPS(), startMillis);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/nianna/karedi/audio/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private class TimeUpdater extends Task<Long> {
private long endMillis;
private long updateInterval;

public TimeUpdater(long startMillis, long endMillis, long updateInterval) {
TimeUpdater(long startMillis, long endMillis, long updateInterval) {
super();
this.startMillis = startMillis;
this.endMillis = endMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class SamplesPerFrame {
private SamplesPerFrame() {
}

private static final int[][] samplesPerFrame = new int[][] {
private static final int[][] SAMPLES_PER_FRAME = new int[][] {
{ // MPEG Version 1
384, // Layer1
1152, // Layer2
Expand All @@ -30,11 +30,11 @@ public static int get(String version, String layer) {
if (version != null && layer != null) {
switch (version) {
case MpegFrame.MPEG_VERSION_1_0:
return get(samplesPerFrame[0], layer);
return get(SAMPLES_PER_FRAME[0], layer);
case MpegFrame.MPEG_VERSION_2_0:
return get(samplesPerFrame[1], layer);
return get(SAMPLES_PER_FRAME[1], layer);
case MpegFrame.MPEG_VERSION_2_5:
return get(samplesPerFrame[1], layer);
return get(SAMPLES_PER_FRAME[1], layer);
}
}
return DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.nianna.karedi.song.Note;

public class MergeNotesCommand extends CommandComposite {
public static enum MergeMode {
public enum MergeMode {
TONES,
SYNCHRO,
LYRICS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RescaleNoteToBpmCommand extends Command {
private int oldLength;
private int oldStart;

public RescaleNoteToBpmCommand(Note note, double scale) {
RescaleNoteToBpmCommand(Note note, double scale) {
super(I18N.get("command.rescale_note_bpm"));
this.note = note;
this.scale = scale;
Expand Down
Loading

0 comments on commit 719ecc7

Please sign in to comment.