Skip to content

Commit

Permalink
Enable checkstyle (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 authored Jul 1, 2024
1 parent 2edfbc4 commit 2cd49e6
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 174 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ repositories {
sourceSets {
legacy {
ext.languageVersion = 8
ext.compatibility = '1.6'
ext.compatibility = '1.8'
}
main {
compileClasspath += legacy.output
ext.languageVersion = 8
ext.compatibility = '1.6'
ext.compatibility = '1.8'
}
ap {
compileClasspath += main.output
Expand All @@ -96,13 +96,13 @@ sourceSets {
fernflower {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.6'
ext.compatibility = '1.8'
ext.modularityExcluded = true
}
agent {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.6'
ext.compatibility = '1.8'
}
bridge {
compileClasspath += main.output
Expand Down Expand Up @@ -322,7 +322,7 @@ checkstyle {
"year" : project.inceptionYear
]
configFile = file("checkstyle.xml")
toolVersion = '8.44'
toolVersion = '10.17.0'
}

// Source compiler configuration
Expand Down
9 changes: 1 addition & 8 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Description: none
-->
<module name="Checker">
<property name="severity" value="warning"/>
<property name="severity" value="error"/>
<property name="charset" value="UTF-8"/>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
Expand Down Expand Up @@ -131,13 +131,6 @@
<module name="UncommentedMain"/>
<module name="SuppressionCommentFilter"/>
</module>
<module name="LineLength">
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
<property name="max" value="150"/>
</module>
<module name="LineLength">
<property name="ignorePattern" value="^[ ]*([a-zA-Z0-9\{\}\+\|\&amp;\&quot;@\(\)\?\.\:]|//)"/>
</module>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/spongepowered/asm/mixin/FabricUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,25 @@ public final class FabricUtil {
public static final String KEY_COMPATIBILITY = "fabric-compat";

// fabric mixin version compatibility boundaries, (major * 1000 + minor) * 1000 + patch

/**
* Fabric compatibility version 0.9.2
*/
public static final int COMPATIBILITY_0_9_2 = 9002; // 0.9.2+mixin.0.8.2 incompatible local variable handling

/**
* Fabric compatibility version 0.10.0
*/
public static final int COMPATIBILITY_0_10_0 = 10000; // 0.10.0+mixin.0.8.4

/**
* Fabric compatibility version 0.14.0
*/
public static final int COMPATIBILITY_0_14_0 = 14000; // 0.14.0+mixin.0.8.6

/**
* Latest compatibility version
*/
public static final int COMPATIBILITY_LATEST = COMPATIBILITY_0_14_0;

public static String getModId(IMixinConfig config) {
Expand Down Expand Up @@ -65,4 +81,7 @@ private static <T> T getDecoration(IMixinConfig config, String key, T defaultVal
return defaultValue;
}
}

private FabricUtil() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ private void inject(final Callback callback) {
}
}
this.invokeCallback(callback, callbackMethod);
if (callback.usesCallbackInfo) this.injectCancellationCode(callback);
if (callback.usesCallbackInfo) {
this.injectCancellationCode(callback);
}

callback.inject();
this.info.notifyInjected(callback.target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import java.util.Arrays;

public class InvokeUtil {
public final class InvokeUtil {
public static Type[] getOriginalArgs(InjectionNode node) {
return Type.getArgumentTypes(((MethodInsnNode) node.getOriginalTarget()).desc);
}
Expand All @@ -47,4 +47,7 @@ public static Type[] getCurrentArgs(InjectionNode node) {
}
return currentArgs;
}

private InvokeUtil() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import org.objectweb.asm.tree.AbstractInsnNode;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.CompareUtil;

/**
* Used to keep track of instruction nodes in a {@link Target} method which are
Expand Down Expand Up @@ -198,7 +197,7 @@ public <V> V getDecoration(String key) {
*/
@Override
public int compareTo(InjectionNode other) {
return other == null ? Integer.MAX_VALUE : CompareUtil.compare(this.hashCode(), other.hashCode());
return other == null ? Integer.MAX_VALUE : Integer.compare(this.hashCode(), other.hashCode());
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ public static class FrameData {
* Frame local size
*/
public final int size;
public final int rawSize; // Fabric non-adjusted frame size for legacy support

/**
* Fabric: non-adjusted frame size for legacy support
*/
public final int rawSize;

FrameData(int index, int type, int locals, int size) {
this.index = index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public String getHandlerName(MixinInfo mixin, MixinMethodNode method) {
String mod = MethodMapper.getMixinSourceId(mixin, "");
String methodName = method.name;
if (!mod.isEmpty()) {
//It's common for mods to prefix their own handlers, let's account for that happening
if (methodName.startsWith(mod) && methodName.length() > mod.length() + 1 && Chars.contains(new char[] {'_', '$'}, methodName.charAt(mod.length()))) {
methodName = methodName.substring(mod.length() + 1);
}
mod += '$';
//It's common for mods to prefix their own handlers, let's account for that happening
if (methodName.startsWith(mod) && methodName.length() > mod.length() + 1 && Chars.contains(new char[] {'_', '$'}, methodName.charAt(mod.length()))) {
methodName = methodName.substring(mod.length() + 1);
}
mod += '$';
}
String methodUID = MethodMapper.getMethodUID(methodName, method.desc, !method.isSurrogate());
return String.format("%s$%s%s$%s%s", prefix, classUID, methodUID, mod, methodName);
Expand All @@ -145,18 +145,18 @@ public String getUniqueName(MixinInfo mixin, MethodNode method, String sessionId
String uniqueIndex = Integer.toHexString(this.nextUniqueMethodIndex++);
String methodName = method.name;
if (method instanceof MethodNodeEx) {
String mod = MethodMapper.getMixinSourceId(mixin, "");
if (!mod.isEmpty()) {
//It's rarer for mods to prefix their @Unique methods, but let's account for it anyway
if (methodName.startsWith(mod) && methodName.length() > mod.length() + 1 && Chars.contains(new char[] {'_', '$'}, methodName.charAt(mod.length()))) {
methodName = methodName.substring(mod.length() + 1);
}
if (preservePrefix) {
methodName += '$' + mod;
} else {
methodName = mod + '$' + methodName;
}
}
String mod = MethodMapper.getMixinSourceId(mixin, "");
if (!mod.isEmpty()) {
//It's rarer for mods to prefix their @Unique methods, but let's account for it anyway
if (methodName.startsWith(mod) && methodName.length() > mod.length() + 1 && Chars.contains(new char[] {'_', '$'}, methodName.charAt(mod.length()))) {
methodName = methodName.substring(mod.length() + 1);
}
if (preservePrefix) {
methodName += '$' + mod;
} else {
methodName = mod + '$' + methodName;
}
}
}
String pattern = preservePrefix ? "%2$s_$md$%1$s$%3$s" : "md%s$%s$%s";
return String.format(pattern, sessionId.substring(30), methodName, uniqueIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ protected final void checkConstraints(MixinTargetContext mixin, MethodNode metho

/**
* Finds a method in the target class
* @param searchFor
* @param searchFor The method node to search for
*
* @return Target method matching searchFor, or null if not found
*/
Expand All @@ -797,7 +797,7 @@ protected final MethodNode findTargetMethod(MethodNode searchFor) {

/**
* Finds a field in the target class
* @param searchFor
* @param searchFor The field node to search for
*
* @return Target field matching searchFor, or null if not found
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.CompareUtil;
import org.spongepowered.asm.util.VersionNumber;

import com.google.common.base.Strings;
Expand Down Expand Up @@ -1374,7 +1373,7 @@ public int compareTo(MixinConfig other) {
return 0;
}
if (other.priority == this.priority) {
return CompareUtil.compare(this.order, other.order);
return Integer.compare(this.order, other.order);
} else {
return (this.priority < other.priority) ? -1 : 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.spongepowered.asm.util.LanguageFeatures;
import org.spongepowered.asm.util.asm.ASM;
import org.spongepowered.asm.util.asm.MethodNodeEx;
import org.spongepowered.asm.util.CompareUtil;
import org.spongepowered.asm.util.perf.Profiler;
import org.spongepowered.asm.util.perf.Profiler.Section;

Expand Down Expand Up @@ -1342,7 +1341,7 @@ public int compareTo(MixinInfo other) {
return 0;
}
if (other.priority == this.priority) {
return CompareUtil.compare(this.order, other.order);
return Integer.compare(this.order, other.order);
} else {
return (this.priority < other.priority) ? -1 : 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,70 @@
import org.spongepowered.asm.util.Bytecode;

public enum MixinInheritanceTracker implements IListener {
INSTANCE;

@Override
public void onPrepare(MixinInfo mixin) {
}

@Override
public void onInit(MixinInfo mixin) {
ClassInfo mixinInfo = mixin.getClassInfo();
assert mixinInfo.isMixin(); //The mixin should certainly be a mixin

for (ClassInfo superType = mixinInfo.getSuperClass(); superType != null && superType.isMixin(); superType = superType.getSuperClass()) {
List<MixinInfo> children = parentMixins.get(superType.getName());

if (children == null) {
parentMixins.put(superType.getName(), children = new ArrayList<MixinInfo>());
}

children.add(mixin);
}
}

public List<MethodNode> findOverrides(ClassInfo owner, String name, String desc) {
return findOverrides(owner.getName(), name, desc);
}

public List<MethodNode> findOverrides(String owner, String name, String desc) {
List<MixinInfo> children = parentMixins.get(owner);
if (children == null) return Collections.emptyList();

List<MethodNode> out = new ArrayList<MethodNode>(children.size());

for (MixinInfo child : children) {
ClassNode node = child.getClassNode(ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);

MethodNode method = Bytecode.findMethod(node, name, desc);
if (method == null || Bytecode.isStatic(method)) continue;

switch (Bytecode.getVisibility(method)) {
case PRIVATE:
break;

case PACKAGE:
int ownerSplit = owner.lastIndexOf('/');
int childSplit = node.name.lastIndexOf('/');
//There is a reasonable chance mixins are in the same package, so it is viable that a package private method is overridden
if (ownerSplit != childSplit || (ownerSplit > 0 && !owner.regionMatches(0, node.name, 0, ownerSplit + 1))) break;

default:
out.add(method);
break;
}
}

return out.isEmpty() ? Collections.<MethodNode>emptyList() : out;
}

private final Map<String, List<MixinInfo>> parentMixins = new HashMap<String, List<MixinInfo>>();
INSTANCE;

@Override
public void onPrepare(MixinInfo mixin) {
}

@Override
public void onInit(MixinInfo mixin) {
ClassInfo mixinInfo = mixin.getClassInfo();
assert mixinInfo.isMixin(); //The mixin should certainly be a mixin

for (ClassInfo superType = mixinInfo.getSuperClass(); superType != null && superType.isMixin(); superType = superType.getSuperClass()) {
List<MixinInfo> children = parentMixins.get(superType.getName());

if (children == null) {
parentMixins.put(superType.getName(), children = new ArrayList<MixinInfo>());
}

children.add(mixin);
}
}

public List<MethodNode> findOverrides(ClassInfo owner, String name, String desc) {
return findOverrides(owner.getName(), name, desc);
}

public List<MethodNode> findOverrides(String owner, String name, String desc) {
List<MixinInfo> children = parentMixins.get(owner);
if (children == null) {
return Collections.emptyList();
}

List<MethodNode> out = new ArrayList<MethodNode>(children.size());

for (MixinInfo child : children) {
ClassNode node = child.getClassNode(ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);

MethodNode method = Bytecode.findMethod(node, name, desc);
if (method == null || Bytecode.isStatic(method)) {
continue;
}

switch (Bytecode.getVisibility(method)) {
case PRIVATE:
break;

case PACKAGE:
int ownerSplit = owner.lastIndexOf('/');
int childSplit = node.name.lastIndexOf('/');
//There is a reasonable chance mixins are in the same package, so it is viable that a package private method is overridden
if (ownerSplit != childSplit || (ownerSplit > 0 && !owner.regionMatches(0, node.name, 0, ownerSplit + 1))) {
break;
}

out.add(method);
break;
default:
out.add(method);
break;
}
}

return out.isEmpty() ? Collections.<MethodNode>emptyList() : out;
}

private final Map<String, List<MixinInfo>> parentMixins = new HashMap<String, List<MixinInfo>>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected boolean validateField(MixinTargetContext context, FieldNode field, Ann

//Making a field non-final will result in verification crashes, so @Mutable is always a mistake
if (Annotations.getVisible(field, Mutable.class) != null) {
throw new InvalidInterfaceMixinException(this.mixin, String.format("@Shadow field %s.%s is marked as mutable. This is not allowed.",
throw new InvalidInterfaceMixinException(this.mixin, String.format("@Shadow field %s.%s is marked as mutable. This is not allowed.",
this.mixin, field.name));
}

Expand Down
Loading

0 comments on commit 2cd49e6

Please sign in to comment.