Enable checkstyle (#149)

This commit is contained in:
modmuss authored and GitHub committed 2024-07-01 09:09:16 +01:00
1 parent 2edfbc448e
commit 2cd49e6314
20 files changed
+143 -159

No files matched your search

+5 -5
View File
@@ -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
@@ -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
@@ -322,7 +322,7 @@ checkstyle {
"year" : project.inceptionYear
]
configFile = file("checkstyle.xml")
toolVersion = '8.44'
toolVersion = '10.17.0'
}
// Source compiler configuration
+1 -8
View File
@@ -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$"/>
@@ -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>
@@ -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) {
@@ -65,4 +81,7 @@ public final class FabricUtil {
return defaultValue;
}
}
private FabricUtil() {
}
}
@@ -570,7 +570,9 @@ public class CallbackInjector extends Injector {
}
}
this.invokeCallback(callback, callbackMethod);
if (callback.usesCallbackInfo) this.injectCancellationCode(callback);
if (callback.usesCallbackInfo) {
this.injectCancellationCode(callback);
}
callback.inject();
this.info.notifyInjected(callback.target);
@@ -32,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode
import java.util.Arrays;
public class InvokeUtil {
public final class InvokeUtil {
public static Type[] getOriginalArgs(InjectionNode node) {
return Type.getArgumentTypes(((MethodInsnNode) node.getOriginalTarget()).desc);
}
@@ -47,4 +47,7 @@ public class InvokeUtil {
}
return currentArgs;
}
private InvokeUtil() {
}
}
@@ -30,7 +30,6 @@ import java.util.Map;
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
@@ -198,7 +197,7 @@ public class InjectionNodes extends ArrayList<InjectionNodes.InjectionNode> {
*/
@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)
@@ -232,7 +232,11 @@ public final class ClassInfo {
* 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;
@@ -122,11 +122,11 @@ class MethodMapper {
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);
@@ -145,18 +145,18 @@ class MethodMapper {
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);
@@ -781,7 +781,7 @@ class MixinApplicatorStandard {
/**
* 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
*/
@@ -797,7 +797,7 @@ class MixinApplicatorStandard {
/**
* 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
*/
@@ -59,7 +59,6 @@ import org.spongepowered.asm.mixin.transformer.ext.Extensions;
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;
@@ -1374,7 +1373,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
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;
}
@@ -73,7 +73,6 @@ import org.spongepowered.asm.util.Bytecode;
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;
@@ -1342,7 +1341,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
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;
}
@@ -38,62 +38,70 @@ import org.spongepowered.asm.mixin.transformer.MixinConfig.IListener;
import org.spongepowered.asm.util.Bytecode;
public enum MixinInheritanceTracker implements IListener {
INSTANCE;
INSTANCE;
@Override
public void onPrepare(MixinInfo mixin) {
}
@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
@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());
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>());
}
if (children == null) {
parentMixins.put(superType.getName(), children = new ArrayList<MixinInfo>());
}
children.add(mixin);
}
}
children.add(mixin);
}
}
public List<MethodNode> findOverrides(ClassInfo owner, String name, String desc) {
return findOverrides(owner.getName(), name, desc);
}
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();
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());
List<MethodNode> out = new ArrayList<MethodNode>(children.size());
for (MixinInfo child : children) {
ClassNode node = child.getClassNode(ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
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;
MethodNode method = Bytecode.findMethod(node, name, desc);
if (method == null || Bytecode.isStatic(method)) {
continue;
}
switch (Bytecode.getVisibility(method)) {
case PRIVATE:
break;
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;
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;
}
}
out.add(method);
break;
default:
out.add(method);
break;
}
}
return out.isEmpty() ? Collections.<MethodNode>emptyList() : out;
}
return out.isEmpty() ? Collections.<MethodNode>emptyList() : out;
}
private final Map<String, List<MixinInfo>> parentMixins = new HashMap<String, List<MixinInfo>>();
private final Map<String, List<MixinInfo>> parentMixins = new HashMap<String, List<MixinInfo>>();
}
@@ -140,7 +140,7 @@ class MixinPreProcessorInterface extends MixinPreProcessorStandard {
//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));
}
@@ -649,13 +649,13 @@ class MixinPreProcessorStandard {
iter.remove();
continue;
} else if (!Bytecode.compareFlags(mixinField, target, Opcodes.ACC_STATIC)) {
if (isShadow) {
throw new InvalidMixinException(this.mixin, String.format("STATIC modifier of @Shadow field %s in %s does not match the target",
mixinField.name, this.mixin));
} else {
throw new InvalidMixinException(this.mixin, String.format("Field %s in %s conflicts with %sstatic field in the target (%s)",
mixinField.name, mixin, Bytecode.isStatic(target) ? "" : "non-", context.getTarget()));
}
if (isShadow) {
throw new InvalidMixinException(this.mixin, String.format("STATIC modifier of @Shadow field %s in %s does not match the target",
mixinField.name, this.mixin));
} else {
throw new InvalidMixinException(this.mixin, String.format("Field %s in %s conflicts with %sstatic field in the target (%s)",
mixinField.name, mixin, Bytecode.isStatic(target) ? "" : "non-", context.getTarget()));
}
}
if (!Bytecode.compareFlags(mixinField, target, Opcodes.ACC_STATIC)) {
@@ -543,7 +543,7 @@ class MixinProcessor {
this.handleMixinPrepareError(config, ex, environment);
} catch (Exception ex) {
String message = ex.getMessage();
MixinProcessor.logger.error("Error encountered whilst initialising mixin config '" + config.getName() + "' from mod '"+org.spongepowered.asm.mixin.FabricUtil.getModId(config)+"': " + message, ex);
MixinProcessor.logger.error("Error encountered whilst initialising mixin config '" + config.getName() + "' from mod '" + org.spongepowered.asm.mixin.FabricUtil.getModId(config) + "': " + message, ex);
}
}
@@ -570,7 +570,7 @@ class MixinProcessor {
this.handleMixinPrepareError(config, ex, environment);
} catch (Exception ex) {
String message = ex.getMessage();
MixinProcessor.logger.error("Error encountered during mixin config postInit step '" + config.getName() + "' from mod '"+org.spongepowered.asm.mixin.FabricUtil.getModId(config)+ "': " + message, ex);
MixinProcessor.logger.error("Error encountered during mixin config postInit step '" + config.getName() + "' from mod '" + org.spongepowered.asm.mixin.FabricUtil.getModId(config) + "': " + message, ex);
}
}
@@ -221,7 +221,9 @@ public final class MixinService {
if (serviceCls != null) {
try {
IMixinService service = (IMixinService) Class.forName(serviceCls).getConstructor().newInstance();
if (!service.isValid()) throw new RuntimeException("invalid service "+serviceCls+" configured via system property");
if (!service.isValid()) {
throw new RuntimeException("invalid service " + serviceCls + " configured via system property");
}
return service;
} catch (ReflectiveOperationException e) {
@@ -1,45 +0,0 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.util;
/**
* Comparison helpers.
*/
public final class CompareUtil {
private CompareUtil() {
}
/**
* Officially added in Java 7.
*/
public static int compare(int a, int b) {
return ((a < b) ? -1 : ((a == b) ? 0 : 1));
}
public static int compare(long a, long b) {
return ((a < b) ? -1 : ((a == b) ? 0 : 1));
}
}
@@ -97,25 +97,25 @@ public abstract class JavaVersion {
*/
public static final double JAVA_18 = 18.0;
/**
* Version number for Java 19
*/
public static final double JAVA_19 = 19.0;
/**
* Version number for Java 19
*/
public static final double JAVA_19 = 19.0;
/**
* Version number for Java 20
*/
public static final double JAVA_20 = 20.0;
/**
* Version number for Java 20
*/
public static final double JAVA_20 = 20.0;
/**
* Version number for Java 21
*/
public static final double JAVA_21 = 21.0;
/**
* Version number for Java 21
*/
public static final double JAVA_21 = 21.0;
/**
* Version number for Java 22
*/
public static final double JAVA_22 = 22.0;
/**
* Version number for Java 22
*/
public static final double JAVA_22 = 22.0;
private static double current = 0.0;
@@ -328,6 +328,7 @@ public final class Locals {
* bear in mind that if the specified node is itself a STORE opcode,
* then we will be looking at the state of the locals PRIOR to its
* invocation
* @param fabricCompatibility Fabric compatibility level
* @return A sparse array containing a view (hopefully) of the locals at the
* specified location
*/
@@ -335,7 +336,7 @@ public final class Locals {
if (fabricCompatibility >= org.spongepowered.asm.mixin.FabricUtil.COMPATIBILITY_0_10_0) {
return Locals.getLocalsAt(classNode, method, node, Settings.DEFAULT);
} else {
return getLocalsAt_0_9_2(classNode, method, node);
return getLocalsAt092(classNode, method, node);
}
}
@@ -580,7 +581,7 @@ public final class Locals {
return frame;
}
private static LocalVariableNode[] getLocalsAt_0_9_2(ClassNode classNode, MethodNode method, AbstractInsnNode node) {
private static LocalVariableNode[] getLocalsAt092(ClassNode classNode, MethodNode method, AbstractInsnNode node) {
for (int i = 0; i < 3 && (node instanceof LabelNode || node instanceof LineNumberNode); i++) {
node = Locals.nextNode(method.instructions, node);
}
@@ -141,7 +141,7 @@ public final class VersionNumber implements Comparable<VersionNumber>, Serializa
if (other == null) {
return 1;
}
return CompareUtil.compare(this.value, other.value);
return Long.compare(this.value, other.value);
}
/* (non-Javadoc)