Skip to content

Commit

Permalink
Add checkstyle, editorconfig and update gitignore (sfPlayer1#19)
Browse files Browse the repository at this point in the history
* Add .editorconfig

* Update .gitignore

* Add checkstyle

* Exclude `module-info.java` from checkstyle

Co-authored-by: Player <sfPlayer1@users.noreply.github.com>
  • Loading branch information
NebelNidas and sfPlayer1 authored Nov 29, 2022
1 parent b048335 commit d6e7623
Show file tree
Hide file tree
Showing 53 changed files with 589 additions and 146 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
tab_width = 4

[*.{gradle,java}]
ij_continuation_indent_size = 8
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.fabricmc.**
ij_java_class_count_to_use_import_on_demand = 999

[*.{yml,yaml}]
indent_style = space
indent_size = 2
34 changes: 28 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
/bin/
/build/
# Gradle
.gradle/
build/
bin/
out/
classes/

# Eclipse
.eclipse
*.launch

# Intellij Idea
.idea/
*.iml
*.ipr
*.iws

# VS Code
.vscode/
.settings/
.classpath
.project

# MacOS
*.DS_Store


# Player's personal exclusions
/build_state/
/tmp/
/run/
/lib/
/extbin/
/.gradle/
/.settings/
/.classpath
/.project
/*.jar
/TODO.txt
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'application'
id 'maven-publish'
id "checkstyle"
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'de.jjohannes.extra-java-module-info' version '0.16'
Expand All @@ -27,6 +28,11 @@ sourceSets {
}
}

checkstyle {
configFile = project.file("checkstyle.xml")
toolVersion = project.checkstyle_version
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
175 changes: 175 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="fileExtensions" value="java"/>
<property name="localeLanguage" value="en"/>
<property name="localeCountry" value="US"/>

<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<module name="NewlineAtEndOfFile"/>

<!-- disallow trailing whitespace -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="trailing whitespace"/>
</module>

<!-- note: RegexpMultiline shows nicer messages than Regexp, but has to be outside TreeWalker -->
<!-- disallow multiple consecutive blank lines -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="adjacent blank lines"/>
</module>

<!-- disallow blank after { -->
<module name="RegexpMultiline">
<property name="format" value="\{[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="message" value="blank line after '{'"/>
</module>

<!-- disallow blank before } -->
<module name="RegexpMultiline">
<property name="format" value="\n[\t ]*\r?\n[\t ]*\}"/>
<property name="message" value="blank line before '}'"/>
</module>

<!-- require blank before { in the same indentation level -->
<module name="RegexpMultiline">
<!-- the regex works as follows:
It matches (=fails) for \n<indentation><something>\n<same indentation><control statement>[...]{\n
while <something> is a single line comment, it'll look for a blank line one line earlier
if <something> is a space, indicating a formatting error or ' */', it'll ignore the instance
if <something> is a tab, indicating a continued line, it'll ignore the instance
<control statement> is 'if', 'do', 'while', 'for', 'try' or nothing (instance initializer block)
- first \n: with positive lookbehind (?<=\n) to move the error marker to a more reasonable place
- capture tabs for <indentation>, later referenced via \1
- remaining preceding line as a non-comment (doesn't start with '/', '//', ' ' or '\t') or multiple lines where all but the first are a single line comment with the same indentation
- new line
- <indentation> as captured earlier
- <control statement> as specified above
- { before the next new line -->
<property name="format" value="(?&lt;=\n)([\t]+)(?:[^/\r\n \t][^\r\n]*|/[^/\r\n][^\r\n]*|[^/\r\n][^\r\n]*(\r?\n\1//[^\r\n]*)+)\r?\n\1(|(if|do|while|for|try)[^\r\n]+)\{[\t ]*\r?\n"/>
<property name="message" value="missing blank line before block at same indentation level"/>
</module>

<!-- require blank after } in the same indentation level -->
<module name="RegexpMultiline">
<!-- \n<indentation>}\n<same indentation><whatever unless newline, '}' or starting with cas(e) or def(ault)> -->
<property name="format" value="(?&lt;=\n)([\t]+)\}\r?\n\1(?:[^\r\n\}cd]|c[^\r\na]|ca[^\r\ns]|d[^\r\ne]|de[^\r\nf])"/>
<property name="message" value="missing blank line after block at same indentation level"/>
</module>

<module name="TreeWalker">
<!-- Ensure all imports are ship shape -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<module name="ImportOrder">
<property name="groups" value="java,javax,*,net.fabricmc,matcher"/>
<property name="ordered" value="false"/><!-- the plugin orders alphabetically without considering separators.. -->
<property name="separated" value="true"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>

<!-- Ensures braces are at the end of a line -->
<module name="LeftCurly"/>
<module name="RightCurly"/>

<!-- single line statements on one line, -->
<module name="NeedBraces">
<property name="tokens" value="LITERAL_IF,LITERAL_FOR,LITERAL_WHILE"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="NeedBraces">
<property name="tokens" value="LITERAL_ELSE,LITERAL_DO"/>
<property name="allowSingleLineStatement" value="false"/>
</module>

<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="allowMultipleEmptyLines" value="false"/>
<!-- exclude METHOD_DEF and VARIABLE_DEF -->
<property name="tokens" value="PACKAGE_DEF,IMPORT,STATIC_IMPORT,CLASS_DEF,INTERFACE_DEF,ENUM_DEF,STATIC_INIT,INSTANCE_INIT,CTOR_DEF"/>
</module>

<module name="OperatorWrap"/>
<module name="SeparatorWrap">
<property name="tokens" value="DOT,ELLIPSIS,AT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="tokens" value="COMMA,SEMI"/>
<property name="option" value="eol"/>
</module>

<module name="Indentation">
<property name="basicOffset" value="8"/>
<property name="caseIndent" value="0"/>
<property name="throwsIndent" value="8"/>
<property name="arrayInitIndent" value="8"/>
<property name="lineWrappingIndentation" value="16"/>
</module>

<module name="ParenPad"/>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceAfter">
<!-- allow ARRAY_INIT -->
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
</module>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<!-- Allow PLUS, MINUS, MUL, DIV as they may be more readable without spaces in some cases -->
<property name="tokens"
value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="GenericWhitespace"/>
<module name="CommentsIndentation"/>

<module name="ArrayTypeStyle"/>
<module name="DefaultComesLast">
<property name="skipIfLastAndSharedWithCase" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>

<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<module name="AnnotationLocation"/>
<module name="MissingOverride"/>

<!-- By default this allows catch blocks with only comments -->
<module name="EmptyCatchBlock"/>

<!-- Enforce tabs -->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* ([^*]|\*[^ /])"/>
<property name="message" value="non-tab indentation"/>
</module>

<module name="OuterTypeFilename"/>

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph"/>
<module name="JavadocStyle"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module>

<!-- Prevent var for all cases other than new instance creation -->
<module name="MatchXpath">
<property name="query" value="//VARIABLE_DEF[./TYPE/IDENT[@text='var'] and not(./ASSIGN/EXPR/LITERAL_NEW)]"/>
</module>
</module>
</module>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ procyon_version = 0.6.0
mappingio_version = 0.3.0
javaparser_version = 3.24.2
javafx_version = 17.0.2
checkstyle_version = 10.3.4
1 change: 1 addition & 0 deletions src/matcher/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package matcher;

import javafx.application.Application;

import matcher.config.Config;
import matcher.gui.Gui;

Expand Down
8 changes: 5 additions & 3 deletions src/matcher/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

public class Util {
public static <T> Set<T> newIdentityHashSet() {
return Collections.newSetFromMap(new IdentityHashMap<>());//new IdentityHashSet<>();
return Collections.newSetFromMap(new IdentityHashMap<>()); //new IdentityHashSet<>();
}

public static <T> Set<T> newIdentityHashSet(Collection<? extends T> c) {
Set<T> ret = Collections.newSetFromMap(new IdentityHashMap<>(c.size()));
ret.addAll(c);

return ret;//new IdentityHashSet<>(c);
return ret; //new IdentityHashSet<>(c);
}

public static <T> Set<T> copySet(Set<T> set) {
Expand Down Expand Up @@ -130,7 +130,9 @@ public static void closeSilently(Closeable c) {

try {
c.close();
} catch (IOException e) { }
} catch (IOException e) {
// ignored
}
}

public static boolean isCallToInterface(MethodInsnNode insn) {
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/bcremap/AsmClassRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected MethodVisitor createMethodRemapper(MethodVisitor mv) {
}

private class AsmMethodRemapper extends MethodRemapper {
public AsmMethodRemapper(MethodVisitor mv, AsmRemapper remapper) {
AsmMethodRemapper(MethodVisitor mv, AsmRemapper remapper) {
super(mv, remapper);

this.remapper = remapper;
Expand Down
3 changes: 1 addition & 2 deletions src/matcher/classifier/ClassClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public double getScore(ClassInstance clsA, ClassInstance clsB, ClassEnvironment
}
};


private static AbstractClassifier hierarchySiblings = new AbstractClassifier("hierarchy siblings") {
@Override
public double getScore(ClassInstance clsA, ClassInstance clsB, ClassEnvironment env) {
Expand Down Expand Up @@ -533,7 +532,7 @@ private static void extractNumbers(ClassInstance cls, Set<Integer> ints, Set<Lon
}
}

public static abstract class AbstractClassifier implements IClassifier<ClassInstance> {
public abstract static class AbstractClassifier implements IClassifier<ClassInstance> {
public AbstractClassifier(String name) {
this.name = name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/classifier/ClassifierResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public String toString() {

private final IClassifier<T> classifier;
private final double score;
}
}
2 changes: 1 addition & 1 deletion src/matcher/classifier/FieldClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static double compareAsmNodes(FieldInstance a, FieldInstance b) {
return a.getAsmNode() == null && b.getAsmNode() == null ? 1 : 0;
}

public static abstract class AbstractClassifier implements IClassifier<FieldInstance> {
public abstract static class AbstractClassifier implements IClassifier<FieldInstance> {
public AbstractClassifier(String name) {
this.name = name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/classifier/IClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public interface IClassifier<T> {
String getName();
double getWeight();
double getScore(T a, T b, ClassEnvironment env);
}
}
2 changes: 1 addition & 1 deletion src/matcher/classifier/IRanker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

public interface IRanker<T> {
List<RankResult<T>> rank(T src, T[] dsts, ClassifierLevel level, ClassEnvironment env, double maxMismatch);
}
}
4 changes: 2 additions & 2 deletions src/matcher/classifier/MatchingCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public void clear() {
cache.clear();
}

public static final class CacheToken<t> {}
public static final class CacheToken<t> { }

private static class CacheKey<T extends Matchable<T>> {
public CacheKey(CacheToken<?> token, T a, T b) {
CacheKey(CacheToken<?> token, T a, T b) {
this.token = token;
this.a = a;
this.b = b;
Expand Down
4 changes: 2 additions & 2 deletions src/matcher/classifier/MethodClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ private static double compareAsmNodes(MethodInstance a, MethodInstance b) {
return a.getAsmNode() == null && b.getAsmNode() == null ? 1 : 0;
}

public static abstract class AbstractClassifier implements IClassifier<MethodInstance> {
public AbstractClassifier(String name) {
public abstract static class AbstractClassifier implements IClassifier<MethodInstance> {
AbstractClassifier(String name) {
this.name = name;
}

Expand Down
2 changes: 1 addition & 1 deletion src/matcher/classifier/MethodVarClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public double getScore(MethodVarInstance argA, MethodVarInstance argB, ClassEnvi
}
};

private static abstract class AbstractClassifier implements IClassifier<MethodVarInstance> {
private abstract static class AbstractClassifier implements IClassifier<MethodVarInstance> {
AbstractClassifier(String name) {
this.name = name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/classifier/RankResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public List<ClassifierResult<T>> getResults() {
private final T subject;
private final double score;
private final List<ClassifierResult<T>> results;
}
}
Loading

0 comments on commit d6e7623

Please sign in to comment.