3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00

Better checking for method return TYPE_USE annotations

Dieser Commit ist enthalten in:
Riley Park 2021-06-21 10:08:30 -07:00
Ursprung 15e4b30e9e
Commit 22280c5f55
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: D831AF236C834E45
4 geänderte Dateien mit 33 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -5,15 +5,28 @@ Subject: [PATCH] Allow use of TYPE_USE annotations
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index 0c7377247ad9251c9e498039511e7220370aba2d..2ef6b56642f792d1a648e76e904e61bf7a662f8c 100644 index 0c7377247ad9251c9e498039511e7220370aba2d..8d14d81c078d29781591e0ce96ea80338565e42b 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java --- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java +++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -66,15 +66,26 @@ public class AnnotationTest { @@ -67,14 +67,40 @@ public class AnnotationTest {
continue;
} }
- if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) { if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
+ if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations) && !isWellAnnotated(method.visibleTypeAnnotations) && !isWellAnnotated(method.invisibleTypeAnnotations)) { // Paper - also check (in)visible type annotations + // Paper start
+ 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
warn(errors, clazz, method, "return value"); warn(errors, clazz, method, "return value");
} }
@ -23,7 +36,7 @@ index 0c7377247ad9251c9e498039511e7220370aba2d..2ef6b56642f792d1a648e76e904e61bf
+ dancing: // Paper + dancing: // Paper
for (int i = 0; i < paramTypes.length; i++) { for (int i = 0; i < paramTypes.length; i++) {
if (mustBeAnnotated(paramTypes[i]) && !isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) { if (mustBeAnnotated(paramTypes[i]) && !isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
+ // Paper start - wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee + // Paper start
+ if (method.invisibleTypeAnnotations != null) { + if (method.invisibleTypeAnnotations != null) {
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) { + for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef); + final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
@ -36,3 +49,12 @@ index 0c7377247ad9251c9e498039511e7220370aba2d..2ef6b56642f792d1a648e76e904e61bf
ParameterNode paramNode = parameters == null ? null : parameters.get(i); ParameterNode paramNode = parameters == null ? null : parameters.get(i);
String paramName = paramNode == null ? null : paramNode.name; String paramName = paramNode == null ? null : paramNode.name;
@@ -174,7 +200,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;
}

Datei anzeigen

@ -3706,7 +3706,7 @@ index da01d2926cc8a2485a3349ac1ebb32cad20e287c..f0af10a5b9ad048be197ed5ec6c8ed26
/** /**
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index 4aee3dd321453009fda10db9c4fbea0ffed6ed69..002677ac589aa88b643c52a883a72a2bdc3696dd 100644 index 8d14d81c078d29781591e0ce96ea80338565e42b..f82f085ab9069abce10c2339446ef0d0bec8888c 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java --- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java +++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -26,6 +26,12 @@ import org.objectweb.asm.tree.ParameterNode; @@ -26,6 +26,12 @@ import org.objectweb.asm.tree.ParameterNode;
@ -3722,12 +3722,3 @@ index 4aee3dd321453009fda10db9c4fbea0ffed6ed69..002677ac589aa88b643c52a883a72a2b
"Lorg/jetbrains/annotations/Nullable;", "Lorg/jetbrains/annotations/Nullable;",
"Lorg/jetbrains/annotations/NotNull;", "Lorg/jetbrains/annotations/NotNull;",
"Lorg/jetbrains/annotations/Contract;", "Lorg/jetbrains/annotations/Contract;",
@@ -185,7 +191,7 @@ public class AnnotationTest {
return true;
}
- private static boolean isWellAnnotated(@Nullable List<AnnotationNode> annotations) {
+ private static boolean isWellAnnotated(@Nullable List<? extends AnnotationNode> annotations) { // Paper - allow children of AnnotationNode
if (annotations == null) {
return false;
}

Datei anzeigen

@ -6,10 +6,10 @@ Subject: [PATCH] Ignore package-private methods for nullability annotations
This isn't API This isn't API
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index dfd4174c8dca51600c2203e3f4c933507fb827e7..1c6a41644257cd35ced235af6cc60efc925ebc18 100644 index 15ae70ae69b27712d68270866d7940ff618c9fbe..911654d36f6ac708eb38b6df1f7f535a15c05fb8 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java --- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java +++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -179,7 +179,7 @@ public class AnnotationTest { @@ -194,7 +194,7 @@ public class AnnotationTest {
private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) { private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
// Exclude private, synthetic and deprecated methods // Exclude private, synthetic and deprecated methods

Datei anzeigen

@ -5,10 +5,10 @@ Subject: [PATCH] Better AnnotationTest printout
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index 1c6a41644257cd35ced235af6cc60efc925ebc18..b94d87832a271a76a5c8c0c9bf403c35348b31ed 100644 index 911654d36f6ac708eb38b6df1f7f535a15c05fb8..32af614abd761e39a412422abe2fcb5272a6374c 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java --- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java +++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -118,13 +118,18 @@ public class AnnotationTest { @@ -133,13 +133,18 @@ public class AnnotationTest {
Collections.sort(errors); Collections.sort(errors);