Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/api/0003-Annotation-Test-changes.patch

92 Zeilen
5.1 KiB
Diff

2021-06-21 18:55:17 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2021-11-24 04:07:05 +01:00
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 17 Mar 2019 23:04:30 +0000
Subject: [PATCH] Annotation Test changes
2021-06-21 18:55:17 +02:00
2021-11-24 04:07:05 +01:00
- Allow use of TYPE_USE annotations
- Ignore package-private methods for nullability annotations
- Add excludes for classes which don't pass
2021-06-21 18:55:17 +02:00
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
2021-11-24 04:07:05 +01:00
index 0c7377247ad9251c9e498039511e7220370aba2d..f9be07fff0bc589e1b0d24c5e5d5695b0b8938c7 100644
2021-06-21 18:55:17 +02:00
--- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java
2021-11-24 04:07:05 +01:00
@@ -40,7 +40,17 @@ public class AnnotationTest {
"org/bukkit/util/io/Wrapper",
"org/bukkit/plugin/java/PluginClassLoader",
// Generic functional interface
- "org/bukkit/util/Consumer"
+ "org/bukkit/util/Consumer",
+ // Paper start
+ // Timings history is broken in terms of nullability due to guavas Function defining that the param is NonNull
+ "co/aikar/timings/TimingHistory$2",
+ "co/aikar/timings/TimingHistory$2$1",
+ "co/aikar/timings/TimingHistory$2$1$1",
+ "co/aikar/timings/TimingHistory$2$1$2",
+ "co/aikar/timings/TimingHistory$3",
+ "co/aikar/timings/TimingHistory$4",
+ "co/aikar/timings/TimingHistoryEntry$1"
+ // Paper end
};
@Test
@@ -67,14 +77,40 @@ public class AnnotationTest {
2021-06-21 18:55:17 +02:00
}
if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
2021-11-24 04:07:05 +01:00
+ // Paper start - Allow use of TYPE_USE annotations
+ boolean warn = true;
+ if (isWellAnnotated(method.visibleTypeAnnotations)) {
+ warn = false;
+ } else if (method.invisibleTypeAnnotations != null) {
+ dance: for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_RETURN && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
+ warn = false;
+ break dance; // cha cha real smooth
+ }
+ }
+ }
+ if (warn)
+ // Paper end
2021-06-21 18:55:17 +02:00
warn(errors, clazz, method, "return value");
}
Type[] paramTypes = Type.getArgumentTypes(method.desc);
List<ParameterNode> parameters = method.parameters;
+ dancing: // Paper
for (int i = 0; i < paramTypes.length; i++) {
if (mustBeAnnotated(paramTypes[i]) && !isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
+ // Paper start
2021-06-21 18:55:17 +02:00
+ if (method.invisibleTypeAnnotations != null) {
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
+ continue dancing;
+ }
+ }
+ }
2021-11-24 04:07:05 +01:00
+ // Paper end - Allow use of TYPE_USE annotations
2021-06-21 18:55:17 +02:00
ParameterNode paramNode = parameters == null ? null : parameters.get(i);
String paramName = paramNode == null ? null : paramNode.name;
2021-11-24 04:07:05 +01:00
@@ -152,7 +188,7 @@ public class AnnotationTest {
private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
// Exclude private, synthetic and deprecated methods
- if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0) {
+ if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0 || (method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0) { // Paper - ignore package-private
return false;
}
@@ -174,7 +210,7 @@ public class AnnotationTest {
return true;
}
- private static boolean isWellAnnotated(@Nullable List<AnnotationNode> annotations) {
+ private static boolean isWellAnnotated(@Nullable List<? extends AnnotationNode> annotations) { // Paper
if (annotations == null) {
return false;
}