Skip to content

Commit

Permalink
Add checkstyle and establish compliance, fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sfPlayer1 committed Jun 13, 2021
1 parent 8b12b54 commit ecf4bde
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
/.settings/
/.classpath
/.project
/.checkstyle
/.gradle
*.jar
*.tiny
.idea/
!src/test/resources/**
/tiny-remapper/
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
plugins {
id 'java'
id 'maven-publish'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

version = '0.4.0'
version = '0.4.1'

def ENV = System.getenv()
version = version + (ENV.GITHUB_ACTIONS ? "" : "+local")
Expand Down Expand Up @@ -61,6 +62,11 @@ jar {
}
}

checkstyle {
configFile = file("checkstyle.xml")
toolVersion = '8.31'
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
167 changes: 167 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?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"/>
<property name="tabWidth" value="4"/>

<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.minecraft,net.fabricmc"/>
<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="4"/>
<property name="caseIndent" value="0"/>
<property name="throwsIndent" value="4"/>
<property name="arrayInitIndent" value="4"/>
<property name="lineWrappingIndentation" value="8"/>
</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="PackageDeclaration"/>
<module name="PackageName"/>

<!--<module name="InvalidJavadocPosition"/>-->
<module name="JavadocParagraph"/>
<module name="JavadocStyle"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param,@return,@throws,@deprecated"/>
</module>
</module>
</module>
21 changes: 11 additions & 10 deletions src/main/java/net/fabricmc/tinyremapper/AsmClassRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import net.fabricmc.tinyremapper.MemberInstance.MemberType;

final class AsmClassRemapper extends VisitTrackingClassRemapper {
public AsmClassRemapper(ClassVisitor cv, AsmRemapper remapper, boolean rebuildSourceFilenames, boolean checkPackageAccess, boolean skipLocalMapping, boolean renameInvalidLocals) {
AsmClassRemapper(ClassVisitor cv, AsmRemapper remapper, boolean rebuildSourceFilenames, boolean checkPackageAccess, boolean skipLocalMapping, boolean renameInvalidLocals) {
super(cv, remapper);

this.rebuildSourceFilenames = rebuildSourceFilenames;
Expand Down Expand Up @@ -137,7 +137,7 @@ public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, Str
}

public static AnnotationRemapper createAsmAnnotationRemapper(String desc, AnnotationVisitor annotationVisitor, Remapper remapper) {
return annotationVisitor == null ? null : new AsmAnnotationRemapper(annotationVisitor, remapper, desc);
return annotationVisitor == null ? null : new AsmAnnotationRemapper(desc, annotationVisitor, remapper, desc);
}

@Override
Expand All @@ -162,7 +162,7 @@ protected void onVisit(VisitKind kind) {
private MethodNode methodNode;

private static class AsmFieldRemapper extends FieldRemapper {
public AsmFieldRemapper(FieldVisitor fieldVisitor, Remapper remapper) {
AsmFieldRemapper(FieldVisitor fieldVisitor, Remapper remapper) {
super(fieldVisitor, remapper);
}

Expand All @@ -178,7 +178,7 @@ public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, Str
}

private static class AsmMethodRemapper extends MethodRemapper {
public AsmMethodRemapper(MethodVisitor methodVisitor, Remapper remapper, String owner, MethodNode methodNode, boolean checkPackageAccess, boolean skipLocalMapping, boolean renameInvalidLocals) {
AsmMethodRemapper(MethodVisitor methodVisitor, Remapper remapper, String owner, MethodNode methodNode, boolean checkPackageAccess, boolean skipLocalMapping, boolean renameInvalidLocals) {
super(methodNode != null ? methodNode : methodVisitor, remapper);

this.owner = owner;
Expand Down Expand Up @@ -277,8 +277,8 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst
bootstrapMethodArguments[i] = remapper.mapValue(bootstrapMethodArguments[i]);
}

mv.visitInvokeDynamicInsn( // bypass remapper
name,
// bypass remapper
mv.visitInvokeDynamicInsn(name,
remapper.mapMethodDesc(descriptor), (Handle) remapper.mapValue(bootstrapMethodHandle),
bootstrapMethodArguments);
}
Expand Down Expand Up @@ -613,9 +613,10 @@ private String getNameFromType(String type, boolean isArg) {
* other variable which already has that name, e.g.:
* (MyClass ?, MyClass2 ?, MyClass ?) -> (MyClass myClass, MyClass2 myClass2, !myClass2 is already taken!)
*/
for (;nameCounts.putIfAbsent(varName, 1) != null; count++) {
varName = baseVarName + Integer.toString(count);
while (nameCounts.putIfAbsent(varName, 1) != null) {
varName = baseVarName + Integer.toString(count++);
}

nameCounts.put(baseVarName, count); // update name count

return varName;
Expand Down Expand Up @@ -685,8 +686,8 @@ private static boolean isJavaKeyword(String s) {
}

private static class AsmAnnotationRemapper extends AnnotationRemapper {
public AsmAnnotationRemapper(AnnotationVisitor annotationVisitor, Remapper remapper, String annotationDesc) {
super(annotationVisitor, remapper);
AsmAnnotationRemapper(String descriptor, AnnotationVisitor annotationVisitor, Remapper remapper, String annotationDesc) {
super(descriptor, annotationVisitor, remapper);

annotationClass = Type.getType(annotationDesc).getInternalName();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/tinyremapper/AsmRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation;

class AsmRemapper extends Remapper {
public AsmRemapper(TinyRemapper remapper) {
AsmRemapper(TinyRemapper remapper) {
this.remapper = remapper;
}

Expand Down
21 changes: 15 additions & 6 deletions src/main/java/net/fabricmc/tinyremapper/ClassInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public String getName() {
return name;
}

public int getMrjVersion() { return mrjVersion; }
public int getMrjVersion() {
return mrjVersion;
}

public String getSuperName() {
return superName;
Expand All @@ -151,7 +153,9 @@ public boolean isPublicOrPrivate() {
return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE)) != 0;
}

public boolean isMrjCopy() { return mrjOrigin != this; }
public boolean isMrjCopy() {
return mrjOrigin != this;
}

public String[] getInterfaces() {
return interfaces;
Expand All @@ -165,7 +169,9 @@ public MemberInstance getMember(MemberType type, String id) {
return members.get(id);
}

public ClassInstance getMrjOrigin() { return mrjOrigin; }
public ClassInstance getMrjOrigin() {
return mrjOrigin;
}

/**
* Rename the member src to dst and continue propagating in dir.
Expand Down Expand Up @@ -589,8 +595,11 @@ ClassInstance constructMrjCopy() {
// isInput should be false, since the MRJ copy should not be emitted
ClassInstance copy = new ClassInstance(context, false, inputTags, srcPath, data);
copy.init(name, mrjVersion, superName, access, interfaces);
members.values().forEach(member ->
copy.addMember(new MemberInstance(member.type, copy, member.name, member.desc, member.access)));

for (MemberInstance member : members.values()) {
copy.addMember(new MemberInstance(member.type, copy, member.name, member.desc, member.access));
}

// set the origin
copy.mrjOrigin = mrjOrigin;
return copy;
Expand Down Expand Up @@ -631,4 +640,4 @@ public static String getMrjName(String clsName, int mrjVersion) {
private String superName;
private int access;
private String[] interfaces;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public static synchronized FileSystem open(URI uri) throws IOException {

try {
ret = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) { }
} catch (FileSystemNotFoundException e) {
// ignore
}

boolean opened;

Expand Down Expand Up @@ -73,7 +75,7 @@ public static synchronized void close(FileSystem fs) throws IOException {
}

private static class RefData {
public RefData(boolean opened, int refs) {
RefData(boolean opened, int refs) {
this.opened = opened;
this.refs = refs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface MappingAcceptor {
void acceptField(Member field, String dstName);
}

public final class Member {
final class Member {
public Member(String owner, String name, String desc) {
this.owner = owner;
this.name = name;
Expand Down
Loading

0 comments on commit ecf4bde

Please sign in to comment.