mirror of
https://github.com/corda/corda.git
synced 2025-06-21 00:23:09 +00:00
Modify the API Scanner plugin to filter method annotations.
This commit is contained in:
@ -36,6 +36,13 @@ public class ScanApi extends DefaultTask {
|
||||
private static final int FIELD_MASK = Modifier.fieldModifiers();
|
||||
private static final int VISIBILITY_MASK = Modifier.PUBLIC | Modifier.PROTECTED;
|
||||
|
||||
private static final Set<String> ANNOTATION_BLACKLIST;
|
||||
static {
|
||||
Set<String> blacklist = new LinkedHashSet<>();
|
||||
blacklist.add("kotlin.jvm.JvmOverloads");
|
||||
ANNOTATION_BLACKLIST = unmodifiableSet(blacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* This information has been lifted from:
|
||||
* @link <a href="https://github.com/JetBrains/kotlin/blob/master/core/runtime.jvm/src/kotlin/Metadata.kt">Metadata.kt</a>
|
||||
@ -251,7 +258,7 @@ public class ScanApi extends DefaultTask {
|
||||
if (isVisible(method.getAccessFlags()) // Only public and protected methods
|
||||
&& isValid(method.getAccessFlags(), METHOD_MASK) // Excludes bridge and synthetic methods
|
||||
&& !isKotlinInternalScope(method)) {
|
||||
writer.append(" ").println(method);
|
||||
writer.append(" ").println(filterAnnotationsFor(method));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,6 +285,22 @@ public class ScanApi extends DefaultTask {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private String filterAnnotationsFor(MethodInfo method) {
|
||||
return new MethodInfo(
|
||||
method.getClassName(),
|
||||
method.getMethodName(),
|
||||
method.getAccessFlags(),
|
||||
method.getTypeDescriptor(),
|
||||
method.getAnnotationNames().stream()
|
||||
.filter(ScanApi::isVisibleAnnotation)
|
||||
.collect(toList())
|
||||
).toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isVisibleAnnotation(String annotationName) {
|
||||
return !ANNOTATION_BLACKLIST.contains(annotationName);
|
||||
}
|
||||
|
||||
private static boolean isKotlinInternalScope(MethodInfo method) {
|
||||
|
Reference in New Issue
Block a user